你怎么给(openFST制作的)FST输入?输出在哪里?

Ste*_*ing 21 python shell fsm openfst

在开始之前,请注意我正在使用linux shell(using subprocess.call()来自Python),我正在使用openFST.

我一直在筛选有关openFST的文档和问题,但我似乎无法找到这个问题的答案:如何实际为openFST定义的,编译和组合的FST提供输入?输出在哪里?我只是执行'fstproject'吗?如果是这样,我怎么会给它一个字符串来转换,并在达到最终状态时打印各种转换?

如果这个问题显而易见,我道歉.我还不熟悉openFST.

Pau*_*xon 22

一种方法是创建执行转换的机器.一个非常简单的例子是大写字符串.

M.wfst

0 0 a A
0 0 b B
0 0 c C
0
Run Code Online (Sandbox Code Playgroud)

随附的符号文件包含用于字母表的每个符号的行.注0保留用于空(epsilon)转换,并且在许多操作中具有特殊含义.

M.syms

<epsilon> 0
a 1
b 2
c 3
A 4
B 5
C 6
Run Code Online (Sandbox Code Playgroud)

然后编译机器

fstcompile --isymbols=M.syms --osymbols=M.syms M.wfst > M.ofst
Run Code Online (Sandbox Code Playgroud)

对于输入字符串"abc",创建一个线性链自动机,这是一个从左到右的链,每个字符都有一个弧.这是一个接受器,所以我们只需要一个输入符号列.

I.wfst

0 1 a
1 2 b
2 3 c
3  
Run Code Online (Sandbox Code Playgroud)

编译为接受者

fstcompile --isymbols=M.syms --acceptor I.wfst > I.ofst
Run Code Online (Sandbox Code Playgroud)

然后组合机器并打印

fstcompose I.ofst M.ofst | fstprint --isymbols=M.syms --osymbols=M.syms 
Run Code Online (Sandbox Code Playgroud)

这将给出输出

0   1   a   A
1   2   b   B
2   3   c   C
3
Run Code Online (Sandbox Code Playgroud)

fstcompose的输出是输入字符串的所有转换的网格.(在这种情况下只有一个).如果M.ofst更复杂,可以使用fstshortestpath使用标志--unique -nshortest = n来提取n字符串.此输出又是一个传感器,您可以废弃fstprint的输出,或者使用C++代码和OpenFst库来运行深度优先搜索以提取字符串.

插入fstproject --project_output会将输出转换为仅包含输出标签的接受器.

fstcompose I.ofst M.ofst | fstproject --project_output |  fstprint --isymbols=M.syms --osymbols=M.syms 
Run Code Online (Sandbox Code Playgroud)

给出以下内容

0  1  A  A
1  2  B  B
2  3  C  C
3
Run Code Online (Sandbox Code Playgroud)

这是一个接受器,因为输入和输出标签是相同的,-acceptor选项可用于生成更简洁的输出.

 fstcompose I.ofst M.ofst | fstproject --project_output |  fstprint --isymbols=M.syms --acceptor
Run Code Online (Sandbox Code Playgroud)

  • 我觉得openfst没有提供创建'线性链自动机'的方法,这有点令人难以置信. (5认同)