summaryrefslogtreecommitdiff
path: root/python/src/_cdec.pyx
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-06-14 20:13:04 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-06-14 20:13:04 +0200
commitc17b8d37e25f79f6892c177dbe849591d0f6d713 (patch)
tree72929143d015c561ab6c4206b5f9ed60462860aa /python/src/_cdec.pyx
parent1d1172a3f85ab7423ae9537cf3c73afdfe7dc693 (diff)
parentc3619d27a6e64d2f13fc16d8959ad7ea70486eb8 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r--python/src/_cdec.pyx30
1 files changed, 3 insertions, 27 deletions
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx
index 45320c46..664724dd 100644
--- a/python/src/_cdec.pyx
+++ b/python/src/_cdec.pyx
@@ -41,28 +41,14 @@ cdef class Decoder:
def __cinit__(self, char* config):
decoder.register_feature_functions()
- cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs)
- #cdef ReadFile* config_file = new ReadFile(string(config))
- #cdef istream* config_stream = config_file.stream()
+ cdef istringstream* config_stream = new istringstream(config)
self.dec = new decoder.Decoder(config_stream)
del config_stream
- #del config_file
self.weights = Weights(self)
def __dealloc__(self):
del self.dec
- @classmethod
- def fromconfig(cls, ini):
- cdef dict config = {}
- with open(ini) as fp:
- for line in fp:
- line = line.strip()
- if not line or line.startswith('#'): continue
- param, value = line.split('=')
- config[param.strip()] = value.strip()
- return cls(**config)
-
def read_weights(self, cfg):
with open(cfg) as fp:
for line in fp:
@@ -73,10 +59,9 @@ cdef class Decoder:
def translate(self, unicode sentence, grammar=None):
if grammar:
self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
- #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
- sgml = sentence.strip().encode('utf8')
+ inp = sentence.strip().encode('utf8')
cdef decoder.BasicObserver observer = decoder.BasicObserver()
- self.dec.Decode(string(<char *>sgml), &observer)
+ self.dec.Decode(string(<char *>inp), &observer)
if observer.hypergraph == NULL:
raise ParseFailed()
cdef Hypergraph hg = Hypergraph()
@@ -169,12 +154,3 @@ cdef class Lattice:
del self.lattice
# TODO: wrap SparseVector
-
-"""
-def params_str(params):
- return '\n'.join('%s=%s' % (param, value) for param, value in params.iteritems())
-
-cdef istringstream* ConfigStream(dict params):
- ini = params_str(params)
- return new istringstream(<char *> ini)
-"""