-module(wfc_pp). -vsn("0.2.0"). -export([ eval_result/1, sentence/1, word/1, ltr/1, bm/1, bm_sparse/1 ]). -spec eval_result(wfc_eval:eval_result()) -> string(). eval_result(noop) -> ""; eval_result(S = {s, _}) -> sentence(S). -spec sentence(wfc_sentence:sentence()) -> string(). sentence({s, []}) -> "(+)"; sentence({s, Words}) -> wfc_utils:str("(+ ~s)", [words(Words)]). -spec words([wfc_word:word()]) -> iolist(). % @private words([W]) -> word(W); words([W | More]) -> [word(W), " ", words(More)]; words([]) -> "". -spec word(wfc_word:word()) -> string(). word({w, []}) -> "(*)"; word({w, Letters}) -> wfc_utils:str("(* ~s)", [letters(Letters)]). -spec letters([wfc_ltr:ltr()]) -> iolist(). % @private letters([W]) -> ltr(W); letters([W | More]) -> [ltr(W), " ", letters(More)]; letters([]) -> "". -spec ltr(wfc_ltr:ltr()) -> string(). ltr({c, Binary}) -> unicode:characters_to_list(Binary). -spec bm(wfc_bm:bm()) -> string(). bm(Matrix) -> List = wfc_bm:to_list(Matrix), Strs = lists:map(fun pf_bm_row/1, List), IoList = ["[", string:join(Strs, "\n "), "]"], unicode:characters_to_list(IoList). pf_bm_row(Bits) -> Strs = lists:map(fun integer_to_list/1, Bits), ["[", string:join(Strs, " "), "]"]. -spec bm_sparse(wfc_bm:bm()) -> string(). bm_sparse(Matrix) -> List = wfc_bm:to_list(Matrix), Strs = lists:map(fun pf_bm_row_sparse/1, List), IoList = ["[", string:join(Strs, "\n "), "]"], unicode:characters_to_list(IoList). pf_bm_row_sparse(Bits) -> Strs = lists:map(fun i2l_sparse/1, Bits), ["[", string:join(Strs, " "), "]"]. i2l_sparse(1) -> "1"; i2l_sparse(0) -> " ".