diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-09-06 11:17:00 +0100 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-09-06 11:17:00 +0100 |
commit | af8b109ad49222bc56527e5e75b8267134233bd4 (patch) | |
tree | ced5356aa5b8932686b02ecba864397bf8c0ccb9 /python/src/sa/sym.pxi | |
parent | b674c40505f48bfc3aafe4df9e116321c89342fa (diff) |
[cdec.sa] Make list of word ids <-> sentence string mapping easy
Diffstat (limited to 'python/src/sa/sym.pxi')
-rw-r--r-- | python/src/sa/sym.pxi | 13 |
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) |