gtn库

源码编译

在windows上通过vs2022无法通过,linux上make过程中不明所以的代码报错。走不通。

pip

windows上0.0.1(最新版)和0.0.0的安装均以“distutil警告目录以’/‘结尾”的错误告终。

linux无法通过最新版的安装,错误原因是subprocess执行cmake命令返回值非0。通过0.0.0的安装。

dot程序

gtn的draw函数需要调用dot程序,linux上安装graphviz,支持gtn构造的有限状态自动机的可视化

示例程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gtn

# Define the mapping from integer ids to arc symbol labels
symbols={0:'a',1:'b',2:'c'}

# Make a graph
fsa=gtn.Graph()

# Add a start node
fsa.add_node(start=True)

# Add an accepting node
fsa.add_node(accept=True)

# Add an internal node
fsa.add_node()

# Add an arc from node 0 to 2 with label 0
fsa.add_arc(src_node=0,dst_node=2,label=0)

# Add an arc from node 0 to 2 with input label 1 and output label 1
fsa.add_arc(src_node=0,dst_node=2,ilabel=1,olabel=1)

# Add an arc from node 2 to 1 with input label 0, output label 0 and
fsa.add_arc(src_node=2,dst_node=1,ilabel=0,olabel=0,weight=2)

gtn.draw(fsa,'intersection.pdf',isymbols=symbols,osymbols={})

创建于2023.2.10/1.6,修改于2023.2.10/1.6