From af8b109ad49222bc56527e5e75b8267134233bd4 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Thu, 6 Sep 2012 11:17:00 +0100 Subject: [cdec.sa] Make list of word ids <-> sentence string mapping easy --- python/src/sa/sym.pxi | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'python/src/sa/sym.pxi') 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) -- cgit v1.2.3