From 57d8aeaf862bad8516e8aa87eca10fdb75bdcb3a Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Mon, 4 Jun 2012 02:16:59 -0400 Subject: Python module: initial version --- python/test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/test.py (limited to 'python/test.py') diff --git a/python/test.py b/python/test.py new file mode 100644 index 00000000..df5ce64d --- /dev/null +++ b/python/test.py @@ -0,0 +1,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') -- cgit v1.2.3