Welcome to mirror list, hosted at ThFree Co, Russian Federation.

example.py « python « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 93eb60d73b5eff198d79afeb97fa720234500590 (plain)
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
from moses.dictree import load
import sys

if len(sys.argv) != 4:
    print("Usage: %s table nscores tlimit < query > result" % (sys.argv[0]))
    sys.exit(0)

path = sys.argv[1]
nscores = int(sys.argv[2])
tlimit = int(sys.argv[3])

table = load(path, nscores, tlimit)

for line in sys.stdin:
    f = line.strip()
    result = table.query(f)
    # you could simply print the matches
    # print '\n'.join([' ||| '.join((f, str(e))) for e in matches])
    # or you can use its attributes
    print result.source
    for e in result:
        if e.lhs:
            print('\t%s -> %s ||| %s ||| %s' % (
                    e.lhs, 
                    ' '.join(e.rhs), 
                    e.scores, 
                    e.alignment
                )
            )
        else:
            print('\t%s ||| %s ||| %s' % (
                    ' '.join(e.rhs), 
                    e.scores, 
                    e.alignment
                )
            )