Mor*_*a R 7 python parsing dot morphological-analysis transducer
我有一个以DOT文件形式保存的传感器.我可以使用gvedit看到图形的图形表示,但是如果我想将DOT文件转换为可执行的传感器,那么我可以测试传感器并查看它接受的字符串以及它不接受的字符串.
在我在Openfst,Graphviz及其Python扩展中看到的大多数工具中,DOT文件仅用于创建图形表示,但如果我想解析文件以获得交互式程序,我可以测试字符串换能器?
是否有任何库可以完成任务,或者我应该从头开始编写它?
正如我所说,DOT文件与我设计的模拟英语形态的换能器有关.这是一个巨大的文件,但只是为了让您了解它是什么样的,我提供了一个示例.假设我想创建一个能够模拟英语关于名词和多个方面行为的传感器.我的词典只包含三个单词(书,男孩,女孩).在这种情况下,我的传感器看起来像这样:

这是从这个DOT文件直接构造的:
digraph A {
rankdir = LR;
node [shape=circle,style=filled] 0
node [shape=circle,style=filled] 1
node [shape=circle,style=filled] 2
node [shape=circle,style=filled] 3
node [shape=circle,style=filled] 4
node [shape=circle,style=filled] 5
node [shape=circle,style=filled] 6
node [shape=circle,style=filled] 7
node [shape=circle,style=filled] 8
node [shape=circle,style=filled] 9
node [shape=doublecircle,style=filled] 10
0 -> 4 [label="g "];
0 -> 1 [label="b "];
1 -> 2 [label="o "];
2 -> 7 [label="y "];
2 -> 3 [label="o "];
3 -> 7 [label="k "];
4 -> 5 [label="i "];
5 -> 6 [label="r "];
6 -> 7 [label="l "];
7 -> 9 [label="<+N:s> "];
7 -> 8 [label="<+N:0> "];
8 -> 10 [label="<+Sg:0> "];
9 -> 10 [label="<+Pl:0> "];
}
Run Code Online (Sandbox Code Playgroud)
现在测试这个换能器的字样意味着如果你用book+Pl它喂它应该吐回来books,反之亦然.我想看看如何将点文件转换为允许进行此类分析和测试的格式.
小智 7
安装graphviz库。然后尝试以下操作:
import graphviz
graphviz.Source.from_file('graph4.dot')
Run Code Online (Sandbox Code Playgroud)
您可以首先使用https://code.google.com/p/pydot/加载文件。从那里开始,编写根据输入字符串遍历内存中的图的代码应该相对简单。
| 归档时间: |
|
| 查看次数: |
14710 次 |
| 最近记录: |