diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-27 22:25:15 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-27 22:25:15 -0400 |
commit | 1d481414a2fa8505a2591c88e2b7b8f86a682ca2 (patch) | |
tree | ed5e9dff569d89da453578ce3d109991623d9303 /python/src/_cdec.pyx | |
parent | b317e0efd2398d75d70e027bb1e2cf442e683981 (diff) |
[python] conversion from cdec.sa.Rule to cdec.TRule
+ remove configobj dependency
+ re-structure packages (no more top-level library)
+ "const" stuff
+ use __new__ instead of constructor for some objects
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r-- | python/src/_cdec.pyx | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index c60f342f..e93474fe 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -3,14 +3,14 @@ from libcpp.vector cimport vector from utils cimport * cimport decoder -cdef char* as_str(data, error_msg='Cannot convert type %s to str'): +cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): cdef bytes ret if isinstance(data, unicode): ret = data.encode('utf8') elif isinstance(data, str): ret = data else: - raise TypeError(error_msg % type(data)) + raise TypeError(error_msg.format(type(data))) return ret include "vectors.pxi" @@ -55,8 +55,9 @@ cdef class Decoder: cdef istringstream* config_stream = new istringstream(config_str) self.dec = new decoder.Decoder(config_stream) del config_stream - self.weights = DenseVector() + self.weights = DenseVector.__new__(DenseVector) self.weights.vector = &self.dec.CurrentWeightVector() + self.weights.owned = True def __dealloc__(self): del self.dec @@ -72,6 +73,7 @@ cdef class Decoder: self.weights.vector.clear() ((<SparseVector> weights).vector[0]).init_vector(self.weights.vector) elif isinstance(weights, dict): + self.weights.vector.clear() for fname, fval in weights.items(): self.weights[fname] = fval else: @@ -80,7 +82,7 @@ cdef class Decoder: property formalism: def __get__(self): cdef variables_map* conf = &self.dec.GetConf() - return conf[0]['formalism'].as_str().c_str() + return conf[0]['formalism'].as_str() def read_weights(self, weights): with open(weights) as fp: |