-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvocab2edit.py
executable file
·59 lines (45 loc) · 1.14 KB
/
vocab2edit.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created: Mon, 29 Jul 2013 12:23:47 -0400
"""
SYNOPSIS
vocab2edit.py < vocab > edit.txt
DESCRIPTION
Constructs a uniform cost edit fst in OpenFst textual format.
AUTHOR
Dogan Can <[email protected]>
VERSION
0.1
"""
import sys
def read_vocab(ifile):
vocab = []
for line in ifile:
vocab += [line.strip()]
return vocab
def vocab2edit(vocab, ofile):
# Ω*
for v in vocab:
print >> ofile, 0, 0, v, "ε"
print >> ofile, 0, 0, "ε", v
for w in vocab:
print >> ofile, 0, 0, v, w
# Ψ
for v in vocab:
print >> ofile, 0, 1, v, "ε"
print >> ofile, 0, 1, "ε", v
for w in vocab:
if v != w:
print >> ofile, 0, 1, v, w
else:
print >> ofile, 0, 1, v, w, 1000000
# Ω*
for v in vocab:
print >> ofile, 1, 1, v, "ε"
print >> ofile, 1, 1, "ε", v
for w in vocab:
print >> ofile, 1, 1, v, w
print >> ofile, 1
if __name__ == '__main__':
vocab = read_vocab(sys.stdin)
vocab2edit(vocab, sys.stdout)