diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-11-05 15:29:46 +0100 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-11-05 15:29:46 +0100 |
commit | 6f29f345dc06c1a1033475eac1d1340781d1d603 (patch) | |
tree | 6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /python/src/sa/sym.pxi | |
parent | b510da2e562c695c90d565eb295c749569c59be8 (diff) | |
parent | c615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff) |
merge upstream/master
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) |