summaryrefslogtreecommitdiff
path: root/python/test.py
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-06-05 15:47:09 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-06-05 15:47:09 -0400
commit6d95c0b1edea38a972c287793fabae8f7f0eea1a (patch)
treea70c0aaddf6e3313ebe349b6a90542ab5359b3be /python/test.py
parent76950778554a836230b68aa1ba517bc19521a66f (diff)
parent57d8aeaf862bad8516e8aa87eca10fdb75bdcb3a (diff)
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'python/test.py')
-rw-r--r--python/test.py17
1 files changed, 17 insertions, 0 deletions
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')