summaryrefslogtreecommitdiff
path: root/python/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/test.py')
-rw-r--r--python/test.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/python/test.py b/python/test.py
index 8069aa0a..54859e81 100644
--- a/python/test.py
+++ b/python/test.py
@@ -2,12 +2,11 @@
import cdec
import gzip
-config = 'formalism=scfg'
weights = '../tests/system_tests/australia/weights'
grammar_file = '../tests/system_tests/australia/australia.scfg.gz'
# Load decoder width configuration
-decoder = cdec.Decoder(config)
+decoder = cdec.Decoder(formalism='scfg')
# Read weights
decoder.read_weights(weights)
@@ -26,15 +25,17 @@ forest = decoder.translate(sentence, grammar=grammar)
# Get viterbi translation
print 'Output[0]:', forest.viterbi().encode('utf8')
-print ' ETree[0]:', forest.viterbi_tree().encode('utf8')
-print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8')
+f_tree, e_tree = forest.viterbi_trees()
+print ' FTree[0]:', f_tree.encode('utf8')
+print ' ETree[0]:', e_tree.encode('utf8')
print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights)
# Get k-best translations
-kbest = zip(forest.kbest(5), forest.kbest_tree(5), forest.kbest_features(5))
-for i, (sentence, tree, features) in enumerate(kbest, 1):
+kbest = zip(forest.kbest(5), forest.kbest_trees(5), forest.kbest_features(5))
+for i, (sentence, (f_tree, e_tree), features) in enumerate(kbest, 1):
print 'Output[%d]:' % i, sentence.encode('utf8')
- print ' Tree[%d]:' % i, tree.encode('utf8')
+ print ' FTree[%d]:' % i, f_tree.encode('utf8')
+ print ' ETree[%d]:' % i, e_tree.encode('utf8')
print ' FVect[%d]:' % i, dict(features)
# Sample translations from the forest
@@ -54,8 +55,9 @@ assert (lattice == tuple(lat))
assert forest.intersect(lat)
# Get best synchronous parse
-print forest.viterbi_tree()
-print forest.viterbi_source_tree()
+f_tree, e_tree = forest.viterbi_trees()
+print 'FTree:', f_tree.encode('utf8')
+print 'ETree:', e_tree.encode('utf8')
# Compare 1best and reference feature vectors
fref = forest.viterbi_features()