summaryrefslogtreecommitdiff
path: root/python/src/sa/sym.pxi
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-09-20 21:51:31 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-09-20 21:51:31 -0400
commitd2bc8694e5450a46c6f851d926c1ebfeb3424cbf (patch)
tree5619896999d43ca478acee0da2b1c60244aab5b1 /python/src/sa/sym.pxi
parent78518f1f417616633b300a361cd5e0c1bcb1ff24 (diff)
parent5d159b948ad71850bcb03d0882ea7183a3a59b7e (diff)
Merge branch 'master' of https://github.com/redpony/cdec
Diffstat (limited to 'python/src/sa/sym.pxi')
-rw-r--r--python/src/sa/sym.pxi13
1 files changed, 12 insertions, 1 deletions
diff --git a/python/src/sa/sym.pxi b/python/src/sa/sym.pxi
index 132925f6..f47599cf 100644
--- a/python/src/sa/sym.pxi
+++ b/python/src/sa/sym.pxi
@@ -101,5 +101,16 @@ cdef int sym_getindex(int sym):
cdef int sym_setindex(int sym, int id):
return ALPHABET.setindex(sym, id)
-def sym_fromstring(char* string, bint terminal):
+cdef int sym_fromstring(char* string, bint terminal):
return ALPHABET.fromstring(string, terminal)
+
+def make_lattice(words):
+ word_ids = (sym_fromstring(word, True) for word in words)
+ return tuple(((word, None, 1), ) for word in word_ids)
+
+def decode_lattice(lattice):
+ return tuple((sym_tostring(sym), weight, dist) for (sym, weight, dist) in arc
+ for arc in node for node in lattice)
+
+def decode_sentence(lattice):
+ return tuple(sym_tostring(sym) for ((sym, _, _),) in lattice)