Pyfst を使用してトランスデューサーを作成する方法を学んでおり、作成したトランスデューサーを視覚化しようとしています。最終的な目標は、トランスデューサをドット ファイルに書き込んで、Graphviz で表示できるようにすることです。
次のアクセプターを視覚化する方法を確認するために、サンプル コードを使用しました。
a = fst.Acceptor()
a.add_arc(0, 1, 'x', 0.1)
a[1].final = -1
a.draw()
パッケージに付属の draw() を使用すると、エラーが発生します。
File "/Users/.../tests.py", line 42, in <module>
a.draw()
File "_fst.pyx", line 816, in fst._fst.StdVectorFst.draw
(fst/_fst.cpp:15487)
File "/Users/.../venv-3.6/lib/python3.6/re.py", line 191, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: cannot use a string pattern on a bytes-like object
上記のアクセプターを .dot に書き込もうとすると、次のようになります。
def fst_dot(dot_object, filename):
path, file = split(filename)
new_path = join(dot_files_folder_path, path)
if not os.path.exists(new_path):
os.makedirs(new_path)
if hasattr(dot_object, 'dotFormat'):
draw_string = dot_object.dotFormat()
else:
draw_string = dot_object.draw()
open(join(dot_files_folder_path, filename + ".dot"), "w").write(draw_string)
次に、次のエラーも表示されます。
File "/Users/...tests.py", line 43, in <module>
fst_dot(a, 'acceptor')
File "/Users/...tests.py", line 22, in fst_dot
draw_string = dot_object.draw()
File "_fst.pyx", line 816, in fst._fst.StdVectorFst.draw
(fst/_fst.cpp:15487)
File "/Users/.../venv-3.6/lib/python3.6/re.py", line 191, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: cannot use a string pattern on a bytes-like object
したがって、どちらのエラーも同じように見えます。draw() には何らかの問題があります。pyfst サイトでは、トランスデューサのドット形式の表現に draw が使用されると書かれています。
エラーの修正方法がわかりません。どんな助けでも大歓迎です。
OSX と PyCharm を使用しています。