diff options
author | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-07-08 14:26:51 +0200 |
---|---|---|
committer | Patrick Simianer <simianer@cl.uni-heidelberg.de> | 2012-07-08 14:26:51 +0200 |
commit | c139ce495861bb341e1b86a85ad4559f9ad53c14 (patch) | |
tree | 1071839ee458f21f169ce06fc536fefe07e4c65d /python/src/_cdec.pyx | |
parent | 3a94ac22e5c60aa205f2b3dadf81b0666500e0c3 (diff) | |
parent | d01e5b66d3010d61b9b56301fd7f302dd4ea5bc8 (diff) |
Merge branch 'master' of github.com:pks/cdec-dtrain
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r-- | python/src/_cdec.pyx | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 698a66f6..cccfec0b 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -6,15 +6,15 @@ cimport decoder include "vectors.pxi" include "hypergraph.pxi" include "lattice.pxi" +include "mteval.pxi" SetSilent(True) -class ParseFailed(Exception): - pass +class ParseFailed(Exception): pass cdef class Decoder: cdef decoder.Decoder* dec - cdef public DenseVector weights + cdef DenseVector weights def __cinit__(self, char* config): decoder.register_feature_functions() @@ -27,6 +27,22 @@ cdef class Decoder: def __dealloc__(self): del self.dec + property weights: + def __get__(self): + return self.weights + + def __set__(self, weights): + if isinstance(weights, DenseVector): + self.weights.vector[0] = (<DenseVector> weights).vector[0] + elif isinstance(weights, SparseVector): + self.weights.vector.clear() + ((<SparseVector> weights).vector[0]).init_vector(self.weights.vector) + elif isinstance(weights, dict): + for fname, fval in weights.items(): + self.weights[fname] = fval + else: + raise TypeError('cannot initialize weights with %s' % type(weights)) + def read_weights(self, cfg): with open(cfg) as fp: for line in fp: |