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)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |