summaryrefslogtreecommitdiff
path: root/python/test.py
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-06-23 15:54:38 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-06-23 15:54:38 -0400
commit6a2bbfa9b28f8be2189744beb89a975bc3da128f (patch)
tree4d9ee4e0b6d2c37be8f8a4e05472cd21e66d0ffd /python/test.py
parentb9266b068a37dc46f8de813c59ffbef2e4b89280 (diff)
parentb738e349be490c24d3604c224f44fc54e16d3d7b (diff)
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'python/test.py')
-rw-r--r--python/test.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/python/test.py b/python/test.py
index 1542dd4f..92403298 100644
--- a/python/test.py
+++ b/python/test.py
@@ -19,14 +19,16 @@ with gzip.open(grammar_file) as f:
# Input sentence
sentence = u'澳洲 是 与 北韩 有 邦交 的 少数 国家 之一 。'
-print 'Input:', sentence
+print ' Input:', sentence.encode('utf8')
# Decode
forest = decoder.translate(sentence, grammar=grammar)
# Get viterbi translation
print 'Output[0]:', forest.viterbi().encode('utf8')
-print ' Tree[0]:', forest.viterbi_tree().encode('utf8')
+print ' ETree[0]:', forest.viterbi_tree().encode('utf8')
+print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8')
+print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights)
# Get k-best translations
for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1):
@@ -37,6 +39,9 @@ for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)),
for sentence in forest.sample(5):
print 'Sample:', sentence.encode('utf8')
+# Get feature vector for 1best
+fsrc = forest.viterbi_features()
+
# Reference lattice
lattice = ((('australia',0,1),),(('is',0,1),),(('one',0,1),),(('of',0,1),),(('the',0,4),('a',0,4),('a',0,1),('the',0,1),),(('small',0,1),('tiny',0,1),('miniscule',0,1),('handful',0,2),),(('number',0,1),('group',0,1),),(('of',0,2),),(('few',0,1),),(('countries',0,1),),(('that',0,1),),(('has',0,1),('have',0,1),),(('diplomatic',0,1),),(('relations',0,1),),(('with',0,1),),(('north',0,1),),(('korea',0,1),),(('.',0,1),),)
@@ -44,6 +49,12 @@ lat = cdec.Lattice(lattice)
assert (lattice == tuple(lat))
# Intersect forest and lattice
-forest.intersect(lat)
+assert forest.intersect(lat)
+
# Get best synchronous parse
print forest.viterbi_tree()
+print forest.viterbi_source_tree()
+
+# Compare 1best and reference feature vectors
+fref = forest.viterbi_features()
+print dict(fsrc - fref)