summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-08-11 23:30:00 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-08-11 23:30:00 -0400
commitccdb3061d1e582a5abd412b37ee0da2278f45706 (patch)
tree9952c909e8bccf4f4ed105c1a135e431f7edd05e
parent7f688a6a4ef605dea284b096889f1735406123b6 (diff)
[python] fix for new dict API
- TDConvert returns a string - various c_str fixes (make copies) - cleanup .gitignore
-rw-r--r--.gitignore251
-rw-r--r--python/setup.py.in31
-rw-r--r--python/src/_cdec.cpp530
-rw-r--r--python/src/_cdec.pyx4
-rw-r--r--python/src/grammar.pxi12
-rw-r--r--python/src/hypergraph.pxi4
-rw-r--r--python/src/lattice.pxi4
-rw-r--r--python/src/mteval.pxi9
-rw-r--r--python/src/utils.pxd2
-rw-r--r--python/src/vectors.pxi4
10 files changed, 464 insertions, 387 deletions
diff --git a/.gitignore b/.gitignore
index 9c60cfcc..6f674f35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,45 +1,127 @@
-*.log
-*.bbl
+*.a
*.aux
+*.bbl
*.blg
+*.dvi
*.idx
+*.log
+*.o
*.pdf
-*.dvi
*.ps
-*.toc
-*.so
*.pyc
+*.so
+*.toc
*swp
-*.o
-*.a
*~
.*
./cdec/
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache/
+config.guess
+config.h
+config.h.in
+config.h.in~
+config.log
+config.status
+config.sub
+configure
+decoder/Makefile
+decoder/Makefile.in
decoder/bin/
+decoder/cdec
+decoder/dict_test
+decoder/ff_test
+decoder/grammar_test
+decoder/hg_test
+decoder/logval_test
+decoder/parser_test
+decoder/rule_lexer.cc
+decoder/small_vector_test
+decoder/trule_test
+decoder/weights_test
+depcomp
+dist
+dpmert/Makefile
+dpmert/Makefile.in
+dpmert/fast_score
+dpmert/lo_test
+dpmert/mr_dpmert_generate_mapper_input
+dpmert/mr_dpmert_map
+dpmert/mr_dpmert_reduce
+dpmert/scorer_test
+dpmert/sentclient
+dpmert/sentserver
+dpmert/union_forests
+dtrain/dtrain
+extools/build_lexical_translation
+extools/extractor
+extools/extractor_monolingual
+extools/featurize_grammar
+extools/filter_grammar
+extools/filter_score_grammar
+extools/mr_stripe_rule_reduce
+extools/score_grammar
+extools/sg_lexer.cc
+gi/clda/src/clda
+gi/markov_al/ml
+gi/pf/align-lexonly
+gi/pf/align-lexonly-pyp
gi/pf/align-tl
gi/pf/bayes_lattice_score
+gi/pf/brat
+gi/pf/cbgi
+gi/pf/condnaive
+gi/pf/dpnaive
+gi/pf/itg
+gi/pf/learn_cfg
gi/pf/nuisance_test
gi/pf/pf_test
+gi/pf/pfbrat
+gi/pf/pfdist
+gi/pf/pfnaive
gi/pf/pyp_lm
+gi/posterior-regularisation/prjava/build/
+gi/posterior-regularisation/prjava/lib/*.jar
+gi/posterior-regularisation/prjava/lib/prjava-20100713.jar
+gi/posterior-regularisation/prjava/lib/prjava-20100715.jar
+gi/posterior-regularisation/prjava/prjava.jar
+gi/pyp-topics/src/contexts_lexer.cc
+gi/pyp-topics/src/pyp-contexts-train
+gi/pyp-topics/src/pyp-topics-train
+install-sh
jam-files/bjam
jam-files/engine/bin.*
jam-files/engine/bootstrap/
klm/lm/bin/
+klm/lm/build_binary
klm/lm/query
klm/util/bin/
+libtool
+ltmain.sh
+m4/libtool.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4
+m4/lt~obsolete.m4
+minrisk/minrisk_optimize
+mira/kbest_mira
+missing
mteval/bin/
+mteval/fast_score
+mteval/mbr_kbest
+mteval/scorer_test
+phrasinator/gibbs_train_plm
+phrasinator/gibbs_train_plm_notables
+previous.sh
+pro-train/mr_pro_map
+pro-train/mr_pro_reduce
rampion/rampion_cccp
rst_parser/mst_train
+rst_parser/random_tree
rst_parser/rst_parse
rst_parser/rst_train
-rst_parser/random_tree
-training/liblbfgs/bin/
-training/liblbfgs/ll_test
-utils/atools
-utils/bin/
-utils/crp_test
-mira/kbest_mira
-utils/m_test
sa-extract/calignment.c
sa-extract/cdat.c
sa-extract/cfloatlist.c
@@ -53,125 +135,44 @@ sa-extract/precomputation.c
sa-extract/rule.c
sa-extract/rulefactory.c
sa-extract/sym.c
-training/lbl_model
-training/mpi_flex_optimize
-training/test_ngram
-utils/dict_test
-utils/logval_test
-utils/mfcr_test
-utils/phmt
-utils/small_vector_test
-utils/ts
-utils/weights_test
-pro-train/mr_pro_map
-pro-train/mr_pro_reduce
-utils/reconstruct_weights
+stamp-h1
+tests/system_tests/hmm/foo.src
+training/Makefile
+training/Makefile.in
+training/atools
training/augment_grammar
+training/cllh_filter_grammar
+training/collapse_weights
+training/grammar_convert
+training/lbfgs_test
+training/lbl_model
+training/liblbfgs/bin/
+training/liblbfgs/ll_test
+training/model1
training/mpi_batch_optimize
training/mpi_compute_cllh
training/mpi_em_optimize
training/mpi_extract_features
training/mpi_extract_reachable
-klm/lm/build_binary
-extools/extractor_monolingual
-gi/pf/learn_cfg
-gi/pf/brat
-gi/pf/cbgi
-gi/pf/dpnaive
-gi/pf/itg
-gi/pf/pfbrat
-gi/pf/pfdist
-gi/pf/pfnaive
-gi/markov_al/ml
-gi/posterior-regularisation/prjava/lib/*.jar
-tests/system_tests/hmm/foo.src
-training/cllh_filter_grammar
-mteval/fast_score
-mteval/mbr_kbest
+training/mpi_flex_optimize
training/mpi_online_optimize
-dpmert/sentserver
-dpmert/sentclient
-gi/pyp-topics/src/contexts_lexer.cc
-config.guess
-config.sub
-libtool
-ltmain.sh
-config.h.in~
-decoder/ff_test
-decoder/grammar_test
-decoder/hg_test
-decoder/parser_test
-decoder/small_vector_test
-decoder/rule_lexer.cc
-training/atools
-training/collapse_weights
-training/lbfgs_test
-training/mr_optimize_reduce
training/mr_em_adapted_reduce
training/mr_em_map_adapter
+training/mr_optimize_reduce
training/mr_reduce_to_weights
training/optimize_test
training/plftools
-dpmert/fast_score
-dpmert/lo_test
-dpmert/mr_dpmert_map
-dpmert/mr_dpmert_reduce
-dpmert/scorer_test
-dpmert/union_forests
-minrisk/minrisk_optimize
-Makefile
-Makefile.in
-aclocal.m4
-autom4te.cache/
-config.h
-config.h.in
-config.log
-config.status
-configure
-depcomp
-install-sh
-missing
-extools/extractor
-extools/mr_stripe_rule_reduce
-decoder/Makefile
-decoder/Makefile.in
-decoder/cdec
-decoder/dict_test
-decoder/trule_test
-decoder/weights_test
-stamp-h1
-training/Makefile
-training/Makefile.in
-training/grammar_convert
-training/model1
-dpmert/Makefile
-dpmert/Makefile.in
-dpmert/mr_dpmert_generate_mapper_input
-decoder/logval_test
-dtrain/dtrain
-extools/build_lexical_translation
-extools/filter_grammar
-extools/score_grammar
-gi/clda/src/clda
-gi/pyp-topics/src/pyp-topics-train
-m4/libtool.m4
-m4/ltoptions.m4
-m4/ltsugar.m4
-m4/ltversion.m4
-m4/lt~obsolete.m4
-extools/featurize_grammar
-extools/filter_score_grammar
-gi/posterior-regularisation/prjava/build/
-gi/posterior-regularisation/prjava/lib/prjava-20100713.jar
-gi/posterior-regularisation/prjava/prjava.jar
-gi/pyp-topics/src/pyp-contexts-train
-extools/sg_lexer.cc
-gi/posterior-regularisation/prjava/lib/prjava-20100715.jar
-gi/pf/align-lexonly
-gi/pf/align-lexonly-pyp
-gi/pf/condnaive
-mteval/scorer_test
-phrasinator/gibbs_train_plm
-phrasinator/gibbs_train_plm_notables
-previous.sh
-dist
+training/test_ngram
+utils/atools
+utils/bin/
+utils/crp_test
+utils/dict_test
+utils/logval_test
+utils/m_test
+utils/mfcr_test
+utils/phmt
+utils/reconstruct_weights
+utils/small_vector_test
+utils/ts
+utils/weights_test
+utils/unigram_pyp_lm
diff --git a/python/setup.py.in b/python/setup.py.in
index 77c10b07..4d77fbc7 100644
--- a/python/setup.py.in
+++ b/python/setup.py.in
@@ -1,35 +1,16 @@
from distutils.core import setup
from distutils.extension import Extension
-import sys
import re
-def fail(msg):
- sys.stderr.write(msg)
- sys.exit(1)
-
INC = ['..', 'src/', '../decoder', '../utils', '../mteval']
LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util']
-# set automatically by configure
-raw_config_libs = '@LIBS@'
-
-try:
- with open('../config.status') as config:
- config = config.read()
- subs = dict(re.findall('s,@(\w+)@,\|#_!!_#\|(.*),g', config)) # sed
- if not subs:
- subs = dict(re.findall('S\["(\w+)"\]="(.*)"', config)) # awk
- if not subs:
- fail('Cannot parse config.status\n'
- 'Please report this bug to the developers')
- LIBS = re.findall('-l([^\s]+)', subs['LIBS'])
- CPPFLAGS = re.findall('-[^R][^\s]+', subs['CPPFLAGS'])
- LDFLAGS = re.findall('-[^\s]+', subs['LDFLAGS'])
- LDFLAGS = [opt.replace('-R', '-Wl,-rpath,') for opt in LDFLAGS]
-except IOError:
- fail('Did you run ./configure? Cannot find config.status')
-except KeyError as e:
- fail('Cannot find option {0} in config.status'.format(e))
+# Set automatically by configure
+LIBS = re.findall('-l([^\s]+)', '@LIBS@')
+CPPFLAGS = re.findall('-[^\s]+', '@CPPFLAGS@')
+LDFLAGS = re.findall('-[^\s]+', '@LDFLAGS@')
+# Make sure linker flags go only to the linker
+LDFLAGS = [opt.replace('-R', '-Wl,-rpath,') for opt in LDFLAGS]
ext_modules = [
Extension(name='cdec._cdec',
diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp
index 87b836f1..dd812b52 100644
--- a/python/src/_cdec.cpp
+++ b/python/src/_cdec.cpp
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.17.beta1 on Wed Aug 8 18:52:57 2012 */
+/* Generated by Cython 0.17.beta1 on Sat Aug 11 23:26:15 2012 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@@ -840,7 +840,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ {
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52
- * return hypergraph.AsPLF(self.lattice[0], True).c_str()
+ * return str(hypergraph.AsPLF(self.lattice[0], True).c_str())
*
* def __iter__(self): # <<<<<<<<<<<<<<
* cdef unsigned i
@@ -856,7 +856,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ {
/* "_cdec.pyx":42
- * yield key, bytes(value)
+ * yield key, str(value)
*
* cdef class Decoder: # <<<<<<<<<<<<<<
* cdef decoder.Decoder* dec
@@ -979,7 +979,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ {
};
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":173
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":172
* out.fields[i] = ss[i]
*
* cdef class Metric: # <<<<<<<<<<<<<<
@@ -1824,7 +1824,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_37__div__(PyObject *__pyx_v_x, P
#endif
static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */
-static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, char *__pyx_v_cat, unsigned int __pyx_v_ref); /* proto */
+static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, unsigned int __pyx_v_ref); /* proto */
static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */
static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
@@ -2824,7 +2824,7 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_12generator(__pyx_GeneratorObject
* def __iter__(self):
* cdef unsigned fid
* for fid in range(1, self.vector.size()): # <<<<<<<<<<<<<<
- * yield FDConvert(fid).c_str(), self.vector[0][fid]
+ * yield str(FDConvert(fid).c_str()), self.vector[0][fid]
*
*/
__pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size();
@@ -2834,18 +2834,26 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_12generator(__pyx_GeneratorObject
/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":34
* cdef unsigned fid
* for fid in range(1, self.vector.size()):
- * yield FDConvert(fid).c_str(), self.vector[0][fid] # <<<<<<<<<<<<<<
+ * yield str(FDConvert(fid).c_str()), self.vector[0][fid] # <<<<<<<<<<<<<<
*
* def dot(self, SparseVector other):
*/
__pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3));
- __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_3 = 0;
@@ -2896,7 +2904,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_14dot(PyObject *__pyx_v_self, PyO
}
/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36
- * yield FDConvert(fid).c_str(), self.vector[0][fid]
+ * yield str(FDConvert(fid).c_str()), self.vector[0][fid]
*
* def dot(self, SparseVector other): # <<<<<<<<<<<<<<
* return other.dot(self)
@@ -3459,7 +3467,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObje
* cdef unsigned i
* try: # <<<<<<<<<<<<<<
* for i in range(self.vector.size()):
- * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second)
+ * yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second)
*/
/*try:*/ {
@@ -3467,7 +3475,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObje
* cdef unsigned i
* try:
* for i in range(self.vector.size()): # <<<<<<<<<<<<<<
- * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second)
+ * yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second)
* pinc(it[0]) # ++it
*/
__pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size();
@@ -3477,18 +3485,26 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObje
/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72
* try:
* for i in range(self.vector.size()):
- * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) # <<<<<<<<<<<<<<
+ * yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second) # <<<<<<<<<<<<<<
* pinc(it[0]) # ++it
* finally:
*/
__pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;}
+ __Pyx_GOTREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
+ __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
__pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;}
__Pyx_GOTREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3));
- __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_4);
__pyx_t_3 = 0;
@@ -3509,7 +3525,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObje
/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73
* for i in range(self.vector.size()):
- * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second)
+ * yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second)
* pinc(it[0]) # ++it # <<<<<<<<<<<<<<
* finally:
* del it
@@ -4888,7 +4904,7 @@ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyO
/* Python wrapper */
static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- char *__pyx_v_cat;
+ PyObject *__pyx_v_cat = 0;
unsigned int __pyx_v_ref;
int __pyx_r;
__Pyx_RefNannyDeclarations
@@ -4927,7 +4943,7 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx
default: goto __pyx_L5_argtuple_error;
}
}
- __pyx_v_cat = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_cat) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_cat = ((PyObject*)values[0]);
if (values[1]) {
__pyx_v_ref = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_ref == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
} else {
@@ -4942,7 +4958,12 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx
__Pyx_RefNannyFinishContext();
return -1;
__pyx_L4_argument_unpacking_done:;
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_cat), (&PyBytes_Type), 1, "cat", 1))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_r = __pyx_pf_5_cdec_2NT___init__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self), __pyx_v_cat, __pyx_v_ref);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __pyx_r = -1;
+ __pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
@@ -4950,37 +4971,31 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":11
* cdef public bytes cat
* cdef public unsigned ref
- * def __init__(self, char* cat, unsigned ref=0): # <<<<<<<<<<<<<<
+ * def __init__(self, bytes cat, unsigned ref=0): # <<<<<<<<<<<<<<
* self.cat = cat
* self.ref = ref
*/
-static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, char *__pyx_v_cat, unsigned int __pyx_v_ref) {
+static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, unsigned int __pyx_v_ref) {
int __pyx_r;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__init__", 0);
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":12
* cdef public unsigned ref
- * def __init__(self, char* cat, unsigned ref=0):
+ * def __init__(self, bytes cat, unsigned ref=0):
* self.cat = cat # <<<<<<<<<<<<<<
* self.ref = ref
*
*/
- __pyx_t_1 = PyBytes_FromString(__pyx_v_cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(((PyObject *)__pyx_v_cat));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_cat));
__Pyx_GOTREF(__pyx_v_self->cat);
__Pyx_DECREF(((PyObject *)__pyx_v_self->cat));
- __pyx_v_self->cat = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_v_self->cat = __pyx_v_cat;
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":13
- * def __init__(self, char* cat, unsigned ref=0):
+ * def __init__(self, bytes cat, unsigned ref=0):
* self.cat = cat
* self.ref = ref # <<<<<<<<<<<<<<
*
@@ -4989,12 +5004,6 @@ static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self
__pyx_v_self->ref = __pyx_v_ref;
__pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("_cdec.NT.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- __pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
@@ -5110,7 +5119,7 @@ static PyObject *__pyx_pw_5_cdec_2NT_3cat_1__get__(PyObject *__pyx_v_self) {
* cdef class NT:
* cdef public bytes cat # <<<<<<<<<<<<<<
* cdef public unsigned ref
- * def __init__(self, char* cat, unsigned ref=0):
+ * def __init__(self, bytes cat, unsigned ref=0):
*/
static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self) {
@@ -5205,7 +5214,7 @@ static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self) {
* cdef class NT:
* cdef public bytes cat
* cdef public unsigned ref # <<<<<<<<<<<<<<
- * def __init__(self, char* cat, unsigned ref=0):
+ * def __init__(self, bytes cat, unsigned ref=0):
* self.cat = cat
*/
@@ -6220,7 +6229,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule
* w = f_[0][i]
* if w < 0: # <<<<<<<<<<<<<<
* idx += 1
- * f.append(NT(TDConvert(-w), idx))
+ * f.append(NT(TDConvert(-w).c_str(), idx))
*/
__pyx_t_4 = (__pyx_v_w < 0);
if (__pyx_t_4) {
@@ -6229,7 +6238,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule
* w = f_[0][i]
* if w < 0:
* idx += 1 # <<<<<<<<<<<<<<
- * f.append(NT(TDConvert(-w), idx))
+ * f.append(NT(TDConvert(-w).c_str(), idx))
* else:
*/
__pyx_v_idx = (__pyx_v_idx + 1);
@@ -6237,11 +6246,11 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":81
* if w < 0:
* idx += 1
- * f.append(NT(TDConvert(-w), idx)) # <<<<<<<<<<<<<<
+ * f.append(NT(TDConvert(-w).c_str(), idx)) # <<<<<<<<<<<<<<
* else:
- * f.append(unicode(TDConvert(w), encoding='utf8'))
+ * f.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
*/
- __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w)).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
@@ -6265,13 +6274,13 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule
/*else*/ {
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":83
- * f.append(NT(TDConvert(-w), idx))
+ * f.append(NT(TDConvert(-w).c_str(), idx))
* else:
- * f.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<<
+ * f.append(unicode(TDConvert(w).c_str(), encoding='utf8')) # <<<<<<<<<<<<<<
* return f
*
*/
- __pyx_t_6 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyBytes_FromString(TD::Convert(__pyx_v_w).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_6));
__pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
@@ -6295,7 +6304,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":84
* else:
- * f.append(unicode(TDConvert(w), encoding='utf8'))
+ * f.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
* return f # <<<<<<<<<<<<<<
*
* def __set__(self, f):
@@ -6569,7 +6578,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule
* idx += 1
* e.append(NTRef(1-w)) # <<<<<<<<<<<<<<
* else:
- * e.append(unicode(TDConvert(w), encoding='utf8'))
+ * e.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
*/
__pyx_t_1 = PyInt_FromLong((1 - __pyx_v_w)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
@@ -6592,11 +6601,11 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":110
* e.append(NTRef(1-w))
* else:
- * e.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<<
+ * e.append(unicode(TDConvert(w).c_str(), encoding='utf8')) # <<<<<<<<<<<<<<
* return e
*
*/
- __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w).c_str()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_5));
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
@@ -6620,7 +6629,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":111
* else:
- * e.append(unicode(TDConvert(w), encoding='utf8'))
+ * e.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
* return e # <<<<<<<<<<<<<<
*
* def __set__(self, e):
@@ -7392,7 +7401,7 @@ static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self) {
*
* property lhs:
* def __get__(self): # <<<<<<<<<<<<<<
- * return NT(TDConvert(-self.rule.get().lhs_))
+ * return NT(TDConvert(-self.rule.get().lhs_).c_str())
*
*/
@@ -7409,12 +7418,12 @@ static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRu
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":157
* property lhs:
* def __get__(self):
- * return NT(TDConvert(-self.rule.get().lhs_)) # <<<<<<<<<<<<<<
+ * return NT(TDConvert(-self.rule.get().lhs_).c_str()) # <<<<<<<<<<<<<<
*
* def __set__(self, lhs):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->get()->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->get()->lhs_)).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
@@ -7453,7 +7462,7 @@ static int __pyx_pw_5_cdec_5TRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject
}
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":159
- * return NT(TDConvert(-self.rule.get().lhs_))
+ * return NT(TDConvert(-self.rule.get().lhs_).c_str())
*
* def __set__(self, lhs): # <<<<<<<<<<<<<<
* if not isinstance(lhs, NT):
@@ -8325,25 +8334,47 @@ static PyObject *__pyx_pw_5_cdec_7Grammar_4name_1__get__(PyObject *__pyx_v_self)
*
* property name:
* def __get__(self): # <<<<<<<<<<<<<<
- * self.grammar.get().GetGrammarName().c_str()
+ * str(self.grammar.get().GetGrammarName().c_str())
*
*/
static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__get__", 0);
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":199
* property name:
* def __get__(self):
- * self.grammar.get().GetGrammarName().c_str() # <<<<<<<<<<<<<<
+ * str(self.grammar.get().GetGrammarName().c_str()) # <<<<<<<<<<<<<<
*
* def __set__(self, name):
*/
- __pyx_v_self->grammar->get()->GetGrammarName().c_str();
+ __pyx_t_1 = PyBytes_FromString(__pyx_v_self->grammar->get()->GetGrammarName().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Grammar.name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
@@ -8361,7 +8392,7 @@ static int __pyx_pw_5_cdec_7Grammar_4name_3__set__(PyObject *__pyx_v_self, PyObj
}
/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":201
- * self.grammar.get().GetGrammarName().c_str()
+ * str(self.grammar.get().GetGrammarName().c_str())
*
* def __set__(self, name): # <<<<<<<<<<<<<<
* self.grammar.get().SetGrammarName(string(<char *>name))
@@ -10474,7 +10505,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_30lattice(PyObject *__pyx_v_self,
* del preserve_mask
*
* def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<<
- * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str()
+ * cdef bytes plf = hypergraph.AsPLF(self.hg[0], True).c_str()
* return Lattice(eval(plf))
*/
@@ -10493,19 +10524,18 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_29lattice(struct __pyx_obj_5_cdec_
/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":114
*
* def lattice(self): # TODO direct hg -> lattice conversion in cdec
- * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<<
+ * cdef bytes plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<<
* return Lattice(eval(plf))
*
*/
__pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_v_plf = ((PyObject*)__pyx_t_1);
+ __pyx_v_plf = __pyx_t_1;
__pyx_t_1 = 0;
/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115
* def lattice(self): # TODO direct hg -> lattice conversion in cdec
- * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str()
+ * cdef bytes plf = hypergraph.AsPLF(self.hg[0], True).c_str()
* return Lattice(eval(plf)) # <<<<<<<<<<<<<<
*
* def reweight(self, weights):
@@ -12318,13 +12348,14 @@ static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_
* property cat:
* def __get__(self): # <<<<<<<<<<<<<<
* if self.node.cat_:
- * return TDConvert(-self.node.cat_)
+ * return str(TDConvert(-self.node.cat_).c_str())
*/
static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -12334,7 +12365,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_
* property cat:
* def __get__(self):
* if self.node.cat_: # <<<<<<<<<<<<<<
- * return TDConvert(-self.node.cat_)
+ * return str(TDConvert(-self.node.cat_).c_str())
*
*/
if (__pyx_v_self->node->cat_) {
@@ -12342,14 +12373,22 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_
/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":234
* def __get__(self):
* if self.node.cat_:
- * return TDConvert(-self.node.cat_) # <<<<<<<<<<<<<<
+ * return str(TDConvert(-self.node.cat_).c_str()) # <<<<<<<<<<<<<<
*
* def __richcmp__(HypergraphNode x, HypergraphNode y, int op):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->node->cat_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->node->cat_)).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
goto __pyx_L3;
@@ -12360,6 +12399,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cdec.HypergraphNode.cat.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
@@ -12386,7 +12426,7 @@ static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v
}
/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":236
- * return TDConvert(-self.node.cat_)
+ * return str(TDConvert(-self.node.cat_).c_str())
*
* def __richcmp__(HypergraphNode x, HypergraphNode y, int op): # <<<<<<<<<<<<<<
* if op == 2: # ==
@@ -12902,7 +12942,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_L
* cdef unsigned i
* for i in range(arc_vector.size()): # <<<<<<<<<<<<<<
* arc = &arc_vector[i]
- * label = unicode(TDConvert(arc.label), 'utf8')
+ * label = unicode(TDConvert(arc.label).c_str(), 'utf8')
*/
__pyx_t_5 = __pyx_v_arc_vector.size();
for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
@@ -12912,7 +12952,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_L
* cdef unsigned i
* for i in range(arc_vector.size()):
* arc = &arc_vector[i] # <<<<<<<<<<<<<<
- * label = unicode(TDConvert(arc.label), 'utf8')
+ * label = unicode(TDConvert(arc.label).c_str(), 'utf8')
* arcs.append((label, arc.cost, arc.dist2next))
*/
__pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i]));
@@ -12920,11 +12960,11 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_L
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":31
* for i in range(arc_vector.size()):
* arc = &arc_vector[i]
- * label = unicode(TDConvert(arc.label), 'utf8') # <<<<<<<<<<<<<<
+ * label = unicode(TDConvert(arc.label).c_str(), 'utf8') # <<<<<<<<<<<<<<
* arcs.append((label, arc.cost, arc.dist2next))
* return tuple(arcs)
*/
- __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_4));
__pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
@@ -12943,7 +12983,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_L
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32
* arc = &arc_vector[i]
- * label = unicode(TDConvert(arc.label), 'utf8')
+ * label = unicode(TDConvert(arc.label).c_str(), 'utf8')
* arcs.append((label, arc.cost, arc.dist2next)) # <<<<<<<<<<<<<<
* return tuple(arcs)
*
@@ -12968,7 +13008,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_L
}
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33
- * label = unicode(TDConvert(arc.label), 'utf8')
+ * label = unicode(TDConvert(arc.label).c_str(), 'utf8')
* arcs.append((label, arc.cost, arc.dist2next))
* return tuple(arcs) # <<<<<<<<<<<<<<
*
@@ -13309,7 +13349,7 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_11__str__(PyObject *__pyx_v_self) {
* return self.lattice.size()
*
* def __str__(self): # <<<<<<<<<<<<<<
- * return hypergraph.AsPLF(self.lattice[0], True).c_str()
+ * return str(hypergraph.AsPLF(self.lattice[0], True).c_str())
*
*/
@@ -13317,6 +13357,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__str__(struct __pyx_obj_5_cdec_Latt
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -13325,14 +13366,22 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__str__(struct __pyx_obj_5_cdec_Latt
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50
*
* def __str__(self):
- * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<<
+ * return str(hypergraph.AsPLF(self.lattice[0], True).c_str()) # <<<<<<<<<<<<<<
*
* def __iter__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
@@ -13340,6 +13389,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__str__(struct __pyx_obj_5_cdec_Latt
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
@@ -13361,7 +13411,7 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_13__iter__(PyObject *__pyx_v_self) {
}
/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52
- * return hypergraph.AsPLF(self.lattice[0], True).c_str()
+ * return str(hypergraph.AsPLF(self.lattice[0], True).c_str())
*
* def __iter__(self): # <<<<<<<<<<<<<<
* cdef unsigned i
@@ -14462,7 +14512,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__
*
* property detail:
* def __get__(self): # <<<<<<<<<<<<<<
- * return self.metric.DetailedScore(self.stats[0]).c_str()
+ * return str(self.metric.DetailedScore(self.stats[0]).c_str())
*
*/
@@ -14470,6 +14520,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -14478,14 +14529,22 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_
/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39
* property detail:
* def __get__(self):
- * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<<
+ * return str(self.metric.DetailedScore(self.stats[0]).c_str()) # <<<<<<<<<<<<<<
*
* def __len__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
@@ -14493,6 +14552,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cdec.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
@@ -14513,7 +14573,7 @@ static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_s
}
/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41
- * return self.metric.DetailedScore(self.stats[0]).c_str()
+ * return str(self.metric.DetailedScore(self.stats[0]).c_str())
*
* def __len__(self): # <<<<<<<<<<<<<<
* return self.stats.size()
@@ -15980,13 +16040,13 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
* refs = [refs]
* cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<<
* cdef vector[WordID]* refv
- * cdef bytes ref_str
+ * for ref in refs:
*/
__pyx_v_refsv = new std::vector<std::vector<WordID> >();
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134
+ * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]()
* cdef vector[WordID]* refv
- * cdef bytes ref_str
* for ref in refs: # <<<<<<<<<<<<<<
* refv = new vector[WordID]()
* ConvertSentence(string(as_str(ref.strip())), refv)
@@ -15995,7 +16055,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
__pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
- __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
}
@@ -16005,21 +16065,21 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
#if CYTHON_COMPILING_IN_CPYTHON
__pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++;
#else
- __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
#endif
} else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_COMPILING_IN_CPYTHON
__pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++;
#else
- __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
#endif
} else {
__pyx_t_7 = __pyx_t_6(__pyx_t_1);
if (unlikely(!__pyx_t_7)) {
if (PyErr_Occurred()) {
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
- else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
break;
}
@@ -16029,8 +16089,8 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
__pyx_v_ref = __pyx_t_7;
__pyx_t_7 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136
- * cdef bytes ref_str
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135
+ * cdef vector[WordID]* refv
* for ref in refs:
* refv = new vector[WordID]() # <<<<<<<<<<<<<<
* ConvertSentence(string(as_str(ref.strip())), refv)
@@ -16038,22 +16098,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
*/
__pyx_v_refv = new std::vector<WordID>();
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136
* for ref in refs:
* refv = new vector[WordID]()
* ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<<
* refsv.push_back(refv[0])
* del refv
*/
- __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
- __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137
* refv = new vector[WordID]()
* ConvertSentence(string(as_str(ref.strip())), refv)
* refsv.push_back(refv[0]) # <<<<<<<<<<<<<<
@@ -16062,7 +16122,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
*/
__pyx_v_refsv->push_back((__pyx_v_refv[0]));
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138
* ConvertSentence(string(as_str(ref.strip())), refv)
* refsv.push_back(refv[0])
* del refv # <<<<<<<<<<<<<<
@@ -16073,19 +16133,19 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140
* del refv
* cdef unsigned i
* cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<<
* evaluator.metric = self.metric
* evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](
*/
- __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1);
__pyx_t_1 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141
* cdef unsigned i
* cdef SegmentEvaluator evaluator = SegmentEvaluator()
* evaluator.metric = self.metric # <<<<<<<<<<<<<<
@@ -16094,7 +16154,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
*/
__pyx_v_evaluator->metric = __pyx_v_self->metric;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142
* cdef SegmentEvaluator evaluator = SegmentEvaluator()
* evaluator.metric = self.metric
* evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( # <<<<<<<<<<<<<<
@@ -16103,7 +16163,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
*/
__pyx_v_evaluator->scorer = new boost::shared_ptr<SegmentEvaluator>(__pyx_v_self->metric->CreateSegmentEvaluator((__pyx_v_refsv[0])));
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":145
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144
* evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](
* self.metric.CreateSegmentEvaluator(refsv[0]))
* del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<<
@@ -16112,7 +16172,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score
*/
delete __pyx_v_refsv;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":146
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":145
* self.metric.CreateSegmentEvaluator(refsv[0]))
* del refsv # in theory should not delete but store in SegmentEvaluator
* return evaluator # <<<<<<<<<<<<<<
@@ -16152,11 +16212,11 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) {
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":148
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":147
* return evaluator
*
* def __str__(self): # <<<<<<<<<<<<<<
- * return self.name.c_str()
+ * return str(self.name.c_str())
*
*/
@@ -16164,22 +16224,31 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__str__", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":149
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":148
*
* def __str__(self):
- * return self.name.c_str() # <<<<<<<<<<<<<<
+ * return str(self.name.c_str()) # <<<<<<<<<<<<<<
*
* cdef float _compute_score(void* metric_, mteval.SufficientStats* stats):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
@@ -16187,6 +16256,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cdec.Scorer.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
@@ -16195,8 +16265,8 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":151
- * return self.name.c_str()
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":150
+ * return str(self.name.c_str())
*
* cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): # <<<<<<<<<<<<<<
* cdef Metric metric = <Metric> metric_
@@ -16221,7 +16291,7 @@ static float __pyx_f_5_cdec__compute_score(void *__pyx_v_metric_, SufficientStat
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("_compute_score", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":152
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":151
*
* cdef float _compute_score(void* metric_, mteval.SufficientStats* stats):
* cdef Metric metric = <Metric> metric_ # <<<<<<<<<<<<<<
@@ -16231,19 +16301,19 @@ static float __pyx_f_5_cdec__compute_score(void *__pyx_v_metric_, SufficientStat
__Pyx_INCREF(((PyObject *)((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_)));
__pyx_v_metric = ((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":152
* cdef float _compute_score(void* metric_, mteval.SufficientStats* stats):
* cdef Metric metric = <Metric> metric_
* cdef list ss = [] # <<<<<<<<<<<<<<
* cdef unsigned i
* for i in range(stats.size()):
*/
- __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_ss = __pyx_t_1;
__pyx_t_1 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":155
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":154
* cdef list ss = []
* cdef unsigned i
* for i in range(stats.size()): # <<<<<<<<<<<<<<
@@ -16254,38 +16324,38 @@ static float __pyx_f_5_cdec__compute_score(void *__pyx_v_metric_, SufficientStat
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
__pyx_v_i = __pyx_t_3;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":156
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":155
* cdef unsigned i
* for i in range(stats.size()):
* ss.append(stats[0][i]) # <<<<<<<<<<<<<<
* return metric.score(ss)
*
*/
- __pyx_t_1 = PyFloat_FromDouble(((__pyx_v_stats[0])[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(((__pyx_v_stats[0])[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_4 = PyList_Append(__pyx_v_ss, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyList_Append(__pyx_v_ss, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":157
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":156
* for i in range(stats.size()):
* ss.append(stats[0][i])
* return metric.score(ss) # <<<<<<<<<<<<<<
*
* cdef void _compute_sufficient_stats(void* metric_,
*/
- __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(((PyObject *)__pyx_v_ss));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_ss));
__Pyx_GIVEREF(((PyObject *)__pyx_v_ss));
- __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
- __pyx_t_7 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_7 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_7 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_r = __pyx_t_7;
goto __pyx_L0;
@@ -16305,7 +16375,7 @@ static float __pyx_f_5_cdec__compute_score(void *__pyx_v_metric_, SufficientStat
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":159
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":158
* return metric.score(ss)
*
* cdef void _compute_sufficient_stats(void* metric_, # <<<<<<<<<<<<<<
@@ -16322,8 +16392,8 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std:
PyObject *__pyx_t_1 = NULL;
size_t __pyx_t_2;
unsigned int __pyx_t_3;
- int __pyx_t_4;
- PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
Py_ssize_t __pyx_t_7;
float __pyx_t_8;
@@ -16332,7 +16402,7 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std:
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("_compute_sufficient_stats", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":163
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":162
* vector[string]* refs,
* mteval.SufficientStats* out):
* cdef Metric metric = <Metric> metric_ # <<<<<<<<<<<<<<
@@ -16342,85 +16412,101 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std:
__Pyx_INCREF(((PyObject *)((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_)));
__pyx_v_metric = ((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":164
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":163
* mteval.SufficientStats* out):
* cdef Metric metric = <Metric> metric_
* cdef list refs_ = [] # <<<<<<<<<<<<<<
* cdef unsigned i
* for i in range(refs.size()):
*/
- __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_refs_ = __pyx_t_1;
__pyx_t_1 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":166
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":165
* cdef list refs_ = []
* cdef unsigned i
* for i in range(refs.size()): # <<<<<<<<<<<<<<
- * refs_.append(refs[0][i].c_str())
- * cdef list ss = metric.evaluate(hyp.c_str(), refs_)
+ * refs_.append(str(refs[0][i].c_str()))
+ * cdef list ss = metric.evaluate(str(hyp.c_str()), refs_)
*/
__pyx_t_2 = __pyx_v_refs->size();
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
__pyx_v_i = __pyx_t_3;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":167
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":166
* cdef unsigned i
* for i in range(refs.size()):
- * refs_.append(refs[0][i].c_str()) # <<<<<<<<<<<<<<
- * cdef list ss = metric.evaluate(hyp.c_str(), refs_)
+ * refs_.append(str(refs[0][i].c_str())) # <<<<<<<<<<<<<<
+ * cdef list ss = metric.evaluate(str(hyp.c_str()), refs_)
* out.fields.resize(len(ss))
*/
- __pyx_t_1 = PyBytes_FromString(((__pyx_v_refs[0])[__pyx_v_i]).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(((__pyx_v_refs[0])[__pyx_v_i]).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_t_4 = PyList_Append(__pyx_v_refs_, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
+ __pyx_t_5 = PyList_Append(__pyx_v_refs_, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":168
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":167
* for i in range(refs.size()):
- * refs_.append(refs[0][i].c_str())
- * cdef list ss = metric.evaluate(hyp.c_str(), refs_) # <<<<<<<<<<<<<<
+ * refs_.append(str(refs[0][i].c_str()))
+ * cdef list ss = metric.evaluate(str(hyp.c_str()), refs_) # <<<<<<<<<<<<<<
* out.fields.resize(len(ss))
* for i in range(len(ss)):
*/
- __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__evaluate); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__evaluate); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_5 = PyBytes_FromString(__pyx_v_hyp->c_str()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(((PyObject *)__pyx_t_5));
- __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyBytes_FromString(__pyx_v_hyp->c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_4));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
+ __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
- PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
- __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
+ PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_4);
__Pyx_INCREF(((PyObject *)__pyx_v_refs_));
PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_refs_));
__Pyx_GIVEREF(((PyObject *)__pyx_v_refs_));
- __pyx_t_5 = 0;
- __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
- if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected list, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_v_ss = ((PyObject*)__pyx_t_5);
- __pyx_t_5 = 0;
+ if (!(likely(PyList_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected list, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_ss = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":169
- * refs_.append(refs[0][i].c_str())
- * cdef list ss = metric.evaluate(hyp.c_str(), refs_)
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":168
+ * refs_.append(str(refs[0][i].c_str()))
+ * cdef list ss = metric.evaluate(str(hyp.c_str()), refs_)
* out.fields.resize(len(ss)) # <<<<<<<<<<<<<<
* for i in range(len(ss)):
* out.fields[i] = ss[i]
*/
if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
- {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_out->fields.resize(__pyx_t_7);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":170
- * cdef list ss = metric.evaluate(hyp.c_str(), refs_)
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":169
+ * cdef list ss = metric.evaluate(str(hyp.c_str()), refs_)
* out.fields.resize(len(ss))
* for i in range(len(ss)): # <<<<<<<<<<<<<<
* out.fields[i] = ss[i]
@@ -16428,13 +16514,13 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std:
*/
if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
- {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_7; __pyx_t_3+=1) {
__pyx_v_i = __pyx_t_3;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":171
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":170
* out.fields.resize(len(ss))
* for i in range(len(ss)):
* out.fields[i] = ss[i] # <<<<<<<<<<<<<<
@@ -16443,19 +16529,19 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std:
*/
if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
- {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- __pyx_t_5 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_ss), __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_t_4 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_ss), __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
(__pyx_v_out->fields[__pyx_v_i]) = __pyx_t_8;
}
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_WriteUnraisable("_cdec._compute_sufficient_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_L0:;
@@ -16479,7 +16565,7 @@ static int __pyx_pw_5_cdec_6Metric_1__cinit__(PyObject *__pyx_v_self, PyObject *
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":175
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":174
* cdef class Metric:
* cdef Scorer scorer
* def __cinit__(self): # <<<<<<<<<<<<<<
@@ -16497,14 +16583,14 @@ static int __pyx_pf_5_cdec_6Metric___cinit__(struct __pyx_obj_5_cdec_Metric *__p
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__cinit__", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":176
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":175
* cdef Scorer scorer
* def __cinit__(self):
* self.scorer = Scorer() # <<<<<<<<<<<<<<
* self.scorer.name = new string(as_str(self.__class__.__name__))
* self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0],
*/
- __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_GOTREF(__pyx_v_self->scorer);
@@ -16512,22 +16598,22 @@ static int __pyx_pf_5_cdec_6Metric___cinit__(struct __pyx_obj_5_cdec_Metric *__p
__pyx_v_self->scorer = ((struct __pyx_obj_5_cdec_Scorer *)__pyx_t_1);
__pyx_t_1 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":177
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":176
* def __cinit__(self):
* self.scorer = Scorer()
* self.scorer.name = new string(as_str(self.__class__.__name__)) # <<<<<<<<<<<<<<
* self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0],
* <void*> self, _compute_sufficient_stats, _compute_score)
*/
- __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_self->scorer->name = new std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL));
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":178
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":177
* self.scorer = Scorer()
* self.scorer.name = new string(as_str(self.__class__.__name__))
* self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0], # <<<<<<<<<<<<<<
@@ -16573,7 +16659,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObj
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
goto __pyx_L5_argtuple_error;
@@ -16584,7 +16670,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObj
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_cdec.Metric.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
@@ -16595,7 +16681,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObj
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":181
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":180
* <void*> self, _compute_sufficient_stats, _compute_score)
*
* def __call__(self, refs): # <<<<<<<<<<<<<<
@@ -16613,7 +16699,7 @@ static PyObject *__pyx_pf_5_cdec_6Metric_2__call__(struct __pyx_obj_5_cdec_Metri
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__call__", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":182
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":181
*
* def __call__(self, refs):
* return self.scorer(refs) # <<<<<<<<<<<<<<
@@ -16621,12 +16707,12 @@ static PyObject *__pyx_pf_5_cdec_6Metric_2__call__(struct __pyx_obj_5_cdec_Metri
* def score(SufficientStats stats):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_refs);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs);
__Pyx_GIVEREF(__pyx_v_refs);
- __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_self->scorer), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_self->scorer), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
@@ -16657,7 +16743,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_5score(PyObject *__pyx_v_stats, CYTHON_
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":184
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":183
* return self.scorer(refs)
*
* def score(SufficientStats stats): # <<<<<<<<<<<<<<
@@ -16670,7 +16756,7 @@ static PyObject *__pyx_pf_5_cdec_6Metric_4score(CYTHON_UNUSED struct __pyx_obj_5
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("score", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":185
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":184
*
* def score(SufficientStats stats):
* return 0 # <<<<<<<<<<<<<<
@@ -16717,11 +16803,11 @@ static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObj
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "evaluate") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "evaluate") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
@@ -16734,7 +16820,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObj
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_cdec.Metric.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
@@ -16745,7 +16831,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObj
return __pyx_r;
}
-/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":187
+/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":186
* return 0
*
* def evaluate(self, hyp, refs): # <<<<<<<<<<<<<<
@@ -16762,7 +16848,7 @@ static PyObject *__pyx_pf_5_cdec_6Metric_6evaluate(CYTHON_UNUSED struct __pyx_ob
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("evaluate", 0);
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":188
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":187
*
* def evaluate(self, hyp, refs):
* return [] # <<<<<<<<<<<<<<
@@ -16770,7 +16856,7 @@ static PyObject *__pyx_pf_5_cdec_6Metric_6evaluate(CYTHON_UNUSED struct __pyx_ob
* BLEU = Scorer('IBM_BLEU')
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = ((PyObject *)__pyx_t_1);
__pyx_t_1 = 0;
@@ -17275,7 +17361,7 @@ static PyObject *__pyx_gb_5_cdec_6generator17(__pyx_GeneratorObject *__pyx_gener
* for name in value:
* yield key, name # <<<<<<<<<<<<<<
* else:
- * yield key, bytes(value)
+ * yield key, str(value)
*/
__pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
@@ -17321,7 +17407,7 @@ static PyObject *__pyx_gb_5_cdec_6generator17(__pyx_GeneratorObject *__pyx_gener
/* "_cdec.pyx":40
* yield key, name
* else:
- * yield key, bytes(value) # <<<<<<<<<<<<<<
+ * yield key, str(value) # <<<<<<<<<<<<<<
*
* cdef class Decoder:
*/
@@ -17330,7 +17416,7 @@ static PyObject *__pyx_gb_5_cdec_6generator17(__pyx_GeneratorObject *__pyx_gener
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_value);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_value);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value);
- __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -18209,7 +18295,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_
* property formalism:
* def __get__(self): # <<<<<<<<<<<<<<
* cdef variables_map* conf = &self.dec.GetConf()
- * return conf[0]['formalism'].as_str().c_str()
+ * return str(conf[0]['formalism'].as_str().c_str())
*/
static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) {
@@ -18217,6 +18303,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -18226,7 +18313,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_
* property formalism:
* def __get__(self):
* cdef variables_map* conf = &self.dec.GetConf() # <<<<<<<<<<<<<<
- * return conf[0]['formalism'].as_str().c_str()
+ * return str(conf[0]['formalism'].as_str().c_str())
*
*/
__pyx_v_conf = (&__pyx_v_self->dec->GetConf());
@@ -18234,14 +18321,22 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_
/* "_cdec.pyx":88
* def __get__(self):
* cdef variables_map* conf = &self.dec.GetConf()
- * return conf[0]['formalism'].as_str().c_str() # <<<<<<<<<<<<<<
+ * return str(conf[0]['formalism'].as_str().c_str()) # <<<<<<<<<<<<<<
*
* def read_weights(self, weights):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyBytes_FromString(((__pyx_v_conf[0])[__pyx_k__formalism]).as<std::string>().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
+ __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
@@ -18249,6 +18344,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("_cdec.Decoder.formalism.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
@@ -18269,7 +18365,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self,
}
/* "_cdec.pyx":90
- * return conf[0]['formalism'].as_str().c_str()
+ * return str(conf[0]['formalism'].as_str().c_str())
*
* def read_weights(self, weights): # <<<<<<<<<<<<<<
* with open(weights) as fp:
@@ -28413,39 +28509,39 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56));
__pyx_k_codeobj_57 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_58, __pyx_n_s___phrase, 5, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_57)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":189
* return []
*
* BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<<
* TER = Scorer('TER')
* CER = Scorer('CER')
*/
- __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_k_tuple_59);
__Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU));
PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__IBM_BLEU));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59));
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190
*
* BLEU = Scorer('IBM_BLEU')
* TER = Scorer('TER') # <<<<<<<<<<<<<<
* CER = Scorer('CER')
*/
- __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_k_tuple_60);
__Pyx_INCREF(((PyObject *)__pyx_n_s__TER));
PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_n_s__TER));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191
* BLEU = Scorer('IBM_BLEU')
* TER = Scorer('TER')
* CER = Scorer('CER') # <<<<<<<<<<<<<<
*/
- __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_k_tuple_61);
__Pyx_INCREF(((PyObject *)__pyx_n_s__CER));
PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_n_s__CER));
@@ -28643,8 +28739,8 @@ PyMODINIT_FUNC PyInit__cdec(void)
if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer;
- if (PyType_Ready(&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (__Pyx_SetAttrString(__pyx_m, "Metric", (PyObject *)&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Metric", (PyObject *)&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec_Metric = &__pyx_type_5_cdec_Metric;
if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__Pyx_SetAttrString(__pyx_m, "Decoder", (PyObject *)&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -28745,37 +28841,37 @@ PyMODINIT_FUNC PyInit__cdec(void)
if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":189
* return []
*
* BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<<
* TER = Scorer('TER')
* CER = Scorer('CER')
*/
- __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190
*
* BLEU = Scorer('IBM_BLEU')
* TER = Scorer('TER') # <<<<<<<<<<<<<<
* CER = Scorer('CER')
*/
- __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192
+ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191
* BLEU = Scorer('IBM_BLEU')
* TER = Scorer('TER')
* CER = Scorer('CER') # <<<<<<<<<<<<<<
*/
- __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* "_cdec.pyx":22
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx
index af4e5f2f..5cdf8eb3 100644
--- a/python/src/_cdec.pyx
+++ b/python/src/_cdec.pyx
@@ -37,7 +37,7 @@ def _make_config(config):
for name in value:
yield key, name
else:
- yield key, bytes(value)
+ yield key, str(value)
cdef class Decoder:
cdef decoder.Decoder* dec
@@ -85,7 +85,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 str(conf[0]['formalism'].as_str().c_str())
def read_weights(self, weights):
with open(weights) as fp:
diff --git a/python/src/grammar.pxi b/python/src/grammar.pxi
index a9a5ea14..05351290 100644
--- a/python/src/grammar.pxi
+++ b/python/src/grammar.pxi
@@ -8,7 +8,7 @@ def _phrase(phrase):
cdef class NT:
cdef public bytes cat
cdef public unsigned ref
- def __init__(self, char* cat, unsigned ref=0):
+ def __init__(self, bytes cat, unsigned ref=0):
self.cat = cat
self.ref = ref
@@ -78,9 +78,9 @@ cdef class TRule:
w = f_[0][i]
if w < 0:
idx += 1
- f.append(NT(TDConvert(-w), idx))
+ f.append(NT(TDConvert(-w).c_str(), idx))
else:
- f.append(unicode(TDConvert(w), encoding='utf8'))
+ f.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
return f
def __set__(self, f):
@@ -107,7 +107,7 @@ cdef class TRule:
idx += 1
e.append(NTRef(1-w))
else:
- e.append(unicode(TDConvert(w), encoding='utf8'))
+ e.append(unicode(TDConvert(w).c_str(), encoding='utf8'))
return e
def __set__(self, e):
@@ -154,7 +154,7 @@ cdef class TRule:
property lhs:
def __get__(self):
- return NT(TDConvert(-self.rule.get().lhs_))
+ return NT(TDConvert(-self.rule.get().lhs_).c_str())
def __set__(self, lhs):
if not isinstance(lhs, NT):
@@ -196,7 +196,7 @@ cdef class Grammar:
property name:
def __get__(self):
- self.grammar.get().GetGrammarName().c_str()
+ str(self.grammar.get().GetGrammarName().c_str())
def __set__(self, name):
self.grammar.get().SetGrammarName(string(<char *>name))
diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi
index f0312a12..1edff3cb 100644
--- a/python/src/hypergraph.pxi
+++ b/python/src/hypergraph.pxi
@@ -111,7 +111,7 @@ cdef class Hypergraph:
del preserve_mask
def lattice(self): # TODO direct hg -> lattice conversion in cdec
- cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str()
+ cdef bytes plf = hypergraph.AsPLF(self.hg[0], True).c_str()
return Lattice(eval(plf))
def reweight(self, weights):
@@ -231,7 +231,7 @@ cdef class HypergraphNode:
property cat:
def __get__(self):
if self.node.cat_:
- return TDConvert(-self.node.cat_)
+ return str(TDConvert(-self.node.cat_).c_str())
def __richcmp__(HypergraphNode x, HypergraphNode y, int op):
if op == 2: # ==
diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi
index 14864549..385a40be 100644
--- a/python/src/lattice.pxi
+++ b/python/src/lattice.pxi
@@ -28,7 +28,7 @@ cdef class Lattice:
cdef unsigned i
for i in range(arc_vector.size()):
arc = &arc_vector[i]
- label = unicode(TDConvert(arc.label), 'utf8')
+ label = unicode(TDConvert(arc.label).c_str(), 'utf8')
arcs.append((label, arc.cost, arc.dist2next))
return tuple(arcs)
@@ -47,7 +47,7 @@ cdef class Lattice:
return self.lattice.size()
def __str__(self):
- return hypergraph.AsPLF(self.lattice[0], True).c_str()
+ return str(hypergraph.AsPLF(self.lattice[0], True).c_str())
def __iter__(self):
cdef unsigned i
diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi
index cd1c3c81..f1b6b5d1 100644
--- a/python/src/mteval.pxi
+++ b/python/src/mteval.pxi
@@ -36,7 +36,7 @@ cdef class SufficientStats:
property detail:
def __get__(self):
- return self.metric.DetailedScore(self.stats[0]).c_str()
+ return str(self.metric.DetailedScore(self.stats[0]).c_str())
def __len__(self):
return self.stats.size()
@@ -131,7 +131,6 @@ cdef class Scorer:
refs = [refs]
cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]()
cdef vector[WordID]* refv
- cdef bytes ref_str
for ref in refs:
refv = new vector[WordID]()
ConvertSentence(string(as_str(ref.strip())), refv)
@@ -146,7 +145,7 @@ cdef class Scorer:
return evaluator
def __str__(self):
- return self.name.c_str()
+ return str(self.name.c_str())
cdef float _compute_score(void* metric_, mteval.SufficientStats* stats):
cdef Metric metric = <Metric> metric_
@@ -164,8 +163,8 @@ cdef void _compute_sufficient_stats(void* metric_,
cdef list refs_ = []
cdef unsigned i
for i in range(refs.size()):
- refs_.append(refs[0][i].c_str())
- cdef list ss = metric.evaluate(hyp.c_str(), refs_)
+ refs_.append(str(refs[0][i].c_str()))
+ cdef list ss = metric.evaluate(str(hyp.c_str()), refs_)
out.fields.resize(len(ss))
for i in range(len(ss)):
out.fields[i] = ss[i]
diff --git a/python/src/utils.pxd b/python/src/utils.pxd
index a1a4799b..687d3ac0 100644
--- a/python/src/utils.pxd
+++ b/python/src/utils.pxd
@@ -63,7 +63,7 @@ cdef extern from "utils/tdict.h" namespace "TD":
string GetString(vector[WordID]& st)
unsigned NumWords()
WordID TDConvert "TD::Convert" (char*)
- char* TDConvert "TD::Convert" (WordID)
+ string& TDConvert "TD::Convert" (WordID)
void ConvertSentence(string& sent, vector[WordID]* ids)
cdef extern from "utils/verbose.h":
diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi
index 989a6a7c..87780556 100644
--- a/python/src/vectors.pxi
+++ b/python/src/vectors.pxi
@@ -31,7 +31,7 @@ cdef class DenseVector:
def __iter__(self):
cdef unsigned fid
for fid in range(1, self.vector.size()):
- yield FDConvert(fid).c_str(), self.vector[0][fid]
+ yield str(FDConvert(fid).c_str()), self.vector[0][fid]
def dot(self, SparseVector other):
return other.dot(self)
@@ -69,7 +69,7 @@ cdef class SparseVector:
cdef unsigned i
try:
for i in range(self.vector.size()):
- yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second)
+ yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second)
pinc(it[0]) # ++it
finally:
del it