summaryrefslogtreecommitdiff
path: root/python/test.py
blob: df5ce64dcb4612105a429b8afa244c4d103f11cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#coding: utf8
import cdec
import gzip

config = 'formalism=scfg'
weights = '../tests/system_tests/australia/weights'
grammar_file = '../tests/system_tests/australia/australia.scfg.gz'

decoder = cdec.Decoder(config)
decoder.read_weights(weights)
print dict(decoder.weights)
with gzip.open(grammar_file) as f:
    grammar = f.read()
sentence = u'澳洲 是 与 北韩 有 邦交 的 少数 国家 之一 。'
print 'Input:', sentence
forest = decoder.translate(sentence, grammar=grammar)
print 'Output:', forest.viterbi().encode('utf8')