summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-06-13 14:42:07 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-06-13 14:42:07 +0200
commite6d3c25191873ca0cf99db8e89702ed91d65277c (patch)
treeb0697ece6f5e4a8229915758c68750793a23f776
parent62c805c90c5347b844f92574e240db5c65578e12 (diff)
parent3acdf1e4b37637d6df86a7b54fb0f1b0464c172b (diff)
Merge remote-tracking branch 'upstream/master'
-rw-r--r--.gitignore5
-rw-r--r--decoder/decoder.cc19
-rw-r--r--decoder/ff_klm.cc7
-rw-r--r--decoder/hg.cc5
-rw-r--r--python/cdec/__init__.py1
-rw-r--r--python/cdec/scfg/__init__.py1
-rw-r--r--python/cdec/scfg/extractor.py112
-rw-r--r--python/cdec/scfg/features.py62
-rw-r--r--python/setup.py20
-rw-r--r--python/src/_cdec.cpp6743
-rw-r--r--python/src/_cdec.pyx180
-rw-r--r--python/src/decoder.pxd37
-rw-r--r--python/src/hypergraph.pxd41
-rw-r--r--python/src/kbest.pxd16
-rw-r--r--python/src/lattice.pxd16
-rw-r--r--python/src/observer.h22
-rw-r--r--python/src/utils.pxd53
-rw-r--r--python/test.py49
18 files changed, 7374 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index 796ee25c..27c6a739 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,4 @@
-cdec/
-creg/bin/
-creg/creg
-creg/json_feature_map_lexer.cc
+./cdec/
decoder/bin/
gi/pf/align-tl
gi/pf/bayes_lattice_score
diff --git a/decoder/decoder.cc b/decoder/decoder.cc
index 487c7635..cbb97a0d 100644
--- a/decoder/decoder.cc
+++ b/decoder/decoder.cc
@@ -122,13 +122,16 @@ inline bool store_conf(po::variables_map const& conf,std::string const& name,V *
inline boost::shared_ptr<FeatureFunction> make_ff(string const& ffp,bool verbose_feature_functions,char const* pre="") {
string ff, param;
SplitCommandAndParam(ffp, &ff, &param);
- cerr << pre << "feature: " << ff;
- if (param.size() > 0) cerr << " (with config parameters '" << param << "')\n";
- else cerr << " (no config parameters)\n";
+ if (verbose_feature_functions && !SILENT)
+ cerr << pre << "feature: " << ff;
+ if (!SILENT) {
+ if (param.size() > 0) cerr << " (with config parameters '" << param << "')\n";
+ else cerr << " (no config parameters)\n";
+ }
boost::shared_ptr<FeatureFunction> pf = ff_registry.Create(ff, param);
if (!pf) exit(1);
int nbyte=pf->NumBytesContext();
- if (verbose_feature_functions)
+ if (verbose_feature_functions && !SILENT)
cerr<<"State is "<<nbyte<<" bytes for "<<pre<<"feature "<<ffp<<endl;
return pf;
}
@@ -142,7 +145,7 @@ inline boost::shared_ptr<FsaFeatureFunction> make_fsa_ff(string const& ffp,bool
else cerr << " (no config parameters)\n";
boost::shared_ptr<FsaFeatureFunction> pf = fsa_ff_registry.Create(ff, param);
if (!pf) exit(1);
- if (verbose_feature_functions)
+ if (verbose_feature_functions && !SILENT)
cerr<<"State is "<<pf->state_bytes()<<" bytes for "<<pre<<"feature "<<ffp<<endl;
return pf;
}
@@ -211,8 +214,10 @@ struct DecoderImpl {
}
forest.PruneInsideOutside(beam_prune,density_prune,pm,false,1);
if (!forestname.empty()) forestname=" "+forestname;
- forest_stats(forest," Pruned "+forestname+" forest",false,false);
- cerr << " Pruned "<<forestname<<" forest portion of edges kept: "<<forest.edges_.size()/presize<<endl;
+ if (!SILENT) {
+ forest_stats(forest," Pruned "+forestname+" forest",false,false);
+ cerr << " Pruned "<<forestname<<" forest portion of edges kept: "<<forest.edges_.size()/presize<<endl;
+ }
}
}
diff --git a/decoder/ff_klm.cc b/decoder/ff_klm.cc
index 7a84add7..09ef282c 100644
--- a/decoder/ff_klm.cc
+++ b/decoder/ff_klm.cc
@@ -11,6 +11,7 @@
#include "tdict.h"
#include "lm/model.hh"
#include "lm/enumerate_vocab.hh"
+#include "utils/verbose.h"
#include "lm/left.hh"
@@ -232,7 +233,8 @@ class KLanguageModelImpl {
ngram_ = new Model(filename.c_str(), conf);
}
order_ = ngram_->Order();
- cerr << "Loaded " << order_ << "-gram KLM from " << filename << " (MapSize=" << cdec2klm_map_.size() << ")\n";
+ if (!SILENT)
+ cerr << "Loaded " << order_ << "-gram KLM from " << filename << " (MapSize=" << cdec2klm_map_.size() << ")\n";
// special handling of beginning / ending sentence markers
kSOS_ = MapWord(kCDEC_SOS);
@@ -252,7 +254,8 @@ class KLanguageModelImpl {
string line;
vector<WordID> dummy;
int lc = 0;
- cerr << " Loading word classes from " << file << " ...\n";
+ if (!SILENT)
+ cerr << " Loading word classes from " << file << " ...\n";
AddWordToClassMapping_(TD::Convert("<s>"), TD::Convert("<s>"));
AddWordToClassMapping_(TD::Convert("</s>"), TD::Convert("</s>"));
while(in) {
diff --git a/decoder/hg.cc b/decoder/hg.cc
index 0dcbe91f..dd272221 100644
--- a/decoder/hg.cc
+++ b/decoder/hg.cc
@@ -13,6 +13,7 @@
#include "viterbi.h"
#include "inside_outside.h"
#include "tdict.h"
+#include "verbose.h"
using namespace std;
@@ -330,9 +331,9 @@ bool Hypergraph::PruneInsideOutside(double alpha,double density,const EdgeMask*
const int plen = ViterbiPathLength(*this);
vector<WordID> bp;
rnum = min(rnum, static_cast<unsigned>(density * plen));
- cerr << "Density pruning: keep "<<rnum<<" of "<<edges_.size()<<" edges (viterbi = "<<plen<<" edges)"<<endl;
+ if (!SILENT) cerr << "Density pruning: keep "<<rnum<<" of "<<edges_.size()<<" edges (viterbi = "<<plen<<" edges)"<<endl;
if (rnum == edges_.size()) {
- cerr << "No pruning required: denisty already sufficient\n";
+ if (!SILENT) cerr << "No pruning required: denisty already sufficient\n";
if (!use_beam)
return false;
use_density=false;
diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py
new file mode 100644
index 00000000..c821f860
--- /dev/null
+++ b/python/cdec/__init__.py
@@ -0,0 +1 @@
+from _cdec import Decoder, Hypergraph, Lattice
diff --git a/python/cdec/scfg/__init__.py b/python/cdec/scfg/__init__.py
new file mode 100644
index 00000000..6eb2f88f
--- /dev/null
+++ b/python/cdec/scfg/__init__.py
@@ -0,0 +1 @@
+from extractor import GrammarExtractor
diff --git a/python/cdec/scfg/extractor.py b/python/cdec/scfg/extractor.py
new file mode 100644
index 00000000..9f1e1137
--- /dev/null
+++ b/python/cdec/scfg/extractor.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+import StringIO
+
+import clex
+import rulefactory
+import calignment
+import csuf
+import cdat
+import sym
+import log
+
+log.level = -1
+
+from features import EgivenFCoherent, SampleCountF, CountEF,\
+ MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE
+from features import contextless
+
+class Output(StringIO.StringIO):
+ def close(self):
+ pass
+
+ def __str__(self):
+ return self.getvalue()
+
+from itertools import chain
+
+def get_cn(sentence):
+ sentence = chain(('<s>',), sentence.split(), ('</s>',))
+ sentence = (sym.fromstring(word, terminal=True) for word in sentence)
+ return tuple(((word, None, 1), ) for word in sentence)
+
+class PhonyGrammar:
+ def add(self, thing):
+ pass
+
+class GrammarExtractor:
+ def __init__(self, config):
+ alignment = calignment.Alignment(config['a_file'], from_binary=True)
+ self.factory = rulefactory.HieroCachingRuleFactory(
+ # compiled alignment object (REQUIRED)
+ alignment=alignment,
+ # name of generic nonterminal used by Hiero
+ category="[X]",
+ # do not change for extraction
+ grammar=PhonyGrammar(), # TODO: set to None?
+ # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1
+ max_chunks=None,
+ # maximum span of a grammar rule in TEST DATA
+ max_initial_size=15,
+ # maximum number of symbols (both T and NT) allowed in a rule
+ max_length=config['max_len'],
+ # maximum number of nonterminals allowed in a rule (set >2 at your own risk)
+ max_nonterminals=config['max_nt'],
+ # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1
+ max_target_chunks=None,
+ # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size
+ max_target_length=None,
+ # minimum span of a nonterminal in the RHS of a rule in TEST DATA
+ min_gap_size=1,
+ # filename of file containing precomputed collocations
+ precompute_file=config['precompute_file'],
+ # maximum frequency rank of patterns used to compute triples (don't set higher than 20).
+ precompute_secondary_rank=config['rank2'],
+ # maximum frequency rank of patterns used to compute collocations (no need to set higher than maybe 200-300)
+ precompute_rank=config['rank1'],
+ # require extracted rules to have at least one aligned word
+ require_aligned_terminal=True,
+ # require each contiguous chunk of extracted rules to have at least one aligned word
+ require_aligned_chunks=False,
+ # generate a complete grammar for each input sentence
+ per_sentence_grammar=True,
+ # maximum span of a grammar rule extracted from TRAINING DATA
+ train_max_initial_size=config['max_size'],
+ # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA
+ train_min_gap_size=config['min_gap'],
+ # True if phrases should be tight, False otherwise (False seems to give better results but is slower)
+ tight_phrases=True,
+ )
+ self.fsarray = csuf.SuffixArray(config['f_sa_file'], from_binary=True)
+ self.edarray = cdat.DataArray(config['e_file'], from_binary=True)
+
+ self.factory.registerContext(self)
+
+ # lower=faster, higher=better; improvements level off above 200-300 range, -1 = don't sample, use all data (VERY SLOW!)
+ self.sampler = rulefactory.Sampler(300)
+ self.sampler.registerContext(self)
+
+ # lexical weighting tables
+ tt = clex.CLex(config['lex_file'], from_binary=True)
+
+ self.models = (EgivenFCoherent, SampleCountF, CountEF,
+ MaxLexFgivenE(tt), MaxLexEgivenF(tt), IsSingletonF, IsSingletonFE)
+ self.models = tuple(contextless(feature) for feature in self.models)
+
+ def grammar(self, sentence):
+ out = Output()
+ cn = get_cn(sentence)
+ self.factory.input_file(cn, out)
+ return str(out)
+
+def main(config):
+ sys.path.append(os.path.dirname(config))
+ module = __import__(os.path.basename(config).replace('.py', ''))
+ extractor = GrammarExtractor(module.__dict__)
+ print extractor.grammar(next(sys.stdin))
+
+if __name__ == '__main__':
+ import sys, os
+ if len(sys.argv) != 2 or not sys.argv[1].endswith('.py'):
+ sys.stderr.write('Usage: %s config.py\n' % sys.argv[0])
+ sys.exit(1)
+ main(*sys.argv[1:])
diff --git a/python/cdec/scfg/features.py b/python/cdec/scfg/features.py
new file mode 100644
index 00000000..6419cdd8
--- /dev/null
+++ b/python/cdec/scfg/features.py
@@ -0,0 +1,62 @@
+from __future__ import division
+import math
+import sym
+
+def contextless(feature):
+ feature.compute_contextless_score = feature
+ return feature
+
+MAXSCORE = 99
+
+def EgivenF(fphrase, ephrase, paircount, fcount, fsample_count): # p(e|f)
+ return -math.log10(paircount/fcount)
+
+def CountEF(fphrase, ephrase, paircount, fcount, fsample_count):
+ return math.log10(1 + paircount)
+
+def SampleCountF(fphrase, ephrase, paircount, fcount, fsample_count):
+ return math.log10(1 + fsample_count)
+
+def EgivenFCoherent(fphrase, ephrase, paircount, fcount, fsample_count):
+ prob = paircount/fsample_count
+ return -math.log10(prob) if prob > 0 else MAXSCORE
+
+def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count):
+ return -math.log10(fcount/fsample_count)
+
+def MaxLexEgivenF(ttable):
+ def feature(fphrase, ephrase, paircount, fcount, fsample_count):
+ fwords = [sym.tostring(w) for w in fphrase if not sym.isvar(w)] + ['NULL']
+ ewords = (sym.tostring(w) for w in ephrase if not sym.isvar(w))
+ def score():
+ for e in ewords:
+ maxScore = max(ttable.get_score(f, e, 0) for f in fwords)
+ yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE
+ return sum(score())
+ return feature
+
+def MaxLexFgivenE(ttable):
+ def feature(fphrase, ephrase, paircount, fcount, fsample_count):
+ fwords = (sym.tostring(w) for w in fphrase if not sym.isvar(w))
+ ewords = [sym.tostring(w) for w in ephrase if not sym.isvar(w)] + ['NULL']
+ def score():
+ for f in fwords:
+ maxScore = max(ttable.get_score(f, e, 1) for e in ewords)
+ yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE
+ return sum(score())
+ return feature
+
+def IsSingletonF(fphrase, ephrase, paircount, fcount, fsample_count):
+ return (fcount == 1)
+
+def IsSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count):
+ return (paircount == 1)
+
+def IsNotSingletonF(fphrase, ephrase, paircount, fcount, fsample_count):
+ return (fcount > 1)
+
+def IsNotSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count):
+ return (paircount > 1)
+
+def IsFEGreaterThanZero(fphrase, ephrase, paircount, fcount, fsample_count):
+ return (paircount > 0.01)
diff --git a/python/setup.py b/python/setup.py
new file mode 100644
index 00000000..756de088
--- /dev/null
+++ b/python/setup.py
@@ -0,0 +1,20 @@
+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Distutils import build_ext
+
+ext_modules = [
+ Extension(name='_cdec',
+ sources=['src/_cdec.pyx'],
+ language='C++',
+ include_dirs=['..', 'src/', '../decoder', '../utils'],
+ library_dirs=['../decoder', '../utils', '../mteval', '../klm/lm', '../klm/util'],
+ libraries=['boost_program_options-mt', 'z',
+ 'cdec', 'utils', 'mteval', 'klm', 'klm_util'])
+]
+
+setup(
+ name='cdec',
+ cmdclass={'build_ext': build_ext},
+ ext_modules=ext_modules,
+ packages=['cdec', 'cdec.scfg']
+)
diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp
new file mode 100644
index 00000000..e1b0f20e
--- /dev/null
+++ b/python/src/_cdec.cpp
@@ -0,0 +1,6743 @@
+/* Generated by Cython 0.15.1 on Wed Jun 6 01:04:37 2012 */
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#ifndef Py_PYTHON_H
+ #error Python headers needed to compile C extensions, please install development version of Python.
+#else
+
+#include <stddef.h> /* For offsetof */
+#ifndef offsetof
+#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
+#endif
+
+#if !defined(WIN32) && !defined(MS_WINDOWS)
+ #ifndef __stdcall
+ #define __stdcall
+ #endif
+ #ifndef __cdecl
+ #define __cdecl
+ #endif
+ #ifndef __fastcall
+ #define __fastcall
+ #endif
+#endif
+
+#ifndef DL_IMPORT
+ #define DL_IMPORT(t) t
+#endif
+#ifndef DL_EXPORT
+ #define DL_EXPORT(t) t
+#endif
+
+#ifndef PY_LONG_LONG
+ #define PY_LONG_LONG LONG_LONG
+#endif
+
+#if PY_VERSION_HEX < 0x02040000
+ #define METH_COEXIST 0
+ #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
+ #define PyDict_Contains(d,o) PySequence_Contains(d,o)
+#endif
+
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+ #define PY_SSIZE_T_MAX INT_MAX
+ #define PY_SSIZE_T_MIN INT_MIN
+ #define PY_FORMAT_SIZE_T ""
+ #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
+ #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
+ #define PyNumber_Index(o) PyNumber_Int(o)
+ #define PyIndex_Check(o) PyNumber_Check(o)
+ #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
+#endif
+
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
+ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
+ #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
+ #define PyVarObject_HEAD_INIT(type, size) \
+ PyObject_HEAD_INIT(type) size,
+ #define PyType_Modified(t)
+
+ typedef struct {
+ void *buf;
+ PyObject *obj;
+ Py_ssize_t len;
+ Py_ssize_t itemsize;
+ int readonly;
+ int ndim;
+ char *format;
+ Py_ssize_t *shape;
+ Py_ssize_t *strides;
+ Py_ssize_t *suboffsets;
+ void *internal;
+ } Py_buffer;
+
+ #define PyBUF_SIMPLE 0
+ #define PyBUF_WRITABLE 0x0001
+ #define PyBUF_FORMAT 0x0004
+ #define PyBUF_ND 0x0008
+ #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+ #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+ #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+ #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+ #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
+
+#endif
+
+#if PY_MAJOR_VERSION < 3
+ #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
+#else
+ #define __Pyx_BUILTIN_MODULE_NAME "builtins"
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define Py_TPFLAGS_CHECKTYPES 0
+ #define Py_TPFLAGS_HAVE_INDEX 0
+#endif
+
+#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+ #define Py_TPFLAGS_HAVE_NEWBUFFER 0
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyBaseString_Type PyUnicode_Type
+ #define PyStringObject PyUnicodeObject
+ #define PyString_Type PyUnicode_Type
+ #define PyString_Check PyUnicode_Check
+ #define PyString_CheckExact PyUnicode_CheckExact
+#endif
+
+#if PY_VERSION_HEX < 0x02060000
+ #define PyBytesObject PyStringObject
+ #define PyBytes_Type PyString_Type
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_CheckExact PyString_CheckExact
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+ #define PyBytes_FromFormat PyString_FromFormat
+ #define PyBytes_DecodeEscape PyString_DecodeEscape
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_AsStringAndSize PyString_AsStringAndSize
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_AS_STRING PyString_AS_STRING
+ #define PyBytes_GET_SIZE PyString_GET_SIZE
+ #define PyBytes_Repr PyString_Repr
+ #define PyBytes_Concat PyString_Concat
+ #define PyBytes_ConcatAndDel PyString_ConcatAndDel
+#endif
+
+#if PY_VERSION_HEX < 0x02060000
+ #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type)
+ #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type)
+#endif
+#ifndef PySet_CheckExact
+ #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
+#endif
+
+#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyIntObject PyLongObject
+ #define PyInt_Type PyLong_Type
+ #define PyInt_Check(op) PyLong_Check(op)
+ #define PyInt_CheckExact(op) PyLong_CheckExact(op)
+ #define PyInt_FromString PyLong_FromString
+ #define PyInt_FromUnicode PyLong_FromUnicode
+ #define PyInt_FromLong PyLong_FromLong
+ #define PyInt_FromSize_t PyLong_FromSize_t
+ #define PyInt_FromSsize_t PyLong_FromSsize_t
+ #define PyInt_AsLong PyLong_AsLong
+ #define PyInt_AS_LONG PyLong_AS_LONG
+ #define PyInt_AsSsize_t PyLong_AsSsize_t
+ #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
+ #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyBoolObject PyLongObject
+#endif
+
+#if PY_VERSION_HEX < 0x03020000
+ typedef long Py_hash_t;
+ #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+ #define __Pyx_PyInt_AsHash_t PyInt_AsLong
+#else
+ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+ #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
+#endif
+
+
+#if PY_MAJOR_VERSION >= 3
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
+#else
+ #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
+ #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
+#endif
+
+#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
+ #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
+ #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
+#else
+ #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
+ #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
+ #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
+ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
+ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
+ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
+#endif
+
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n)))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n)))
+#else
+ #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n))
+ #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
+ #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n))
+#endif
+
+#if PY_VERSION_HEX < 0x02050000
+ #define __Pyx_NAMESTR(n) ((char *)(n))
+ #define __Pyx_DOCSTR(n) ((char *)(n))
+#else
+ #define __Pyx_NAMESTR(n) (n)
+ #define __Pyx_DOCSTR(n) (n)
+#endif
+
+#ifndef __PYX_EXTERN_C
+ #ifdef __cplusplus
+ #define __PYX_EXTERN_C extern "C"
+ #else
+ #define __PYX_EXTERN_C extern
+ #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+#define __PYX_HAVE___cdec
+#define __PYX_HAVE_API___cdec
+#include <string>
+#include <vector>
+#include <iostream>
+#include "utils/weights.h"
+#include "utils/logval.h"
+#include "utils/prob.h"
+#include "utils/wordid.h"
+#include "utils/sparse_vector.h"
+#include "utils/tdict.cc"
+#include "utils/verbose.h"
+#include "utils/fdict.h"
+#include "utils/filelib.h"
+#include "utils/sampler.h"
+#include "decoder/lattice.h"
+#include "decoder/hg.h"
+#include "decoder/viterbi.h"
+#include "decoder/hg_io.h"
+#include "decoder/hg_intersect.h"
+#include "decoder/hg_sampler.h"
+#include "decoder/ff_register.h"
+#include "decoder/decoder.h"
+#include "observer.h"
+#include "decoder/kbest.h"
+#ifdef _OPENMP
+#include <omp.h>
+#endif /* _OPENMP */
+
+#ifdef PYREX_WITHOUT_ASSERTIONS
+#define CYTHON_WITHOUT_ASSERTIONS
+#endif
+
+
+/* inline attribute */
+#ifndef CYTHON_INLINE
+ #if defined(__GNUC__)
+ #define CYTHON_INLINE __inline__
+ #elif defined(_MSC_VER)
+ #define CYTHON_INLINE __inline
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_INLINE inline
+ #else
+ #define CYTHON_INLINE
+ #endif
+#endif
+
+/* unused attribute */
+#ifndef CYTHON_UNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+# elif defined(__ICC) || defined(__INTEL_COMPILER)
+# define CYTHON_UNUSED __attribute__ ((__unused__))
+# else
+# define CYTHON_UNUSED
+# endif
+#endif
+
+typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+
+
+/* Type Conversion Predeclarations */
+
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s))
+
+#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
+
+#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
+
+
+#ifdef __GNUC__
+ /* Test for GCC > 2.95 */
+ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
+ #define likely(x) __builtin_expect(!!(x), 1)
+ #define unlikely(x) __builtin_expect(!!(x), 0)
+ #else /* __GNUC__ > 2 ... */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+ #endif /* __GNUC__ > 2 ... */
+#else /* __GNUC__ */
+ #define likely(x) (x)
+ #define unlikely(x) (x)
+#endif /* __GNUC__ */
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static PyObject *__pyx_empty_tuple;
+static PyObject *__pyx_empty_bytes;
+static int __pyx_lineno;
+static int __pyx_clineno = 0;
+static const char * __pyx_cfilenm= __FILE__;
+static const char *__pyx_filename;
+
+
+static const char *__pyx_f[] = {
+ "_cdec.pyx",
+};
+
+static PyObject *__Pyx_Generator_Next(PyObject *self);
+static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
+static PyObject *__Pyx_Generator_Close(PyObject *self);
+static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args, CYTHON_UNUSED PyObject *kwds);
+
+typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *);
+
+/*--- Type declarations ---*/
+struct __pyx_Generator_object;
+struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree;
+struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample;
+struct __pyx_obj_5_cdec_Weights;
+struct __pyx_obj_5_cdec_Decoder;
+struct __pyx_obj_5_cdec_Hypergraph;
+struct __pyx_obj_5_cdec_Lattice;
+struct __pyx_obj_5_cdec___pyx_scope_struct____iter__;
+struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest;
+
+/* "_cdec.pyx":33
+ * self.weights[0][fid] = value
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()):
+ */
+struct __pyx_Generator_object {
+ PyObject_HEAD
+ __pyx_generator_body_t body;
+ int is_running;
+ int resume_label;
+ PyObject *exc_type;
+ PyObject *exc_value;
+ PyObject *exc_traceback;
+};
+
+
+/* "_cdec.pyx":120
+ * del derivations
+ *
+ * def kbest_tree(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree {
+ struct __pyx_Generator_object __pyx_base;
+ KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal>::Derivation *__pyx_v_derivation;
+ KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal> *__pyx_v_derivations;
+ unsigned int __pyx_v_k;
+ PyObject *__pyx_v_self;
+ PyObject *__pyx_v_sentence;
+ PyObject *__pyx_v_size;
+ unsigned int __pyx_t_0;
+ long __pyx_t_1;
+};
+
+
+/* "_cdec.pyx":137
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ * def sample(self, unsigned n): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample {
+ struct __pyx_Generator_object __pyx_base;
+ std::vector<HypergraphSampler::Hypothesis> *__pyx_v_hypos;
+ unsigned int __pyx_v_k;
+ unsigned int __pyx_v_n;
+ PyObject *__pyx_v_self;
+ PyObject *__pyx_v_sentence;
+ size_t __pyx_t_0;
+ unsigned int __pyx_t_1;
+};
+
+
+/* "_cdec.pyx":15
+ * pass
+ *
+ * cdef class Weights: # <<<<<<<<<<<<<<
+ * cdef vector[weight_t]* weights
+ *
+ */
+struct __pyx_obj_5_cdec_Weights {
+ PyObject_HEAD
+ std::vector<weight_t> *weights;
+};
+
+
+/* "_cdec.pyx":38
+ * yield FDConvert(fid).c_str(), self.weights[0][fid]
+ *
+ * cdef class Decoder: # <<<<<<<<<<<<<<
+ * cdef decoder.Decoder* dec
+ * cdef public Weights weights
+ */
+struct __pyx_obj_5_cdec_Decoder {
+ PyObject_HEAD
+ Decoder *dec;
+ struct __pyx_obj_5_cdec_Weights *weights;
+};
+
+
+/* "_cdec.pyx":86
+ * return hg
+ *
+ * cdef class Hypergraph: # <<<<<<<<<<<<<<
+ * cdef hypergraph.Hypergraph* hg
+ * cdef MT19937* rng
+ */
+struct __pyx_obj_5_cdec_Hypergraph {
+ PyObject_HEAD
+ Hypergraph *hg;
+ MT19937 *rng;
+};
+
+
+/* "_cdec.pyx":154
+ * # TODO: inside-outside pruning
+ *
+ * cdef class Lattice: # <<<<<<<<<<<<<<
+ * cdef lattice.Lattice* lattice
+ *
+ */
+struct __pyx_obj_5_cdec_Lattice {
+ PyObject_HEAD
+ Lattice *lattice;
+};
+
+
+/* "_cdec.pyx":33
+ * self.weights[0][fid] = value
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()):
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ {
+ struct __pyx_Generator_object __pyx_base;
+ unsigned int __pyx_v_fid;
+ PyObject *__pyx_v_self;
+ size_t __pyx_t_0;
+ unsigned int __pyx_t_1;
+};
+
+
+/* "_cdec.pyx":107
+ * return tree.decode('utf8')
+ *
+ * def kbest(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest {
+ struct __pyx_Generator_object __pyx_base;
+ KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal>::Derivation *__pyx_v_derivation;
+ KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal> *__pyx_v_derivations;
+ unsigned int __pyx_v_k;
+ PyObject *__pyx_v_self;
+ PyObject *__pyx_v_size;
+ PyObject *__pyx_v_tree;
+ unsigned int __pyx_t_0;
+ long __pyx_t_1;
+};
+
+
+#ifndef CYTHON_REFNANNY
+ #define CYTHON_REFNANNY 0
+#endif
+
+#if CYTHON_REFNANNY
+ typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*SetupContext)(const char*, int, const char*);
+ void (*FinishContext)(void**);
+ } __Pyx_RefNannyAPIStruct;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
+ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+ #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
+ #define __Pyx_RefNannySetupContext(name) __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
+ #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
+ #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
+ #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
+ #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
+ #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
+ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
+#else
+ #define __Pyx_RefNannyDeclarations
+ #define __Pyx_RefNannySetupContext(name)
+ #define __Pyx_RefNannyFinishContext()
+ #define __Pyx_INCREF(r) Py_INCREF(r)
+ #define __Pyx_DECREF(r) Py_DECREF(r)
+ #define __Pyx_GOTREF(r)
+ #define __Pyx_GIVEREF(r)
+ #define __Pyx_XINCREF(r) Py_XINCREF(r)
+ #define __Pyx_XDECREF(r) Py_XDECREF(r)
+ #define __Pyx_XGOTREF(r)
+ #define __Pyx_XGIVEREF(r)
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static void __Pyx_RaiseDoubleKeywordsError(
+ const char* func_name, PyObject* kw_name); /*proto*/
+
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/
+
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+
+static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
+ const char *name, int exact); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
+
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
+
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
+
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
+
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
+
+#define __Pyx_PyObject_AsDouble(obj) \
+ ((likely(PyFloat_CheckExact(obj))) ? \
+ PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
+
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+
+static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+
+static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/
+
+static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
+ PyObject *modname); /*proto*/
+
+#include "descrobject.h"
+static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
+
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
+
+static int __Pyx_check_binary_version(void);
+
+static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno,
+ int __pyx_lineno, const char *__pyx_filename); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+/* Module declarations from 'libcpp.string' */
+
+/* Module declarations from 'libcpp.vector' */
+
+/* Module declarations from 'utils' */
+
+/* Module declarations from 'lattice' */
+
+/* Module declarations from 'hypergraph' */
+
+/* Module declarations from 'decoder' */
+
+/* Module declarations from 'kbest' */
+
+/* Module declarations from '_cdec' */
+static PyTypeObject *__pyx_ptype_5_cdec_Weights = 0;
+static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0;
+static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0;
+static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_Generator = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_sample = 0;
+#define __Pyx_MODULE_NAME "_cdec"
+int __pyx_module_is_main__cdec = 0;
+
+/* Implementation of '_cdec' */
+static PyObject *__pyx_builtin_Exception;
+static PyObject *__pyx_builtin_KeyError;
+static PyObject *__pyx_builtin_range;
+static PyObject *__pyx_builtin_open;
+static PyObject *__pyx_builtin_eval;
+static char __pyx_k_1[] = "#";
+static char __pyx_k_3[] = "=";
+static char __pyx_k__eval[] = "eval";
+static char __pyx_k__open[] = "open";
+static char __pyx_k__utf8[] = "utf8";
+static char __pyx_k___cdec[] = "_cdec";
+static char __pyx_k__range[] = "range";
+static char __pyx_k__split[] = "split";
+static char __pyx_k__strip[] = "strip";
+static char __pyx_k__config[] = "config";
+static char __pyx_k__decode[] = "decode";
+static char __pyx_k__encode[] = "encode";
+static char __pyx_k__decoder[] = "decoder";
+static char __pyx_k__grammar[] = "grammar";
+static char __pyx_k__KeyError[] = "KeyError";
+static char __pyx_k____exit__[] = "__exit__";
+static char __pyx_k____main__[] = "__main__";
+static char __pyx_k____test__[] = "__test__";
+static char __pyx_k__sentence[] = "sentence";
+static char __pyx_k__Exception[] = "Exception";
+static char __pyx_k____enter__[] = "__enter__";
+static char __pyx_k__plf_tuple[] = "plf_tuple";
+static char __pyx_k__fromconfig[] = "fromconfig";
+static char __pyx_k__startswith[] = "startswith";
+static char __pyx_k__ParseFailed[] = "ParseFailed";
+static PyObject *__pyx_kp_s_1;
+static PyObject *__pyx_kp_s_3;
+static PyObject *__pyx_n_s__Exception;
+static PyObject *__pyx_n_s__KeyError;
+static PyObject *__pyx_n_s__ParseFailed;
+static PyObject *__pyx_n_s____enter__;
+static PyObject *__pyx_n_s____exit__;
+static PyObject *__pyx_n_s____main__;
+static PyObject *__pyx_n_s____test__;
+static PyObject *__pyx_n_s___cdec;
+static PyObject *__pyx_n_s__config;
+static PyObject *__pyx_n_s__decode;
+static PyObject *__pyx_n_s__decoder;
+static PyObject *__pyx_n_s__encode;
+static PyObject *__pyx_n_s__eval;
+static PyObject *__pyx_n_s__fromconfig;
+static PyObject *__pyx_n_s__grammar;
+static PyObject *__pyx_n_s__open;
+static PyObject *__pyx_n_s__plf_tuple;
+static PyObject *__pyx_n_s__range;
+static PyObject *__pyx_n_s__sentence;
+static PyObject *__pyx_n_s__split;
+static PyObject *__pyx_n_s__startswith;
+static PyObject *__pyx_n_s__strip;
+static PyObject *__pyx_n_s__utf8;
+static PyObject *__pyx_k_tuple_2;
+static PyObject *__pyx_k_tuple_4;
+static PyObject *__pyx_k_tuple_5;
+static PyObject *__pyx_k_tuple_6;
+static PyObject *__pyx_k_tuple_7;
+static PyObject *__pyx_k_tuple_8;
+static PyObject *__pyx_k_tuple_9;
+static PyObject *__pyx_k_tuple_10;
+static PyObject *__pyx_k_tuple_11;
+static PyObject *__pyx_k_tuple_12;
+
+/* "_cdec.pyx":18
+ * cdef vector[weight_t]* weights
+ *
+ * def __cinit__(self, Decoder decoder): # <<<<<<<<<<<<<<
+ * self.weights = &decoder.dec.CurrentWeightVector()
+ *
+ */
+
+static int __pyx_pf_5_cdec_7Weights___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pf_5_cdec_7Weights___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ struct __pyx_obj_5_cdec_Decoder *__pyx_v_decoder = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__decoder,0};
+ __Pyx_RefNannySetupContext("__cinit__");
+ {
+ PyObject* values[1] = {0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 0:
+ values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__decoder);
+ if (likely(values[0])) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ }
+ __pyx_v_decoder = ((struct __pyx_obj_5_cdec_Decoder *)values[0]);
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Weights.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_decoder), __pyx_ptype_5_cdec_Decoder, 1, "decoder", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":19
+ *
+ * def __cinit__(self, Decoder decoder):
+ * self.weights = &decoder.dec.CurrentWeightVector() # <<<<<<<<<<<<<<
+ *
+ * def __getitem__(self, char* fname):
+ */
+ ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights = (&__pyx_v_decoder->dec->CurrentWeightVector());
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_AddTraceback("_cdec.Weights.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":21
+ * self.weights = &decoder.dec.CurrentWeightVector()
+ *
+ * def __getitem__(self, char* fname): # <<<<<<<<<<<<<<
+ * cdef unsigned fid = FDConvert(fname)
+ * if fid <= self.weights.size():
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) {
+ char *__pyx_v_fname;
+ unsigned int __pyx_v_fid;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__getitem__");
+ assert(__pyx_arg_fname); {
+ __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Weights.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+
+ /* "_cdec.pyx":22
+ *
+ * def __getitem__(self, char* fname):
+ * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<<
+ * if fid <= self.weights.size():
+ * return self.weights[0][fid]
+ */
+ __pyx_v_fid = FD::Convert(__pyx_v_fname);
+
+ /* "_cdec.pyx":23
+ * def __getitem__(self, char* fname):
+ * cdef unsigned fid = FDConvert(fname)
+ * if fid <= self.weights.size(): # <<<<<<<<<<<<<<
+ * return self.weights[0][fid]
+ * raise KeyError(fname)
+ */
+ __pyx_t_1 = (__pyx_v_fid <= ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights->size());
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":24
+ * cdef unsigned fid = FDConvert(fname)
+ * if fid <= self.weights.size():
+ * return self.weights[0][fid] # <<<<<<<<<<<<<<
+ * raise KeyError(fname)
+ *
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+ goto __pyx_L5;
+ }
+ __pyx_L5:;
+
+ /* "_cdec.pyx":25
+ * if fid <= self.weights.size():
+ * return self.weights[0][fid]
+ * raise KeyError(fname) # <<<<<<<<<<<<<<
+ *
+ * def __setitem__(self, char* fname, float value):
+ */
+ __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("_cdec.Weights.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":27
+ * raise KeyError(fname)
+ *
+ * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<<
+ * cdef unsigned fid = FDConvert(<char *>fname)
+ * if self.weights.size() <= fid:
+ */
+
+static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/
+static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) {
+ char *__pyx_v_fname;
+ float __pyx_v_value;
+ unsigned int __pyx_v_fid;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setitem__");
+ assert(__pyx_arg_fname); {
+ __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ assert(__pyx_arg_value); {
+ __pyx_v_value = __pyx_PyFloat_AsDouble(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Weights.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+
+ /* "_cdec.pyx":28
+ *
+ * def __setitem__(self, char* fname, float value):
+ * cdef unsigned fid = FDConvert(<char *>fname) # <<<<<<<<<<<<<<
+ * if self.weights.size() <= fid:
+ * self.weights.resize(fid + 1)
+ */
+ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname));
+
+ /* "_cdec.pyx":29
+ * def __setitem__(self, char* fname, float value):
+ * cdef unsigned fid = FDConvert(<char *>fname)
+ * if self.weights.size() <= fid: # <<<<<<<<<<<<<<
+ * self.weights.resize(fid + 1)
+ * self.weights[0][fid] = value
+ */
+ __pyx_t_1 = (((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights->size() <= __pyx_v_fid);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":30
+ * cdef unsigned fid = FDConvert(<char *>fname)
+ * if self.weights.size() <= fid:
+ * self.weights.resize(fid + 1) # <<<<<<<<<<<<<<
+ * self.weights[0][fid] = value
+ *
+ */
+ ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights->resize((__pyx_v_fid + 1));
+ goto __pyx_L5;
+ }
+ __pyx_L5:;
+
+ /* "_cdec.pyx":31
+ * if self.weights.size() <= fid:
+ * self.weights.resize(fid + 1)
+ * self.weights[0][fid] = value # <<<<<<<<<<<<<<
+ *
+ * def __iter__(self):
+ */
+ ((((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights[0])[__pyx_v_fid]) = __pyx_v_value;
+
+ __pyx_r = 0;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":33
+ * self.weights[0][fid] = value
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()):
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Weights_3__iter__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Weights_3__iter__(PyObject *__pyx_v_self) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__iter__");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct____iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct____iter__, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_7Weights_4generator;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ size_t __pyx_t_1;
+ unsigned int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L6_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":35
+ * def __iter__(self):
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()): # <<<<<<<<<<<<<<
+ * yield FDConvert(fid).c_str(), self.weights[0][fid]
+ *
+ */
+ __pyx_t_1 = ((struct __pyx_obj_5_cdec_Weights *)__pyx_cur_scope->__pyx_v_self)->weights->size();
+ for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
+ __pyx_cur_scope->__pyx_v_fid = __pyx_t_2;
+
+ /* "_cdec.pyx":36
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()):
+ * yield FDConvert(fid).c_str(), self.weights[0][fid] # <<<<<<<<<<<<<<
+ *
+ * cdef class Decoder:
+ */
+ __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ __pyx_t_4 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_cur_scope->__pyx_v_self)->weights[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __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[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__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, 1, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_4);
+ __pyx_t_3 = 0;
+ __pyx_t_4 = 0;
+ __pyx_r = ((PyObject *)__pyx_t_5);
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L6_resume_from_yield:;
+ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+
+/* "_cdec.pyx":42
+ * cdef public Weights weights
+ *
+ * def __cinit__(self, char* config): # <<<<<<<<<<<<<<
+ * decoder.register_feature_functions()
+ * cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs)
+ */
+
+static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ char *__pyx_v_config;
+ std::istringstream *__pyx_v_config_stream;
+ int __pyx_r;
+ __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;
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0};
+ __Pyx_RefNannySetupContext("__cinit__");
+ {
+ PyObject* values[1] = {0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 0:
+ values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config);
+ if (likely(values[0])) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ }
+ __pyx_v_config = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_config) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+
+ /* "_cdec.pyx":43
+ *
+ * def __cinit__(self, char* config):
+ * decoder.register_feature_functions() # <<<<<<<<<<<<<<
+ * cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs)
+ * #cdef ReadFile* config_file = new ReadFile(string(config))
+ */
+ register_feature_functions();
+
+ /* "_cdec.pyx":44
+ * def __cinit__(self, char* config):
+ * decoder.register_feature_functions()
+ * cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs) # <<<<<<<<<<<<<<
+ * #cdef ReadFile* config_file = new ReadFile(string(config))
+ * #cdef istream* config_stream = config_file.stream()
+ */
+ __pyx_v_config_stream = new std::istringstream(__pyx_v_config);
+
+ /* "_cdec.pyx":47
+ * #cdef ReadFile* config_file = new ReadFile(string(config))
+ * #cdef istream* config_stream = config_file.stream()
+ * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<<
+ * del config_stream
+ * #del config_file
+ */
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec = new Decoder(__pyx_v_config_stream);
+
+ /* "_cdec.pyx":48
+ * #cdef istream* config_stream = config_file.stream()
+ * self.dec = new decoder.Decoder(config_stream)
+ * del config_stream # <<<<<<<<<<<<<<
+ * #del config_file
+ * self.weights = Weights(self)
+ */
+ delete __pyx_v_config_stream;
+
+ /* "_cdec.pyx":50
+ * del config_stream
+ * #del config_file
+ * self.weights = Weights(self) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(__pyx_v_self);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
+ __Pyx_GIVEREF(__pyx_v_self);
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Weights)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_GOTREF(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights);
+ __Pyx_DECREF(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights));
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights = ((struct __pyx_obj_5_cdec_Weights *)__pyx_t_2);
+ __pyx_t_2 = 0;
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":52
+ * self.weights = Weights(self)
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * del self.dec
+ *
+ */
+
+static void __pyx_pf_5_cdec_7Decoder_1__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_5_cdec_7Decoder_1__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__");
+
+ /* "_cdec.pyx":53
+ *
+ * def __dealloc__(self):
+ * del self.dec # <<<<<<<<<<<<<<
+ *
+ * @classmethod
+ */
+ delete ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec;
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "_cdec.pyx":56
+ *
+ * @classmethod
+ * def fromconfig(cls, ini): # <<<<<<<<<<<<<<
+ * cdef dict config = {}
+ * with open(ini) as fp:
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyObject *__pyx_v_ini); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyObject *__pyx_v_ini) {
+ PyObject *__pyx_v_config = 0;
+ PyObject *__pyx_v_fp = NULL;
+ PyObject *__pyx_v_line = NULL;
+ PyObject *__pyx_v_param = NULL;
+ PyObject *__pyx_v_value = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ Py_ssize_t __pyx_t_7;
+ PyObject *(*__pyx_t_8)(PyObject *);
+ PyObject *__pyx_t_9 = NULL;
+ int __pyx_t_10;
+ int __pyx_t_11;
+ int __pyx_t_12;
+ PyObject *__pyx_t_13 = NULL;
+ PyObject *__pyx_t_14 = NULL;
+ PyObject *(*__pyx_t_15)(PyObject *);
+ PyObject *__pyx_t_16 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("fromconfig");
+
+ /* "_cdec.pyx":57
+ * @classmethod
+ * def fromconfig(cls, ini):
+ * cdef dict config = {} # <<<<<<<<<<<<<<
+ * with open(ini) as fp:
+ * for line in fp:
+ */
+ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __pyx_v_config = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":58
+ * def fromconfig(cls, ini):
+ * cdef dict config = {}
+ * with open(ini) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * line = line.strip()
+ */
+ /*with:*/ {
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(__pyx_v_ini);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_ini);
+ __Pyx_GIVEREF(__pyx_v_ini);
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ /*try:*/ {
+ {
+ __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+ __Pyx_XGOTREF(__pyx_t_4);
+ __Pyx_XGOTREF(__pyx_t_5);
+ __Pyx_XGOTREF(__pyx_t_6);
+ /*try:*/ {
+ __pyx_v_fp = __pyx_t_2;
+ __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":59
+ * cdef dict config = {}
+ * with open(ini) as fp:
+ * for line in fp: # <<<<<<<<<<<<<<
+ * line = line.strip()
+ * if not line or line.startswith('#'): continue
+ */
+ if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) {
+ __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
+ __pyx_t_8 = NULL;
+ } else {
+ __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext;
+ }
+ for (;;) {
+ if (PyList_CheckExact(__pyx_t_2)) {
+ if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
+ __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
+ } else if (PyTuple_CheckExact(__pyx_t_2)) {
+ if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+ __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
+ } else {
+ __pyx_t_1 = __pyx_t_8(__pyx_t_2);
+ if (unlikely(!__pyx_t_1)) {
+ if (PyErr_Occurred()) {
+ if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
+ else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ break;
+ }
+ __Pyx_GOTREF(__pyx_t_1);
+ }
+ __Pyx_XDECREF(__pyx_v_line);
+ __pyx_v_line = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":60
+ * with open(ini) as fp:
+ * for line in fp:
+ * line = line.strip() # <<<<<<<<<<<<<<
+ * if not line or line.startswith('#'): continue
+ * param, value = line.split('=')
+ */
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_v_line);
+ __pyx_v_line = __pyx_t_9;
+ __pyx_t_9 = 0;
+
+ /* "_cdec.pyx":61
+ * for line in fp:
+ * line = line.strip()
+ * if not line or line.startswith('#'): continue # <<<<<<<<<<<<<<
+ * param, value = line.split('=')
+ * config[param.strip()] = value.strip()
+ */
+ __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_11 = (!__pyx_t_10);
+ if (!__pyx_t_11) {
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_12 = __pyx_t_10;
+ } else {
+ __pyx_t_12 = __pyx_t_11;
+ }
+ if (__pyx_t_12) {
+ goto __pyx_L17_continue;
+ goto __pyx_L19;
+ }
+ __pyx_L19:;
+
+ /* "_cdec.pyx":62
+ * line = line.strip()
+ * if not line or line.startswith('#'): continue
+ * param, value = line.split('=') # <<<<<<<<<<<<<<
+ * config[param.strip()] = value.strip()
+ * return cls(**config)
+ */
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
+ PyObject* sequence = __pyx_t_9;
+ if (likely(PyTuple_CheckExact(sequence))) {
+ if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
+ if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
+ else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0);
+ __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1);
+ } else {
+ if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
+ if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
+ else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ __pyx_t_1 = PyList_GET_ITEM(sequence, 0);
+ __pyx_t_13 = PyList_GET_ITEM(sequence, 1);
+ }
+ __Pyx_INCREF(__pyx_t_1);
+ __Pyx_INCREF(__pyx_t_13);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ } else {
+ Py_ssize_t index = -1;
+ __pyx_t_14 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_14);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
+ index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_1)) goto __pyx_L20_unpacking_failed;
+ __Pyx_GOTREF(__pyx_t_1);
+ index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L20_unpacking_failed;
+ __Pyx_GOTREF(__pyx_t_13);
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+ goto __pyx_L21_unpacking_done;
+ __pyx_L20_unpacking_failed:;
+ __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
+ if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_L21_unpacking_done:;
+ }
+ __Pyx_XDECREF(__pyx_v_param);
+ __pyx_v_param = __pyx_t_1;
+ __pyx_t_1 = 0;
+ __Pyx_XDECREF(__pyx_v_value);
+ __pyx_v_value = __pyx_t_13;
+ __pyx_t_13 = 0;
+
+ /* "_cdec.pyx":63
+ * if not line or line.startswith('#'): continue
+ * param, value = line.split('=')
+ * config[param.strip()] = value.strip() # <<<<<<<<<<<<<<
+ * return cls(**config)
+ *
+ */
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_13 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_13);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_param, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ if (PyDict_SetItem(((PyObject *)__pyx_v_config), __pyx_t_1, __pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+ __pyx_L17_continue:;
+ }
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ }
+ __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+ goto __pyx_L16_try_end;
+ __pyx_L9_error:;
+ __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
+ __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
+ __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":58
+ * def fromconfig(cls, ini):
+ * cdef dict config = {}
+ * with open(ini) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * line = line.strip()
+ */
+ /*except:*/ {
+ __Pyx_AddTraceback("_cdec.Decoder.fromconfig", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_13, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(__pyx_t_13);
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_9));
+ __Pyx_INCREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_t_13);
+ PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_13);
+ __Pyx_GIVEREF(__pyx_t_13);
+ __Pyx_INCREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_16 = PyObject_Call(__pyx_t_3, __pyx_t_9, NULL);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(__pyx_t_16);
+ __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_16);
+ __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
+ if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __pyx_t_11 = (!__pyx_t_12);
+ if (__pyx_t_11) {
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_13);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __Pyx_ErrRestore(__pyx_t_2, __pyx_t_13, __pyx_t_1);
+ __pyx_t_2 = 0; __pyx_t_13 = 0; __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ goto __pyx_L24;
+ }
+ __pyx_L24:;
+ __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ goto __pyx_L10_exception_handled;
+ }
+ __pyx_L11_except_error:;
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_XGIVEREF(__pyx_t_6);
+ __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+ goto __pyx_L1_error;
+ __pyx_L10_exception_handled:;
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_XGIVEREF(__pyx_t_6);
+ __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+ __pyx_L16_try_end:;
+ }
+ }
+ /*finally:*/ {
+ if (__pyx_t_3) {
+ __pyx_t_6 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_5, NULL);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ goto __pyx_L25;
+ __pyx_L5_error:;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ goto __pyx_L1_error;
+ __pyx_L25:;
+ }
+
+ /* "_cdec.pyx":64
+ * param, value = line.split('=')
+ * config[param.strip()] = value.strip()
+ * return cls(**config) # <<<<<<<<<<<<<<
+ *
+ * def read_weights(self, cfg):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_v_cls, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_v_config)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __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_XDECREF(__pyx_t_9);
+ __Pyx_XDECREF(__pyx_t_13);
+ __Pyx_XDECREF(__pyx_t_14);
+ __Pyx_AddTraceback("_cdec.Decoder.fromconfig", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_config);
+ __Pyx_XDECREF(__pyx_v_fp);
+ __Pyx_XDECREF(__pyx_v_line);
+ __Pyx_XDECREF(__pyx_v_param);
+ __Pyx_XDECREF(__pyx_v_value);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":66
+ * return cls(**config)
+ *
+ * def read_weights(self, cfg): # <<<<<<<<<<<<<<
+ * with open(cfg) as fp:
+ * for line in fp:
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) {
+ PyObject *__pyx_v_fp = NULL;
+ PyObject *__pyx_v_line = NULL;
+ PyObject *__pyx_v_fname = NULL;
+ PyObject *__pyx_v_value = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ Py_ssize_t __pyx_t_7;
+ PyObject *(*__pyx_t_8)(PyObject *);
+ PyObject *__pyx_t_9 = NULL;
+ PyObject *__pyx_t_10 = NULL;
+ PyObject *__pyx_t_11 = NULL;
+ PyObject *(*__pyx_t_12)(PyObject *);
+ double __pyx_t_13;
+ int __pyx_t_14;
+ PyObject *__pyx_t_15 = NULL;
+ int __pyx_t_16;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("read_weights");
+
+ /* "_cdec.pyx":67
+ *
+ * def read_weights(self, cfg):
+ * with open(cfg) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * fname, value = line.split()
+ */
+ /*with:*/ {
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(__pyx_v_cfg);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cfg);
+ __Pyx_GIVEREF(__pyx_v_cfg);
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ /*try:*/ {
+ {
+ __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
+ __Pyx_XGOTREF(__pyx_t_4);
+ __Pyx_XGOTREF(__pyx_t_5);
+ __Pyx_XGOTREF(__pyx_t_6);
+ /*try:*/ {
+ __pyx_v_fp = __pyx_t_2;
+ __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":68
+ * def read_weights(self, cfg):
+ * with open(cfg) as fp:
+ * for line in fp: # <<<<<<<<<<<<<<
+ * fname, value = line.split()
+ * self.weights[fname.strip()] = float(value)
+ */
+ if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) {
+ __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
+ __pyx_t_8 = NULL;
+ } else {
+ __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext;
+ }
+ for (;;) {
+ if (PyList_CheckExact(__pyx_t_2)) {
+ if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
+ __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
+ } else if (PyTuple_CheckExact(__pyx_t_2)) {
+ if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+ __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++;
+ } else {
+ __pyx_t_1 = __pyx_t_8(__pyx_t_2);
+ if (unlikely(!__pyx_t_1)) {
+ if (PyErr_Occurred()) {
+ if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
+ else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ break;
+ }
+ __Pyx_GOTREF(__pyx_t_1);
+ }
+ __Pyx_XDECREF(__pyx_v_line);
+ __pyx_v_line = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":69
+ * with open(cfg) as fp:
+ * for line in fp:
+ * fname, value = line.split() # <<<<<<<<<<<<<<
+ * self.weights[fname.strip()] = float(value)
+ *
+ */
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
+ PyObject* sequence = __pyx_t_9;
+ if (likely(PyTuple_CheckExact(sequence))) {
+ if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
+ if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
+ else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0);
+ __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1);
+ } else {
+ if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
+ if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
+ else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ }
+ __pyx_t_1 = PyList_GET_ITEM(sequence, 0);
+ __pyx_t_10 = PyList_GET_ITEM(sequence, 1);
+ }
+ __Pyx_INCREF(__pyx_t_1);
+ __Pyx_INCREF(__pyx_t_10);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ } else {
+ Py_ssize_t index = -1;
+ __pyx_t_11 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_11);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
+ index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed;
+ __Pyx_GOTREF(__pyx_t_1);
+ index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L19_unpacking_failed;
+ __Pyx_GOTREF(__pyx_t_10);
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+ goto __pyx_L20_unpacking_done;
+ __pyx_L19_unpacking_failed:;
+ __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
+ if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_L20_unpacking_done:;
+ }
+ __Pyx_XDECREF(__pyx_v_fname);
+ __pyx_v_fname = __pyx_t_1;
+ __pyx_t_1 = 0;
+ __Pyx_XDECREF(__pyx_v_value);
+ __pyx_v_value = __pyx_t_10;
+ __pyx_t_10 = 0;
+
+ /* "_cdec.pyx":70
+ * for line in fp:
+ * fname, value = line.split()
+ * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<<
+ *
+ * # TODO: list, lattice translation
+ */
+ __pyx_t_13 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_10);
+ __pyx_t_1 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ if (PyObject_SetItem(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights), __pyx_t_1, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ }
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ }
+ __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+ goto __pyx_L16_try_end;
+ __pyx_L9_error:;
+ __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
+ __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":67
+ *
+ * def read_weights(self, cfg):
+ * with open(cfg) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * fname, value = line.split()
+ */
+ /*except:*/ {
+ __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_9, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_10));
+ __Pyx_INCREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_t_9);
+ PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
+ __Pyx_GIVEREF(__pyx_t_9);
+ __Pyx_INCREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_10, NULL);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __Pyx_GOTREF(__pyx_t_15);
+ __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_15);
+ __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+ if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __pyx_t_16 = (!__pyx_t_14);
+ if (__pyx_t_16) {
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_9);
+ __Pyx_GIVEREF(__pyx_t_1);
+ __Pyx_ErrRestore(__pyx_t_2, __pyx_t_9, __pyx_t_1);
+ __pyx_t_2 = 0; __pyx_t_9 = 0; __pyx_t_1 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ goto __pyx_L23;
+ }
+ __pyx_L23:;
+ __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ goto __pyx_L10_exception_handled;
+ }
+ __pyx_L11_except_error:;
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_XGIVEREF(__pyx_t_6);
+ __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+ goto __pyx_L1_error;
+ __pyx_L10_exception_handled:;
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_XGIVEREF(__pyx_t_6);
+ __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
+ __pyx_L16_try_end:;
+ }
+ }
+ /*finally:*/ {
+ if (__pyx_t_3) {
+ __pyx_t_6 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_6, NULL);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ }
+ goto __pyx_L24;
+ __pyx_L5_error:;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ goto __pyx_L1_error;
+ __pyx_L24:;
+ }
+
+ __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_XDECREF(__pyx_t_9);
+ __Pyx_XDECREF(__pyx_t_10);
+ __Pyx_XDECREF(__pyx_t_11);
+ __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_fp);
+ __Pyx_XDECREF(__pyx_v_line);
+ __Pyx_XDECREF(__pyx_v_fname);
+ __Pyx_XDECREF(__pyx_v_value);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":73
+ *
+ * # TODO: list, lattice translation
+ * def translate(self, unicode sentence, grammar=None): # <<<<<<<<<<<<<<
+ * if grammar:
+ * self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_sentence = 0;
+ PyObject *__pyx_v_grammar = 0;
+ PyObject *__pyx_v_sgml = NULL;
+ BasicObserver __pyx_v_observer;
+ struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ char *__pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0};
+ __Pyx_RefNannySetupContext("translate");
+ {
+ PyObject* values[2] = {0,0};
+ values[1] = ((PyObject *)Py_None);
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 0:
+ values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence);
+ if (likely(values[0])) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ case 1:
+ if (kw_args > 0) {
+ PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar);
+ if (value) { values[1] = value; kw_args--; }
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else {
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_sentence = ((PyObject*)values[0]);
+ __pyx_v_grammar = values[1];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("translate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sentence), (&PyUnicode_Type), 1, "sentence", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":74
+ * # TODO: list, lattice translation
+ * def translate(self, unicode sentence, grammar=None):
+ * if grammar: # <<<<<<<<<<<<<<
+ * self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
+ * #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ */
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":75
+ * def translate(self, unicode sentence, grammar=None):
+ * if grammar:
+ * self.dec.SetSentenceGrammarFromString(string(<char *> grammar)) # <<<<<<<<<<<<<<
+ * #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ * sgml = sentence.strip().encode('utf8')
+ */
+ __pyx_t_2 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_2)));
+ goto __pyx_L6;
+ }
+ __pyx_L6:;
+
+ /* "_cdec.pyx":77
+ * self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
+ * #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ * sgml = sentence.strip().encode('utf8') # <<<<<<<<<<<<<<
+ * cdef decoder.BasicObserver observer = decoder.BasicObserver()
+ * self.dec.Decode(string(<char *>sgml), &observer)
+ */
+ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_sgml = __pyx_t_4;
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":78
+ * #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ * sgml = sentence.strip().encode('utf8')
+ * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<<
+ * self.dec.Decode(string(<char *>sgml), &observer)
+ * if observer.hypergraph == NULL:
+ */
+ __pyx_v_observer = BasicObserver();
+
+ /* "_cdec.pyx":79
+ * sgml = sentence.strip().encode('utf8')
+ * cdef decoder.BasicObserver observer = decoder.BasicObserver()
+ * self.dec.Decode(string(<char *>sgml), &observer) # <<<<<<<<<<<<<<
+ * if observer.hypergraph == NULL:
+ * raise ParseFailed()
+ */
+ __pyx_t_2 = PyBytes_AsString(__pyx_v_sgml); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec->Decode(std::string(((char *)__pyx_t_2)), (&__pyx_v_observer));
+
+ /* "_cdec.pyx":80
+ * cdef decoder.BasicObserver observer = decoder.BasicObserver()
+ * self.dec.Decode(string(<char *>sgml), &observer)
+ * if observer.hypergraph == NULL: # <<<<<<<<<<<<<<
+ * raise ParseFailed()
+ * cdef Hypergraph hg = Hypergraph()
+ */
+ __pyx_t_1 = (__pyx_v_observer.hypergraph == NULL);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":81
+ * self.dec.Decode(string(<char *>sgml), &observer)
+ * if observer.hypergraph == NULL:
+ * raise ParseFailed() # <<<<<<<<<<<<<<
+ * cdef Hypergraph hg = Hypergraph()
+ * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
+ */
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L7;
+ }
+ __pyx_L7:;
+
+ /* "_cdec.pyx":82
+ * if observer.hypergraph == NULL:
+ * raise ParseFailed()
+ * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<<
+ * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
+ * return hg
+ */
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_3);
+ __pyx_t_3 = 0;
+
+ /* "_cdec.pyx":83
+ * raise ParseFailed()
+ * cdef Hypergraph hg = Hypergraph()
+ * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<<
+ * return hg
+ *
+ */
+ __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0]));
+
+ /* "_cdec.pyx":84
+ * cdef Hypergraph hg = Hypergraph()
+ * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
+ * return hg # <<<<<<<<<<<<<<
+ *
+ * cdef class Hypergraph:
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_hg));
+ __pyx_r = ((PyObject *)__pyx_v_hg);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_sgml);
+ __Pyx_XDECREF((PyObject *)__pyx_v_hg);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":40
+ * cdef class Decoder:
+ * cdef decoder.Decoder* dec
+ * cdef public Weights weights # <<<<<<<<<<<<<<
+ *
+ * def __cinit__(self, char* config):
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__");
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights));
+ __pyx_r = ((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights);
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static int __pyx_pf_5_cdec_7Decoder_7weights_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_pf_5_cdec_7Decoder_7weights_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__set__");
+ if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_Weights))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_INCREF(__pyx_v_value);
+ __Pyx_GIVEREF(__pyx_v_value);
+ __Pyx_GOTREF(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights);
+ __Pyx_DECREF(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights));
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights = ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_value);
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static int __pyx_pf_5_cdec_7Decoder_7weights_2__del__(PyObject *__pyx_v_self); /*proto*/
+static int __pyx_pf_5_cdec_7Decoder_7weights_2__del__(PyObject *__pyx_v_self) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__del__");
+ __Pyx_INCREF(Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_GOTREF(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights);
+ __Pyx_DECREF(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights));
+ ((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None);
+
+ __pyx_r = 0;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":90
+ * cdef MT19937* rng
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * del self.hg
+ * if self.rng != NULL:
+ */
+
+static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ __Pyx_RefNannySetupContext("__dealloc__");
+
+ /* "_cdec.pyx":91
+ *
+ * def __dealloc__(self):
+ * del self.hg # <<<<<<<<<<<<<<
+ * if self.rng != NULL:
+ * del self.rng
+ */
+ delete ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg;
+
+ /* "_cdec.pyx":92
+ * def __dealloc__(self):
+ * del self.hg
+ * if self.rng != NULL: # <<<<<<<<<<<<<<
+ * del self.rng
+ *
+ */
+ __pyx_t_1 = (((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->rng != NULL);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":93
+ * del self.hg
+ * if self.rng != NULL:
+ * del self.rng # <<<<<<<<<<<<<<
+ *
+ * def viterbi(self):
+ */
+ delete ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->rng;
+ goto __pyx_L5;
+ }
+ __pyx_L5:;
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "_cdec.pyx":95
+ * del self.rng
+ *
+ * def viterbi(self): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef vector[WordID] trans
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_1viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_1viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ std::vector<WordID> __pyx_v_trans;
+ PyObject *__pyx_v_sentence = 0;
+ 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("viterbi");
+
+ /* "_cdec.pyx":96
+ *
+ * def viterbi(self):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef vector[WordID] trans
+ * hypergraph.ViterbiESentence(self.hg[0], &trans)
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":98
+ * assert (self.hg != NULL)
+ * cdef vector[WordID] trans
+ * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<<
+ * cdef str sentence = GetString(trans).c_str()
+ * return sentence.decode('utf8')
+ */
+ ViterbiESentence((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg[0]), (&__pyx_v_trans));
+
+ /* "_cdec.pyx":99
+ * cdef vector[WordID] trans
+ * hypergraph.ViterbiESentence(self.hg[0], &trans)
+ * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<<
+ * return sentence.decode('utf8')
+ *
+ */
+ __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __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[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_sentence = ((PyObject*)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":100
+ * hypergraph.ViterbiESentence(self.hg[0], &trans)
+ * cdef str sentence = GetString(trans).c_str()
+ * return sentence.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def viterbi_tree(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __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.Hypergraph.viterbi", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_sentence);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":102
+ * return sentence.decode('utf8')
+ *
+ * def viterbi_tree(self): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_v_tree = 0;
+ 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("viterbi_tree");
+
+ /* "_cdec.pyx":103
+ *
+ * def viterbi_tree(self):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8')
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":104
+ * def viterbi_tree(self):
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() # <<<<<<<<<<<<<<
+ * return tree.decode('utf8')
+ *
+ */
+ __pyx_t_1 = PyBytes_FromString(ViterbiETree((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __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[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_tree = ((PyObject*)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":105
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def kbest(self, size):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __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.Hypergraph.viterbi_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_tree);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_4generator1(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":107
+ * return tree.decode('utf8')
+ *
+ * def kbest(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_3kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_3kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("kbest");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ __Pyx_INCREF(__pyx_v_size);
+ __pyx_cur_scope->__pyx_v_size = __pyx_v_size;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_4generator1;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_4generator1(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ unsigned int __pyx_t_1;
+ long __pyx_t_2;
+ int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":108
+ *
+ * def kbest(self, size):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":109
+ * def kbest(self, size):
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ * cdef str tree
+ */
+ __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal>((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_t_1);
+
+ /* "_cdec.pyx":113
+ * cdef str tree
+ * cdef unsigned k
+ * for k in range(size): # <<<<<<<<<<<<<<
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ */
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_1;
+
+ /* "_cdec.pyx":114
+ * cdef unsigned k
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<<
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ */
+ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k);
+
+ /* "_cdec.pyx":115
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break # <<<<<<<<<<<<<<
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8')
+ */
+ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0));
+ if (__pyx_t_3) {
+ goto __pyx_L5_break;
+ goto __pyx_L6;
+ }
+ __pyx_L6:;
+
+ /* "_cdec.pyx":116
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<<
+ * yield tree.decode('utf8')
+ * del derivations
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_tree = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":117
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_L5_break:;
+
+ /* "_cdec.pyx":118
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8')
+ * del derivations # <<<<<<<<<<<<<<
+ *
+ * def kbest_tree(self, size):
+ */
+ delete __pyx_cur_scope->__pyx_v_derivations;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("kbest", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_6generator2(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":120
+ * del derivations
+ *
+ * def kbest_tree(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_5kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_5kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("kbest_tree");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ __Pyx_INCREF(__pyx_v_size);
+ __pyx_cur_scope->__pyx_v_size = __pyx_v_size;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_6generator2;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_6generator2(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ unsigned int __pyx_t_1;
+ long __pyx_t_2;
+ int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":121
+ *
+ * def kbest_tree(self, size):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":122
+ * def kbest_tree(self, size):
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ * cdef str sentence
+ */
+ __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal>((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_t_1);
+
+ /* "_cdec.pyx":126
+ * cdef str sentence
+ * cdef unsigned k
+ * for k in range(size): # <<<<<<<<<<<<<<
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ */
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_1;
+
+ /* "_cdec.pyx":127
+ * cdef unsigned k
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<<
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ */
+ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k);
+
+ /* "_cdec.pyx":128
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break # <<<<<<<<<<<<<<
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8')
+ */
+ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0));
+ if (__pyx_t_3) {
+ goto __pyx_L5_break;
+ goto __pyx_L6;
+ }
+ __pyx_L6:;
+
+ /* "_cdec.pyx":129
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<<
+ * yield sentence.decode('utf8')
+ * del derivations
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":130
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_L5_break:;
+
+ /* "_cdec.pyx":131
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8')
+ * del derivations # <<<<<<<<<<<<<<
+ *
+ * def intersect(self, Lattice lat):
+ */
+ delete __pyx_cur_scope->__pyx_v_derivations;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+
+/* "_cdec.pyx":133
+ * del derivations
+ *
+ * def intersect(self, Lattice lat): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_7intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_7intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("intersect");
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":134
+ *
+ * def intersect(self, Lattice lat):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":135
+ * def intersect(self, Lattice lat):
+ * assert (self.hg != NULL)
+ * hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<<
+ *
+ * def sample(self, unsigned n):
+ */
+ HG::Intersect((((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)->lattice[0]), ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_AddTraceback("_cdec.Hypergraph.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_9generator3(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":137
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ * def sample(self, unsigned n): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_8sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_8sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("sample");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_3_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_sample, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ assert(__pyx_arg_n); {
+ __pyx_cur_scope->__pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_cur_scope->__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __pyx_cur_scope->__pyx_v_self = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_9generator3;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_9generator3(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ int __pyx_t_1;
+ size_t __pyx_t_2;
+ unsigned int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":138
+ *
+ * def sample(self, unsigned n):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL:
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":139
+ * def sample(self, unsigned n):
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<<
+ * if self.rng == NULL:
+ * self.rng = new MT19937()
+ */
+ __pyx_cur_scope->__pyx_v_hypos = new std::vector<HypergraphSampler::Hypothesis>();
+
+ /* "_cdec.pyx":140
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL: # <<<<<<<<<<<<<<
+ * self.rng = new MT19937()
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ */
+ __pyx_t_1 = (((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng == NULL);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":141
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL:
+ * self.rng = new MT19937() # <<<<<<<<<<<<<<
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ * cdef str sentence
+ */
+ ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng = new MT19937();
+ goto __pyx_L4;
+ }
+ __pyx_L4:;
+
+ /* "_cdec.pyx":142
+ * if self.rng == NULL:
+ * self.rng = new MT19937()
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<<
+ * cdef str sentence
+ * cdef unsigned k
+ */
+ HypergraphSampler::sample_hypotheses((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_cur_scope->__pyx_v_n, ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng, __pyx_cur_scope->__pyx_v_hypos);
+
+ /* "_cdec.pyx":145
+ * cdef str sentence
+ * cdef unsigned k
+ * for k in range(hypos.size()): # <<<<<<<<<<<<<<
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8')
+ */
+ __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size();
+ for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_3;
+
+ /* "_cdec.pyx":146
+ * cdef unsigned k
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<<
+ * yield sentence.decode('utf8')
+ * del hypos
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":147
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del hypos
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+
+ /* "_cdec.pyx":148
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8')
+ * del hypos # <<<<<<<<<<<<<<
+ *
+ * # TODO: get feature expectations, get partition function ("inside" score)
+ */
+ delete __pyx_cur_scope->__pyx_v_hypos;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("sample", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+
+/* "_cdec.pyx":157
+ * cdef lattice.Lattice* lattice
+ *
+ * def __init__(self, tuple plf_tuple): # <<<<<<<<<<<<<<
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple)
+ */
+
+static int __pyx_pf_5_cdec_7Lattice___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pf_5_cdec_7Lattice___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_plf_tuple = 0;
+ PyObject *__pyx_v_plf = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ char *__pyx_t_3;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__plf_tuple,0};
+ __Pyx_RefNannySetupContext("__init__");
+ {
+ PyObject* values[1] = {0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 0:
+ values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__plf_tuple);
+ if (likely(values[0])) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ }
+ __pyx_v_plf_tuple = ((PyObject*)values[0]);
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_plf_tuple), (&PyTuple_Type), 1, "plf_tuple", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":158
+ *
+ * def __init__(self, tuple plf_tuple):
+ * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<<
+ * cdef bytes plf = str(plf_tuple)
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ */
+ ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice = new Lattice();
+
+ /* "_cdec.pyx":159
+ * def __init__(self, tuple plf_tuple):
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple) # <<<<<<<<<<<<<<
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ *
+ */
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(((PyObject *)__pyx_v_plf_tuple));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_plf_tuple));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_plf_tuple));
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_plf = ((PyObject*)__pyx_t_2);
+ __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":160
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple)
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice) # <<<<<<<<<<<<<<
+ *
+ * def __str__(self):
+ */
+ __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_plf)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ HypergraphIO::PLFtoLattice(std::string(((char *)__pyx_t_3)), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice);
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_plf);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":162
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ *
+ * def __str__(self): # <<<<<<<<<<<<<<
+ * return hypergraph.AsPLF(self.lattice[0]).c_str()
+ *
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Lattice_1__str__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Lattice_1__str__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__str__");
+
+ /* "_cdec.pyx":163
+ *
+ * def __str__(self):
+ * return hypergraph.AsPLF(self.lattice[0]).c_str() # <<<<<<<<<<<<<<
+ *
+ * def __iter__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice[0]), NULL).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":165
+ * return hypergraph.AsPLF(self.lattice[0]).c_str()
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * return iter(eval(str(self)))
+ *
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Lattice_2__iter__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Lattice_2__iter__(PyObject *__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("__iter__");
+
+ /* "_cdec.pyx":166
+ *
+ * def __iter__(self):
+ * return iter(eval(str(self))) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(__pyx_v_self);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
+ __Pyx_GIVEREF(__pyx_v_self);
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __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.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":168
+ * return iter(eval(str(self)))
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * del self.lattice
+ *
+ */
+
+static void __pyx_pf_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__");
+
+ /* "_cdec.pyx":169
+ *
+ * def __dealloc__(self):
+ * del self.lattice # <<<<<<<<<<<<<<
+ *
+ * # TODO: wrap SparseVector
+ */
+ delete ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice;
+
+ __Pyx_RefNannyFinishContext();
+}
+
+static PyObject *__pyx_tp_new_5_cdec_Weights(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ if (__pyx_pf_5_cdec_7Weights___cinit__(o, a, k) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec_Weights(PyObject *o) {
+ (*Py_TYPE(o)->tp_free)(o);
+}
+static PyObject *__pyx_sq_item_5_cdec_Weights(PyObject *o, Py_ssize_t i) {
+ PyObject *r;
+ PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
+ r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
+ Py_DECREF(x);
+ return r;
+}
+
+static int __pyx_mp_ass_subscript_5_cdec_Weights(PyObject *o, PyObject *i, PyObject *v) {
+ if (v) {
+ return __pyx_pf_5_cdec_7Weights_2__setitem__(o, i, v);
+ }
+ else {
+ PyErr_Format(PyExc_NotImplementedError,
+ "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name);
+ return -1;
+ }
+}
+
+static PyMethodDef __pyx_methods_5_cdec_Weights[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Weights = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_Weights = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ __pyx_sq_item_5_cdec_Weights, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_Weights = {
+ 0, /*mp_length*/
+ __pyx_pf_5_cdec_7Weights_1__getitem__, /*mp_subscript*/
+ __pyx_mp_ass_subscript_5_cdec_Weights, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_Weights = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec_Weights = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.Weights"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec_Weights), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec_Weights, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_Weights, /*tp_as_number*/
+ &__pyx_tp_as_sequence_Weights, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_Weights, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_Weights, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ __pyx_pf_5_cdec_7Weights_3__iter__, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec_Weights, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec_Weights, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec_Decoder *p;
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec_Decoder *)o);
+ p->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None); Py_INCREF(Py_None);
+ if (__pyx_pf_5_cdec_7Decoder___cinit__(o, a, k) < 0) {
+ Py_DECREF(o); o = 0;
+ }
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) {
+ struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o;
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pf_5_cdec_7Decoder_1__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ Py_XDECREF(((PyObject *)p->weights));
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o;
+ if (p->weights) {
+ e = (*v)(((PyObject*)p->weights), a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) {
+ struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o;
+ PyObject* tmp;
+ tmp = ((PyObject*)p->weights);
+ p->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) {
+ return __pyx_pf_5_cdec_7Decoder_7weights___get__(o);
+}
+
+static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) {
+ if (v) {
+ return __pyx_pf_5_cdec_7Decoder_7weights_1__set__(o, v);
+ }
+ else {
+ return __pyx_pf_5_cdec_7Decoder_7weights_2__del__(o);
+ }
+}
+
+static PyMethodDef __pyx_methods_5_cdec_Decoder[] = {
+ {__Pyx_NAMESTR("fromconfig"), (PyCFunction)__pyx_pf_5_cdec_7Decoder_2fromconfig, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pf_5_cdec_7Decoder_3read_weights, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pf_5_cdec_7Decoder_4translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
+ {0, 0, 0, 0}
+};
+
+static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = {
+ {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0},
+ {0, 0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Decoder = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_Decoder = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_Decoder = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_Decoder = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec_Decoder = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_Decoder, /*tp_as_number*/
+ &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec_Decoder, /*tp_methods*/
+ 0, /*tp_members*/
+ __pyx_getsets_5_cdec_Decoder, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec_Decoder, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pf_5_cdec_10Hypergraph___dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = {
+ {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_1viterbi, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_3kbest, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_5kbest_tree, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_7intersect, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_8sample, METH_O, __Pyx_DOCSTR(0)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Hypergraph = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec_Hypergraph = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/
+ &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pf_5_cdec_7Lattice_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_5_cdec_Lattice[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Lattice = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_Lattice = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_Lattice = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_Lattice = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec_Lattice = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number_Lattice, /*tp_as_number*/
+ &__pyx_tp_as_sequence_Lattice, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_Lattice, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ __pyx_pf_5_cdec_7Lattice_1__str__, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ __pyx_pf_5_cdec_7Lattice_2__iter__, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec_Lattice, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ __pyx_pf_5_cdec_7Lattice___init__, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec_Lattice, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec___pyx_Generator(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_Generator_object *p;
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ p = ((struct __pyx_Generator_object *)o);
+ p->exc_type = 0;
+ p->exc_value = 0;
+ p->exc_traceback = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_Generator(PyObject *o) {
+ struct __pyx_Generator_object *p = (struct __pyx_Generator_object *)o;
+ Py_XDECREF(p->exc_type);
+ Py_XDECREF(p->exc_value);
+ Py_XDECREF(p->exc_traceback);
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_Generator(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_Generator_object *p = (struct __pyx_Generator_object *)o;
+ if (p->exc_type) {
+ e = (*v)(p->exc_type, a); if (e) return e;
+ }
+ if (p->exc_value) {
+ e = (*v)(p->exc_value, a); if (e) return e;
+ }
+ if (p->exc_traceback) {
+ e = (*v)(p->exc_traceback, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_Generator(PyObject *o) {
+ struct __pyx_Generator_object *p = (struct __pyx_Generator_object *)o;
+ PyObject* tmp;
+ tmp = ((PyObject*)p->exc_type);
+ p->exc_type = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->exc_value);
+ p->exc_value = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->exc_traceback);
+ p->exc_traceback = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_Generator[] = {
+ {__Pyx_NAMESTR("send"), (PyCFunction)__Pyx_Generator_Send, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("close"), (PyCFunction)__Pyx_Generator_Close, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("throw"), (PyCFunction)__Pyx_Generator_Throw, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_Generator = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_Generator = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_Generator = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_Generator = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_Generator_type = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_Generator"), /*tp_name*/
+ sizeof(struct __pyx_Generator_object), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_Generator, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number___pyx_Generator, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_Generator, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_Generator, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_Generator, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_Generator, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_Generator, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ PyObject_SelfIter, /*tp_iter*/
+ __Pyx_Generator_Next, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_Generator, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec___pyx_Generator, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o);
+ p->__pyx_v_self = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ if (p->__pyx_v_self) {
+ e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1_kbest(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_size = 0;
+ p->__pyx_v_tree = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1_kbest(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(p->__pyx_v_size);
+ Py_XDECREF(((PyObject *)p->__pyx_v_tree));
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ if (p->__pyx_v_self) {
+ e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e;
+ }
+ if (p->__pyx_v_size) {
+ e = (*v)(p->__pyx_v_size, a); if (e) return e;
+ }
+ if (p->__pyx_v_tree) {
+ e = (*v)(p->__pyx_v_tree, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_size);
+ p->__pyx_v_size = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_tree);
+ p->__pyx_v_tree = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1_kbest[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_kbest = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_kbest = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_kbest = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_kbest = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1_kbest"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1_kbest, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number___pyx_scope_struct_1_kbest, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_1_kbest, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_1_kbest, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_1_kbest, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_1_kbest, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec___pyx_scope_struct_1_kbest, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_sentence = 0;
+ p->__pyx_v_size = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(((PyObject *)p->__pyx_v_sentence));
+ Py_XDECREF(p->__pyx_v_size);
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ if (p->__pyx_v_self) {
+ e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e;
+ }
+ if (p->__pyx_v_sentence) {
+ e = (*v)(p->__pyx_v_sentence, a); if (e) return e;
+ }
+ if (p->__pyx_v_size) {
+ e = (*v)(p->__pyx_v_size, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_sentence);
+ p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_size);
+ p->__pyx_v_size = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest_tree[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest_tree = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest_tree = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest_tree"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number___pyx_scope_struct_2_kbest_tree, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest_tree, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_sample(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_sentence = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_sample(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(((PyObject *)p->__pyx_v_sentence));
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_sample(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ if (p->__pyx_v_self) {
+ e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e;
+ }
+ if (p->__pyx_v_sentence) {
+ e = (*v)(p->__pyx_v_sentence, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_sample(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_sentence);
+ p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_sample[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_sample = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_sample = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_sample = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_sample = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_sample = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_sample"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_sample, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*tp_compare*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*tp_repr*/
+ &__pyx_tp_as_number___pyx_scope_struct_3_sample, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_3_sample, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_3_sample, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_3_sample, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_sample, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_3_sample, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_3_sample, /*tp_methods*/
+ 0, /*tp_members*/
+ 0, /*tp_getset*/
+ 0, /*tp_base*/
+ 0, /*tp_dict*/
+ 0, /*tp_descr_get*/
+ 0, /*tp_descr_set*/
+ 0, /*tp_dictoffset*/
+ 0, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec___pyx_scope_struct_3_sample, /*tp_new*/
+ 0, /*tp_free*/
+ 0, /*tp_is_gc*/
+ 0, /*tp_bases*/
+ 0, /*tp_mro*/
+ 0, /*tp_cache*/
+ 0, /*tp_subclasses*/
+ 0, /*tp_weaklist*/
+ 0, /*tp_del*/
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*tp_version_tag*/
+ #endif
+};
+
+static PyMethodDef __pyx_methods[] = {
+ {0, 0, 0, 0}
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef __pyx_moduledef = {
+ PyModuleDef_HEAD_INIT,
+ __Pyx_NAMESTR("_cdec"),
+ 0, /* m_doc */
+ -1, /* m_size */
+ __pyx_methods /* m_methods */,
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
+};
+#endif
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+ {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
+ {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
+ {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1},
+ {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
+ {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1},
+ {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1},
+ {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1},
+ {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
+ {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
+ {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1},
+ {&__pyx_n_s__config, __pyx_k__config, sizeof(__pyx_k__config), 0, 0, 1, 1},
+ {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1},
+ {&__pyx_n_s__decoder, __pyx_k__decoder, sizeof(__pyx_k__decoder), 0, 0, 1, 1},
+ {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1},
+ {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1},
+ {&__pyx_n_s__fromconfig, __pyx_k__fromconfig, sizeof(__pyx_k__fromconfig), 0, 0, 1, 1},
+ {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1},
+ {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1},
+ {&__pyx_n_s__plf_tuple, __pyx_k__plf_tuple, sizeof(__pyx_k__plf_tuple), 0, 0, 1, 1},
+ {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
+ {&__pyx_n_s__sentence, __pyx_k__sentence, sizeof(__pyx_k__sentence), 0, 0, 1, 1},
+ {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
+ {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1},
+ {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1},
+ {&__pyx_n_s__utf8, __pyx_k__utf8, sizeof(__pyx_k__utf8), 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+static int __Pyx_InitCachedBuiltins(void) {
+ __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+static int __Pyx_InitCachedConstants(void) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
+
+ /* "_cdec.pyx":61
+ * for line in fp:
+ * line = line.strip()
+ * if not line or line.startswith('#'): continue # <<<<<<<<<<<<<<
+ * param, value = line.split('=')
+ * config[param.strip()] = value.strip()
+ */
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
+ PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
+
+ /* "_cdec.pyx":62
+ * line = line.strip()
+ * if not line or line.startswith('#'): continue
+ * param, value = line.split('=') # <<<<<<<<<<<<<<
+ * config[param.strip()] = value.strip()
+ * return cls(**config)
+ */
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
+ __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
+ PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
+
+ /* "_cdec.pyx":58
+ * def fromconfig(cls, ini):
+ * cdef dict config = {}
+ * with open(ini) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * line = line.strip()
+ */
+ __pyx_k_tuple_5 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5));
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 1, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_5, 2, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
+
+ /* "_cdec.pyx":67
+ *
+ * def read_weights(self, cfg):
+ * with open(cfg) as fp: # <<<<<<<<<<<<<<
+ * for line in fp:
+ * fname, value = line.split()
+ */
+ __pyx_k_tuple_6 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_6, 1, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_INCREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_k_tuple_6, 2, Py_None);
+ __Pyx_GIVEREF(Py_None);
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
+
+ /* "_cdec.pyx":77
+ * self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
+ * #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ * sgml = sentence.strip().encode('utf8') # <<<<<<<<<<<<<<
+ * cdef decoder.BasicObserver observer = decoder.BasicObserver()
+ * self.dec.Decode(string(<char *>sgml), &observer)
+ */
+ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));
+
+ /* "_cdec.pyx":100
+ * hypergraph.ViterbiESentence(self.hg[0], &trans)
+ * cdef str sentence = GetString(trans).c_str()
+ * return sentence.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def viterbi_tree(self):
+ */
+ __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
+
+ /* "_cdec.pyx":105
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def kbest(self, size):
+ */
+ __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_9));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9));
+
+ /* "_cdec.pyx":117
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
+
+ /* "_cdec.pyx":130
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_11));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
+
+ /* "_cdec.pyx":147
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del hypos
+ *
+ */
+ __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
+ __Pyx_RefNannyFinishContext();
+ return 0;
+ __pyx_L1_error:;
+ __Pyx_RefNannyFinishContext();
+ return -1;
+}
+
+static int __Pyx_InitGlobals(void) {
+ if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ return 0;
+ __pyx_L1_error:;
+ return -1;
+}
+
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC init_cdec(void); /*proto*/
+PyMODINIT_FUNC init_cdec(void)
+#else
+PyMODINIT_FUNC PyInit__cdec(void); /*proto*/
+PyMODINIT_FUNC PyInit__cdec(void)
+#endif
+{
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ __Pyx_RefNannyDeclarations
+ #if CYTHON_REFNANNY
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
+ if (!__Pyx_RefNanny) {
+ PyErr_Clear();
+ __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
+ if (!__Pyx_RefNanny)
+ Py_FatalError("failed to import 'refnanny' module");
+ }
+ #endif
+ __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__cdec(void)");
+ if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #ifdef __pyx_binding_PyCFunctionType_USED
+ if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ #endif
+ /*--- Library function declarations ---*/
+ /*--- Threads initialization code ---*/
+ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
+ #ifdef WITH_THREAD /* Python build with threading support? */
+ PyEval_InitThreads();
+ #endif
+ #endif
+ /*--- Module creation code ---*/
+ #if PY_MAJOR_VERSION < 3
+ __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_cdec"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
+ #else
+ __pyx_m = PyModule_Create(&__pyx_moduledef);
+ #endif
+ if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ #if PY_MAJOR_VERSION < 3
+ Py_INCREF(__pyx_m);
+ #endif
+ __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
+ if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ /*--- Initialize various global constants etc. ---*/
+ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__pyx_module_is_main__cdec) {
+ if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ }
+ /*--- Builtin init code ---*/
+ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Constants init code ---*/
+ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ /*--- Global init code ---*/
+ /*--- Variable export code ---*/
+ /*--- Function export code ---*/
+ /*--- Type init code ---*/
+ if (PyType_Ready(&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Weights", (PyObject *)&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec_Weights = &__pyx_type_5_cdec_Weights;
+ if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __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 = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder;
+ if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph;
+ if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice;
+ if (PyType_Ready(&__pyx_Generator_type) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_Generator = &__pyx_Generator_type;
+ __pyx_type_5_cdec___pyx_scope_struct____iter__.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__;
+ __pyx_type_5_cdec___pyx_scope_struct_1_kbest.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1_kbest) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_1_kbest = &__pyx_type_5_cdec___pyx_scope_struct_1_kbest;
+ __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree;
+ __pyx_type_5_cdec___pyx_scope_struct_3_sample.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_sample) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_3_sample = &__pyx_type_5_cdec___pyx_scope_struct_3_sample;
+ /*--- Type import code ---*/
+ /*--- Variable import code ---*/
+ /*--- Function import code ---*/
+ /*--- Execution code ---*/
+
+ /* "_cdec.pyx":10
+ * cimport kbest as kb
+ *
+ * SetSilent(True) # <<<<<<<<<<<<<<
+ *
+ * class ParseFailed(Exception):
+ */
+ SetSilent(1);
+
+ /* "_cdec.pyx":12
+ * SetSilent(True)
+ *
+ * class ParseFailed(Exception): # <<<<<<<<<<<<<<
+ * pass
+ *
+ */
+ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __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[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_2));
+ __Pyx_INCREF(__pyx_builtin_Exception);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_Exception);
+ __Pyx_GIVEREF(__pyx_builtin_Exception);
+ __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":56
+ *
+ * @classmethod
+ * def fromconfig(cls, ini): # <<<<<<<<<<<<<<
+ * cdef dict config = {}
+ * with open(ini) as fp:
+ */
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_5_cdec_Decoder, __pyx_n_s__fromconfig); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_5_cdec_Decoder->tp_dict, __pyx_n_s__fromconfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ PyType_Modified(__pyx_ptype_5_cdec_Decoder);
+
+ /* "_cdec.pyx":1
+ * from libcpp.string cimport string # <<<<<<<<<<<<<<
+ * from libcpp.vector cimport vector
+ * from cython.operator cimport dereference as deref
+ */
+ __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_3));
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ if (__pyx_m) {
+ __Pyx_AddTraceback("init _cdec", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ Py_DECREF(__pyx_m); __pyx_m = 0;
+ } else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "init _cdec");
+ }
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ #if PY_MAJOR_VERSION < 3
+ return;
+ #else
+ return __pyx_m;
+ #endif
+}
+
+/* Runtime support code */
+
+#if CYTHON_REFNANNY
+static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
+ PyObject *m = NULL, *p = NULL;
+ void *r = NULL;
+ m = PyImport_ImportModule((char *)modname);
+ if (!m) goto end;
+ p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
+ if (!p) goto end;
+ r = PyLong_AsVoidPtr(p);
+end:
+ Py_XDECREF(p);
+ Py_XDECREF(m);
+ return (__Pyx_RefNannyAPIStruct *)r;
+}
+#endif /* CYTHON_REFNANNY */
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+ PyObject *result;
+ result = PyObject_GetAttr(dict, name);
+ if (!result) {
+ if (dict != __pyx_b) {
+ PyErr_Clear();
+ result = PyObject_GetAttr(__pyx_b, name);
+ }
+ if (!result) {
+ PyErr_SetObject(PyExc_NameError, name);
+ }
+ }
+ return result;
+}
+
+static void __Pyx_RaiseDoubleKeywordsError(
+ const char* func_name,
+ PyObject* kw_name)
+{
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION >= 3
+ "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
+ #else
+ "%s() got multiple values for keyword argument '%s'", func_name,
+ PyString_AS_STRING(kw_name));
+ #endif
+}
+
+static int __Pyx_ParseOptionalKeywords(
+ PyObject *kwds,
+ PyObject **argnames[],
+ PyObject *kwds2,
+ PyObject *values[],
+ Py_ssize_t num_pos_args,
+ const char* function_name)
+{
+ PyObject *key = 0, *value = 0;
+ Py_ssize_t pos = 0;
+ PyObject*** name;
+ PyObject*** first_kw_arg = argnames + num_pos_args;
+
+ while (PyDict_Next(kwds, &pos, &key, &value)) {
+ name = first_kw_arg;
+ while (*name && (**name != key)) name++;
+ if (*name) {
+ values[name-argnames] = value;
+ } else {
+ #if PY_MAJOR_VERSION < 3
+ if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
+ #else
+ if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
+ #endif
+ goto invalid_keyword_type;
+ } else {
+ for (name = first_kw_arg; *name; name++) {
+ #if PY_MAJOR_VERSION >= 3
+ if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
+ PyUnicode_Compare(**name, key) == 0) break;
+ #else
+ if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
+ _PyString_Eq(**name, key)) break;
+ #endif
+ }
+ if (*name) {
+ values[name-argnames] = value;
+ } else {
+ /* unexpected keyword found */
+ for (name=argnames; name != first_kw_arg; name++) {
+ if (**name == key) goto arg_passed_twice;
+ #if PY_MAJOR_VERSION >= 3
+ if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
+ PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
+ #else
+ if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
+ _PyString_Eq(**name, key)) goto arg_passed_twice;
+ #endif
+ }
+ if (kwds2) {
+ if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+ } else {
+ goto invalid_keyword;
+ }
+ }
+ }
+ }
+ }
+ return 0;
+arg_passed_twice:
+ __Pyx_RaiseDoubleKeywordsError(function_name, **name);
+ goto bad;
+invalid_keyword_type:
+ PyErr_Format(PyExc_TypeError,
+ "%s() keywords must be strings", function_name);
+ goto bad;
+invalid_keyword:
+ PyErr_Format(PyExc_TypeError,
+ #if PY_MAJOR_VERSION < 3
+ "%s() got an unexpected keyword argument '%s'",
+ function_name, PyString_AsString(key));
+ #else
+ "%s() got an unexpected keyword argument '%U'",
+ function_name, key);
+ #endif
+bad:
+ return -1;
+}
+
+static void __Pyx_RaiseArgtupleInvalid(
+ const char* func_name,
+ int exact,
+ Py_ssize_t num_min,
+ Py_ssize_t num_max,
+ Py_ssize_t num_found)
+{
+ Py_ssize_t num_expected;
+ const char *more_or_less;
+
+ if (num_found < num_min) {
+ num_expected = num_min;
+ more_or_less = "at least";
+ } else {
+ num_expected = num_max;
+ more_or_less = "at most";
+ }
+ if (exact) {
+ more_or_less = "exactly";
+ }
+ PyErr_Format(PyExc_TypeError,
+ "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)",
+ func_name, more_or_less, num_expected,
+ (num_expected == 1) ? "" : "s", num_found);
+}
+
+static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
+ const char *name, int exact)
+{
+ if (!type) {
+ PyErr_Format(PyExc_SystemError, "Missing type object");
+ return 0;
+ }
+ if (none_allowed && obj == Py_None) return 1;
+ else if (exact) {
+ if (Py_TYPE(obj) == type) return 1;
+ }
+ else {
+ if (PyObject_TypeCheck(obj, type)) return 1;
+ }
+ PyErr_Format(PyExc_TypeError,
+ "Argument '%s' has incorrect type (expected %s, got %s)",
+ name, type->tp_name, Py_TYPE(obj)->tp_name);
+ return 0;
+}
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+
+ tmp_type = tstate->curexc_type;
+ tmp_value = tstate->curexc_value;
+ tmp_tb = tstate->curexc_traceback;
+ tstate->curexc_type = type;
+ tstate->curexc_value = value;
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+}
+
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->curexc_type;
+ *value = tstate->curexc_value;
+ *tb = tstate->curexc_traceback;
+
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+}
+
+
+#if PY_MAJOR_VERSION < 3
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ /* cause is unused */
+ Py_XINCREF(type);
+ Py_XINCREF(value);
+ Py_XINCREF(tb);
+ /* First, check the traceback argument, replacing None with NULL. */
+ if (tb == Py_None) {
+ Py_DECREF(tb);
+ tb = 0;
+ }
+ else if (tb != NULL && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto raise_error;
+ }
+ /* Next, replace a missing value with None */
+ if (value == NULL) {
+ value = Py_None;
+ Py_INCREF(value);
+ }
+ #if PY_VERSION_HEX < 0x02050000
+ if (!PyClass_Check(type))
+ #else
+ if (!PyType_Check(type))
+ #endif
+ {
+ /* Raising an instance. The value should be a dummy. */
+ if (value != Py_None) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto raise_error;
+ }
+ /* Normalize to raise <class>, <instance> */
+ Py_DECREF(value);
+ value = type;
+ #if PY_VERSION_HEX < 0x02050000
+ if (PyInstance_Check(type)) {
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
+ }
+ else {
+ type = 0;
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception must be an old-style class or instance");
+ goto raise_error;
+ }
+ #else
+ type = (PyObject*) Py_TYPE(type);
+ Py_INCREF(type);
+ if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto raise_error;
+ }
+ #endif
+ }
+
+ __Pyx_ErrRestore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ return;
+}
+
+#else /* Python 3+ */
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
+ if (tb == Py_None) {
+ tb = 0;
+ } else if (tb && !PyTraceBack_Check(tb)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: arg 3 must be a traceback or None");
+ goto bad;
+ }
+ if (value == Py_None)
+ value = 0;
+
+ if (PyExceptionInstance_Check(type)) {
+ if (value) {
+ PyErr_SetString(PyExc_TypeError,
+ "instance exception may not have a separate value");
+ goto bad;
+ }
+ value = type;
+ type = (PyObject*) Py_TYPE(value);
+ } else if (!PyExceptionClass_Check(type)) {
+ PyErr_SetString(PyExc_TypeError,
+ "raise: exception class must be a subclass of BaseException");
+ goto bad;
+ }
+
+ if (cause) {
+ PyObject *fixed_cause;
+ if (PyExceptionClass_Check(cause)) {
+ fixed_cause = PyObject_CallObject(cause, NULL);
+ if (fixed_cause == NULL)
+ goto bad;
+ }
+ else if (PyExceptionInstance_Check(cause)) {
+ fixed_cause = cause;
+ Py_INCREF(fixed_cause);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "exception causes must derive from "
+ "BaseException");
+ goto bad;
+ }
+ if (!value) {
+ value = PyObject_CallObject(type, NULL);
+ }
+ PyException_SetCause(value, fixed_cause);
+ }
+
+ PyErr_SetObject(type, value);
+
+ if (tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ PyObject* tmp_tb = tstate->curexc_traceback;
+ if (tb != tmp_tb) {
+ Py_INCREF(tb);
+ tstate->curexc_traceback = tb;
+ Py_XDECREF(tmp_tb);
+ }
+ }
+
+bad:
+ return;
+}
+#endif
+
+static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
+ PyErr_Format(PyExc_ValueError,
+ "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack",
+ index, (index == 1) ? "" : "s");
+}
+
+static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
+ PyErr_Format(PyExc_ValueError,
+ "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected);
+}
+
+static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
+ if (unlikely(retval)) {
+ Py_DECREF(retval);
+ __Pyx_RaiseTooManyValuesError(expected);
+ return -1;
+ } else if (PyErr_Occurred()) {
+ if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
+ PyErr_Clear();
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
+ PyObject *local_type, *local_value, *local_tb;
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ local_type = tstate->curexc_type;
+ local_value = tstate->curexc_value;
+ local_tb = tstate->curexc_traceback;
+ tstate->curexc_type = 0;
+ tstate->curexc_value = 0;
+ tstate->curexc_traceback = 0;
+ PyErr_NormalizeException(&local_type, &local_value, &local_tb);
+ if (unlikely(tstate->curexc_type))
+ goto bad;
+ #if PY_MAJOR_VERSION >= 3
+ if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
+ goto bad;
+ #endif
+ *type = local_type;
+ *value = local_value;
+ *tb = local_tb;
+ Py_INCREF(local_type);
+ Py_INCREF(local_value);
+ Py_INCREF(local_tb);
+ tmp_type = tstate->exc_type;
+ tmp_value = tstate->exc_value;
+ tmp_tb = tstate->exc_traceback;
+ tstate->exc_type = local_type;
+ tstate->exc_value = local_value;
+ tstate->exc_traceback = local_tb;
+ /* Make sure tstate is in a consistent state when we XDECREF
+ these objects (XDECREF may run arbitrary code). */
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+ return 0;
+bad:
+ *type = 0;
+ *value = 0;
+ *tb = 0;
+ Py_XDECREF(local_type);
+ Py_XDECREF(local_value);
+ Py_XDECREF(local_tb);
+ return -1;
+}
+
+
+static double __Pyx__PyObject_AsDouble(PyObject* obj) {
+ PyObject* float_value;
+ if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) {
+ return PyFloat_AsDouble(obj);
+ } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) {
+#if PY_MAJOR_VERSION >= 3
+ float_value = PyFloat_FromString(obj);
+#else
+ float_value = PyFloat_FromString(obj, 0);
+#endif
+ } else {
+ PyObject* args = PyTuple_New(1);
+ if (unlikely(!args)) goto bad;
+ PyTuple_SET_ITEM(args, 0, obj);
+ float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0);
+ PyTuple_SET_ITEM(args, 0, 0);
+ Py_DECREF(args);
+ }
+ if (likely(float_value)) {
+ double value = PyFloat_AS_DOUBLE(float_value);
+ Py_DECREF(float_value);
+ return value;
+ }
+bad:
+ return (double)-1;
+}
+
+static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+ if (unlikely(!type)) {
+ PyErr_Format(PyExc_SystemError, "Missing type object");
+ return 0;
+ }
+ if (likely(PyObject_TypeCheck(obj, type)))
+ return 1;
+ PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
+ Py_TYPE(obj)->tp_name, type->tp_name);
+ return 0;
+}
+
+static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
+ PyThreadState *tstate = PyThreadState_GET();
+ *type = tstate->exc_type;
+ *value = tstate->exc_value;
+ *tb = tstate->exc_traceback;
+ Py_XINCREF(*type);
+ Py_XINCREF(*value);
+ Py_XINCREF(*tb);
+}
+
+static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+ tmp_type = tstate->exc_type;
+ tmp_value = tstate->exc_value;
+ tmp_tb = tstate->exc_traceback;
+ tstate->exc_type = type;
+ tstate->exc_value = value;
+ tstate->exc_traceback = tb;
+ Py_XDECREF(tmp_type);
+ Py_XDECREF(tmp_value);
+ Py_XDECREF(tmp_tb);
+}
+
+static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) {
+ PyObject *metaclass;
+ /* Default metaclass */
+#if PY_MAJOR_VERSION < 3
+ if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
+ PyObject *base = PyTuple_GET_ITEM(bases, 0);
+ metaclass = PyObject_GetAttrString(base, (char *)"__class__");
+ if (!metaclass) {
+ PyErr_Clear();
+ metaclass = (PyObject*) Py_TYPE(base);
+ }
+ } else {
+ metaclass = (PyObject *) &PyClass_Type;
+ }
+#else
+ if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
+ PyObject *base = PyTuple_GET_ITEM(bases, 0);
+ metaclass = (PyObject*) Py_TYPE(base);
+ } else {
+ metaclass = (PyObject *) &PyType_Type;
+ }
+#endif
+ Py_INCREF(metaclass);
+ return metaclass;
+}
+
+static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
+ PyObject *modname) {
+ PyObject *result;
+ PyObject *metaclass;
+
+ if (PyDict_SetItemString(dict, "__module__", modname) < 0)
+ return NULL;
+
+ /* Python2 __metaclass__ */
+ metaclass = PyDict_GetItemString(dict, "__metaclass__");
+ if (metaclass) {
+ Py_INCREF(metaclass);
+ } else {
+ metaclass = __Pyx_FindPy2Metaclass(bases);
+ }
+ result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
+ Py_DECREF(metaclass);
+ return result;
+}
+
+static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
+ /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
+ static PyTypeObject *methoddescr_type = NULL;
+ if (methoddescr_type == NULL) {
+ PyObject *meth = __Pyx_GetAttrString((PyObject*)&PyList_Type, "append");
+ if (!meth) return NULL;
+ methoddescr_type = Py_TYPE(meth);
+ Py_DECREF(meth);
+ }
+ if (PyObject_TypeCheck(method, methoddescr_type)) { /* cdef classes */
+ PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+ #if PY_VERSION_HEX < 0x03020000
+ PyTypeObject *d_type = descr->d_type;
+ #else
+ PyTypeObject *d_type = descr->d_common.d_type;
+ #endif
+ return PyDescr_NewClassMethod(d_type, descr->d_method);
+ }
+ else if (PyMethod_Check(method)) { /* python classes */
+ return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
+ }
+ else if (PyCFunction_Check(method)) {
+ return PyClassMethod_New(method);
+ }
+#ifdef __pyx_binding_PyCFunctionType_USED
+ else if (PyObject_TypeCheck(method, __pyx_binding_PyCFunctionType)) { /* binded CFunction */
+ return PyClassMethod_New(method);
+ }
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "Class-level classmethod() can only be called on "
+ "a method_descriptor or instance method.");
+ return NULL;
+}
+
+static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
+ const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned char" :
+ "value too large to convert to unsigned char");
+ }
+ return (unsigned char)-1;
+ }
+ return (unsigned char)val;
+ }
+ return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
+ const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned short" :
+ "value too large to convert to unsigned short");
+ }
+ return (unsigned short)-1;
+ }
+ return (unsigned short)val;
+ }
+ return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
+ const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(unsigned int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(unsigned int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to unsigned int" :
+ "value too large to convert to unsigned int");
+ }
+ return (unsigned int)-1;
+ }
+ return (unsigned int)val;
+ }
+ return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
+}
+
+static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
+ const char neg_one = (char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to char" :
+ "value too large to convert to char");
+ }
+ return (char)-1;
+ }
+ return (char)val;
+ }
+ return (char)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
+ const short neg_one = (short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to short" :
+ "value too large to convert to short");
+ }
+ return (short)-1;
+ }
+ return (short)val;
+ }
+ return (short)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
+ const signed char neg_one = (signed char)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed char) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed char)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed char" :
+ "value too large to convert to signed char");
+ }
+ return (signed char)-1;
+ }
+ return (signed char)val;
+ }
+ return (signed char)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
+ const signed short neg_one = (signed short)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed short) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed short)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed short" :
+ "value too large to convert to signed short");
+ }
+ return (signed short)-1;
+ }
+ return (signed short)val;
+ }
+ return (signed short)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
+ const signed int neg_one = (signed int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(signed int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(signed int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to signed int" :
+ "value too large to convert to signed int");
+ }
+ return (signed int)-1;
+ }
+ return (signed int)val;
+ }
+ return (signed int)__Pyx_PyInt_AsSignedLong(x);
+}
+
+static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
+ const int neg_one = (int)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+ if (sizeof(int) < sizeof(long)) {
+ long val = __Pyx_PyInt_AsLong(x);
+ if (unlikely(val != (long)(int)val)) {
+ if (!unlikely(val == -1 && PyErr_Occurred())) {
+ PyErr_SetString(PyExc_OverflowError,
+ (is_unsigned && unlikely(val < 0)) ?
+ "can't convert negative value to int" :
+ "value too large to convert to int");
+ }
+ return (int)-1;
+ }
+ return (int)val;
+ }
+ return (int)__Pyx_PyInt_AsLong(x);
+}
+
+static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
+ const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned long");
+ return (unsigned long)-1;
+ }
+ return (unsigned long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (unsigned long)PyLong_AsLong(x);
+ }
+ } else {
+ unsigned long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned long)-1;
+ val = __Pyx_PyInt_AsUnsignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
+ const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to unsigned PY_LONG_LONG");
+ return (unsigned PY_LONG_LONG)-1;
+ }
+ return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ unsigned PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (unsigned PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
+ const long neg_one = (long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to long");
+ return (long)-1;
+ }
+ return (long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (long)PyLong_AsLong(x);
+ }
+ } else {
+ long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (long)-1;
+ val = __Pyx_PyInt_AsLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
+ const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to PY_LONG_LONG");
+ return (PY_LONG_LONG)-1;
+ }
+ return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
+ const signed long neg_one = (signed long)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed long");
+ return (signed long)-1;
+ }
+ return (signed long)PyLong_AsUnsignedLong(x);
+ } else {
+ return (signed long)PyLong_AsLong(x);
+ }
+ } else {
+ signed long val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed long)-1;
+ val = __Pyx_PyInt_AsSignedLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
+ const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
+ const int is_unsigned = neg_one > const_zero;
+#if PY_VERSION_HEX < 0x03000000
+ if (likely(PyInt_Check(x))) {
+ long val = PyInt_AS_LONG(x);
+ if (is_unsigned && unlikely(val < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)val;
+ } else
+#endif
+ if (likely(PyLong_Check(x))) {
+ if (is_unsigned) {
+ if (unlikely(Py_SIZE(x) < 0)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "can't convert negative value to signed PY_LONG_LONG");
+ return (signed PY_LONG_LONG)-1;
+ }
+ return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
+ } else {
+ return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
+ }
+ } else {
+ signed PY_LONG_LONG val;
+ PyObject *tmp = __Pyx_PyNumber_Int(x);
+ if (!tmp) return (signed PY_LONG_LONG)-1;
+ val = __Pyx_PyInt_AsSignedLongLong(tmp);
+ Py_DECREF(tmp);
+ return val;
+ }
+}
+
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
+ PyObject *tmp_type, *tmp_value, *tmp_tb;
+ PyThreadState *tstate = PyThreadState_GET();
+
+ tmp_type = tstate->exc_type;
+ tmp_value = tstate->exc_value;
+ tmp_tb = tstate->exc_traceback;
+
+ tstate->exc_type = *type;
+ tstate->exc_value = *value;
+ tstate->exc_traceback = *tb;
+
+ *type = tmp_type;
+ *value = tmp_value;
+ *tb = tmp_tb;
+}
+
+static CYTHON_INLINE void __Pyx_Generator_ExceptionClear(struct __pyx_Generator_object *self)
+{
+ Py_XDECREF(self->exc_type);
+ Py_XDECREF(self->exc_value);
+ Py_XDECREF(self->exc_traceback);
+
+ self->exc_type = NULL;
+ self->exc_value = NULL;
+ self->exc_traceback = NULL;
+}
+
+static CYTHON_INLINE PyObject *__Pyx_Generator_SendEx(struct __pyx_Generator_object *self, PyObject *value)
+{
+ PyObject *retval;
+
+ if (self->is_running) {
+ PyErr_SetString(PyExc_ValueError,
+ "generator already executing");
+ return NULL;
+ }
+
+ if (self->resume_label == 0) {
+ if (value && value != Py_None) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't send non-None value to a "
+ "just-started generator");
+ return NULL;
+ }
+ }
+
+ if (self->resume_label == -1) {
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+ }
+
+
+ if (value)
+ __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback);
+ else
+ __Pyx_Generator_ExceptionClear(self);
+
+ self->is_running = 1;
+ retval = self->body((PyObject *) self, value);
+ self->is_running = 0;
+
+ if (retval)
+ __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback);
+ else
+ __Pyx_Generator_ExceptionClear(self);
+
+ return retval;
+}
+
+static PyObject *__Pyx_Generator_Next(PyObject *self)
+{
+ return __Pyx_Generator_SendEx((struct __pyx_Generator_object *) self, Py_None);
+}
+
+static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value)
+{
+ return __Pyx_Generator_SendEx((struct __pyx_Generator_object *) self, value);
+}
+
+static PyObject *__Pyx_Generator_Close(PyObject *self)
+{
+ struct __pyx_Generator_object *generator = (struct __pyx_Generator_object *) self;
+ PyObject *retval;
+#if PY_VERSION_HEX < 0x02050000
+ PyErr_SetNone(PyExc_StopIteration);
+#else
+ PyErr_SetNone(PyExc_GeneratorExit);
+#endif
+ retval = __Pyx_Generator_SendEx(generator, NULL);
+ if (retval) {
+ Py_DECREF(retval);
+ PyErr_SetString(PyExc_RuntimeError,
+ "generator ignored GeneratorExit");
+ return NULL;
+ }
+#if PY_VERSION_HEX < 0x02050000
+ if (PyErr_ExceptionMatches(PyExc_StopIteration))
+#else
+ if (PyErr_ExceptionMatches(PyExc_StopIteration)
+ || PyErr_ExceptionMatches(PyExc_GeneratorExit))
+#endif
+ {
+ PyErr_Clear(); /* ignore these errors */
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return NULL;
+}
+
+static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args, CYTHON_UNUSED PyObject *kwds)
+{
+ struct __pyx_Generator_object *generator = (struct __pyx_Generator_object *) self;
+ PyObject *typ;
+ PyObject *tb = NULL;
+ PyObject *val = NULL;
+
+ if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
+ return NULL;
+ __Pyx_Raise(typ, val, tb, NULL);
+ return __Pyx_Generator_SendEx(generator, NULL);
+}
+
+static int __Pyx_check_binary_version(void) {
+ char ctversion[4], rtversion[4];
+ PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+ PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+ if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+ char message[200];
+ PyOS_snprintf(message, sizeof(message),
+ "compiletime version %s of module '%.100s' "
+ "does not match runtime version %s",
+ ctversion, __Pyx_MODULE_NAME, rtversion);
+ #if PY_VERSION_HEX < 0x02050000
+ return PyErr_Warn(NULL, message);
+ #else
+ return PyErr_WarnEx(NULL, message, 1);
+ #endif
+ }
+ return 0;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno,
+ int __pyx_lineno, const char *__pyx_filename) {
+ PyObject *py_srcfile = 0;
+ PyObject *py_funcname = 0;
+ PyObject *py_globals = 0;
+ PyCodeObject *py_code = 0;
+ PyFrameObject *py_frame = 0;
+
+ #if PY_MAJOR_VERSION < 3
+ py_srcfile = PyString_FromString(__pyx_filename);
+ #else
+ py_srcfile = PyUnicode_FromString(__pyx_filename);
+ #endif
+ if (!py_srcfile) goto bad;
+ if (__pyx_clineno) {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
+ #else
+ py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
+ #endif
+ }
+ else {
+ #if PY_MAJOR_VERSION < 3
+ py_funcname = PyString_FromString(funcname);
+ #else
+ py_funcname = PyUnicode_FromString(funcname);
+ #endif
+ }
+ if (!py_funcname) goto bad;
+ py_globals = PyModule_GetDict(__pyx_m);
+ if (!py_globals) goto bad;
+ py_code = PyCode_New(
+ 0, /*int argcount,*/
+ #if PY_MAJOR_VERSION >= 3
+ 0, /*int kwonlyargcount,*/
+ #endif
+ 0, /*int nlocals,*/
+ 0, /*int stacksize,*/
+ 0, /*int flags,*/
+ __pyx_empty_bytes, /*PyObject *code,*/
+ __pyx_empty_tuple, /*PyObject *consts,*/
+ __pyx_empty_tuple, /*PyObject *names,*/
+ __pyx_empty_tuple, /*PyObject *varnames,*/
+ __pyx_empty_tuple, /*PyObject *freevars,*/
+ __pyx_empty_tuple, /*PyObject *cellvars,*/
+ py_srcfile, /*PyObject *filename,*/
+ py_funcname, /*PyObject *name,*/
+ __pyx_lineno, /*int firstlineno,*/
+ __pyx_empty_bytes /*PyObject *lnotab*/
+ );
+ if (!py_code) goto bad;
+ py_frame = PyFrame_New(
+ PyThreadState_GET(), /*PyThreadState *tstate,*/
+ py_code, /*PyCodeObject *code,*/
+ py_globals, /*PyObject *globals,*/
+ 0 /*PyObject *locals*/
+ );
+ if (!py_frame) goto bad;
+ py_frame->f_lineno = __pyx_lineno;
+ PyTraceBack_Here(py_frame);
+bad:
+ Py_XDECREF(py_srcfile);
+ Py_XDECREF(py_funcname);
+ Py_XDECREF(py_code);
+ Py_XDECREF(py_frame);
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+ while (t->p) {
+ #if PY_MAJOR_VERSION < 3
+ if (t->is_unicode) {
+ *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
+ } else if (t->intern) {
+ *t->p = PyString_InternFromString(t->s);
+ } else {
+ *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+ }
+ #else /* Python 3+ has unicode identifiers */
+ if (t->is_unicode | t->is_str) {
+ if (t->intern) {
+ *t->p = PyUnicode_InternFromString(t->s);
+ } else if (t->encoding) {
+ *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
+ } else {
+ *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
+ }
+ } else {
+ *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
+ }
+ #endif
+ if (!*t->p)
+ return -1;
+ ++t;
+ }
+ return 0;
+}
+
+/* Type Conversion Functions */
+
+static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
+ int is_true = x == Py_True;
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
+ else return PyObject_IsTrue(x);
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
+ PyNumberMethods *m;
+ const char *name = NULL;
+ PyObject *res = NULL;
+#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(x) || PyLong_Check(x))
+#else
+ if (PyLong_Check(x))
+#endif
+ return Py_INCREF(x), x;
+ m = Py_TYPE(x)->tp_as_number;
+#if PY_VERSION_HEX < 0x03000000
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Int(x);
+ }
+ else if (m && m->nb_long) {
+ name = "long";
+ res = PyNumber_Long(x);
+ }
+#else
+ if (m && m->nb_int) {
+ name = "int";
+ res = PyNumber_Long(x);
+ }
+#endif
+ if (res) {
+#if PY_VERSION_HEX < 0x03000000
+ if (!PyInt_Check(res) && !PyLong_Check(res)) {
+#else
+ if (!PyLong_Check(res)) {
+#endif
+ PyErr_Format(PyExc_TypeError,
+ "__%s__ returned non-%s (type %.200s)",
+ name, name, Py_TYPE(res)->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "an integer is required");
+ }
+ return res;
+}
+
+static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
+ Py_ssize_t ival;
+ PyObject* x = PyNumber_Index(b);
+ if (!x) return -1;
+ ival = PyInt_AsSsize_t(x);
+ Py_DECREF(x);
+ return ival;
+}
+
+static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
+#if PY_VERSION_HEX < 0x02050000
+ if (ival <= LONG_MAX)
+ return PyInt_FromLong((long)ival);
+ else {
+ unsigned char *bytes = (unsigned char *) &ival;
+ int one = 1; int little = (int)*(unsigned char*)&one;
+ return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
+ }
+#else
+ return PyInt_FromSize_t(ival);
+#endif
+}
+
+static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
+ unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
+ if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
+ return (size_t)-1;
+ } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
+ PyErr_SetString(PyExc_OverflowError,
+ "value too large to convert to size_t");
+ return (size_t)-1;
+ }
+ return (size_t)val;
+}
+
+
+#endif /* Py_PYTHON_H */
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx
new file mode 100644
index 00000000..45320c46
--- /dev/null
+++ b/python/src/_cdec.pyx
@@ -0,0 +1,180 @@
+from libcpp.string cimport string
+from libcpp.vector cimport vector
+from cython.operator cimport dereference as deref
+from utils cimport *
+cimport hypergraph
+cimport decoder
+cimport lattice
+cimport kbest as kb
+
+SetSilent(True)
+
+class ParseFailed(Exception):
+ pass
+
+cdef class Weights:
+ cdef vector[weight_t]* weights
+
+ def __cinit__(self, Decoder decoder):
+ self.weights = &decoder.dec.CurrentWeightVector()
+
+ def __getitem__(self, char* fname):
+ cdef unsigned fid = FDConvert(fname)
+ if fid <= self.weights.size():
+ return self.weights[0][fid]
+ raise KeyError(fname)
+
+ def __setitem__(self, char* fname, float value):
+ cdef unsigned fid = FDConvert(<char *>fname)
+ if self.weights.size() <= fid:
+ self.weights.resize(fid + 1)
+ self.weights[0][fid] = value
+
+ def __iter__(self):
+ cdef unsigned fid
+ for fid in range(1, self.weights.size()):
+ yield FDConvert(fid).c_str(), self.weights[0][fid]
+
+cdef class Decoder:
+ cdef decoder.Decoder* dec
+ cdef public Weights weights
+
+ def __cinit__(self, char* config):
+ decoder.register_feature_functions()
+ cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs)
+ #cdef ReadFile* config_file = new ReadFile(string(config))
+ #cdef istream* config_stream = config_file.stream()
+ self.dec = new decoder.Decoder(config_stream)
+ del config_stream
+ #del config_file
+ self.weights = Weights(self)
+
+ def __dealloc__(self):
+ del self.dec
+
+ @classmethod
+ def fromconfig(cls, ini):
+ cdef dict config = {}
+ with open(ini) as fp:
+ for line in fp:
+ line = line.strip()
+ if not line or line.startswith('#'): continue
+ param, value = line.split('=')
+ config[param.strip()] = value.strip()
+ return cls(**config)
+
+ def read_weights(self, cfg):
+ with open(cfg) as fp:
+ for line in fp:
+ fname, value = line.split()
+ self.weights[fname.strip()] = float(value)
+
+ # TODO: list, lattice translation
+ def translate(self, unicode sentence, grammar=None):
+ if grammar:
+ self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
+ #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
+ sgml = sentence.strip().encode('utf8')
+ cdef decoder.BasicObserver observer = decoder.BasicObserver()
+ self.dec.Decode(string(<char *>sgml), &observer)
+ if observer.hypergraph == NULL:
+ raise ParseFailed()
+ cdef Hypergraph hg = Hypergraph()
+ hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
+ return hg
+
+cdef class Hypergraph:
+ cdef hypergraph.Hypergraph* hg
+ cdef MT19937* rng
+
+ def __dealloc__(self):
+ del self.hg
+ if self.rng != NULL:
+ del self.rng
+
+ def viterbi(self):
+ assert (self.hg != NULL)
+ cdef vector[WordID] trans
+ hypergraph.ViterbiESentence(self.hg[0], &trans)
+ cdef str sentence = GetString(trans).c_str()
+ return sentence.decode('utf8')
+
+ def viterbi_tree(self):
+ assert (self.hg != NULL)
+ cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ return tree.decode('utf8')
+
+ def kbest(self, size):
+ assert (self.hg != NULL)
+ cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ cdef str tree
+ cdef unsigned k
+ for k in range(size):
+ derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ if not derivation: break
+ tree = GetString(derivation._yield).c_str()
+ yield tree.decode('utf8')
+ del derivations
+
+ def kbest_tree(self, size):
+ assert (self.hg != NULL)
+ cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ cdef str sentence
+ cdef unsigned k
+ for k in range(size):
+ derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ if not derivation: break
+ sentence = GetString(derivation._yield).c_str()
+ yield sentence.decode('utf8')
+ del derivations
+
+ def intersect(self, Lattice lat):
+ assert (self.hg != NULL)
+ hypergraph.Intersect(lat.lattice[0], self.hg)
+
+ def sample(self, unsigned n):
+ assert (self.hg != NULL)
+ cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ if self.rng == NULL:
+ self.rng = new MT19937()
+ hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ cdef str sentence
+ cdef unsigned k
+ for k in range(hypos.size()):
+ sentence = GetString(hypos[0][k].words).c_str()
+ yield sentence.decode('utf8')
+ del hypos
+
+ # TODO: get feature expectations, get partition function ("inside" score)
+ # TODO: reweight the forest with different weights (Hypergraph::Reweight)
+ # TODO: inside-outside pruning
+
+cdef class Lattice:
+ cdef lattice.Lattice* lattice
+
+ def __init__(self, tuple plf_tuple):
+ self.lattice = new lattice.Lattice()
+ cdef bytes plf = str(plf_tuple)
+ hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+
+ def __str__(self):
+ return hypergraph.AsPLF(self.lattice[0]).c_str()
+
+ def __iter__(self):
+ return iter(eval(str(self)))
+
+ def __dealloc__(self):
+ del self.lattice
+
+# TODO: wrap SparseVector
+
+"""
+def params_str(params):
+ return '\n'.join('%s=%s' % (param, value) for param, value in params.iteritems())
+
+cdef istringstream* ConfigStream(dict params):
+ ini = params_str(params)
+ return new istringstream(<char *> ini)
+"""
diff --git a/python/src/decoder.pxd b/python/src/decoder.pxd
new file mode 100644
index 00000000..ab858841
--- /dev/null
+++ b/python/src/decoder.pxd
@@ -0,0 +1,37 @@
+from libcpp.string cimport string
+from libcpp.vector cimport vector
+from hypergraph cimport Hypergraph
+from utils cimport istream, weight_t
+
+cdef extern from "decoder/ff_register.h":
+ cdef void register_feature_functions()
+
+cdef extern from "decoder/decoder.h":
+ cdef cppclass SentenceMetadata:
+ pass
+
+ cdef cppclass DecoderObserver:
+ DecoderObserver()
+
+ cdef cppclass Decoder:
+ Decoder(int argc, char** argv)
+ Decoder(istream* config_file)
+ bint Decode(string input, DecoderObserver* observer)
+
+ # access this to either *read* or *write* to the decoder's last
+ # weight vector (i.e., the weights of the finest past)
+ vector[weight_t]& CurrentWeightVector()
+
+ void SetId(int id)
+ #const boost::program_options::variables_map& GetConf() const { return conf }
+
+ # add grammar rules (currently only supported by SCFG decoders)
+ # that will be used on subsequent calls to Decode. rules should be in standard
+ # text format. This function does NOT read from a file.
+ void SetSupplementalGrammar(string grammar)
+ void SetSentenceGrammarFromString(string grammar_str)
+
+cdef extern from "observer.h":
+ cdef cppclass BasicObserver(DecoderObserver):
+ Hypergraph* hypergraph
+ BasicObserver()
diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd
new file mode 100644
index 00000000..4aef6955
--- /dev/null
+++ b/python/src/hypergraph.pxd
@@ -0,0 +1,41 @@
+from libcpp.string cimport string
+from libcpp.vector cimport vector
+from utils cimport *
+cimport lattice
+
+cdef extern from "decoder/hg.h":
+ cdef cppclass Hypergraph:
+ cppclass Node:
+ int id_
+ WordID cat_
+ WordID NT()
+ #EdgesVector in_edges_
+ #EdgesVector out_edges_
+ Hypergraph(Hypergraph)
+ vector[Node] nodes_
+
+cdef extern from "decoder/viterbi.h":
+ cdef prob_t ViterbiESentence(Hypergraph hg, vector[WordID]* trans)
+ cdef string ViterbiETree(Hypergraph hg)
+
+cdef extern from "decoder/hg_io.h" namespace "HypergraphIO":
+ bint ReadFromJSON(istream* inp, Hypergraph* out)
+ bint WriteToJSON(Hypergraph hg, bint remove_rules, ostream* out)
+
+ #void WriteAsCFG(Hypergraph hg)
+ #void WriteTarget(string base, unsigned sent_id, Hypergraph hg)
+
+ void ReadFromPLF(string inp, Hypergraph* out, int line=*)
+ string AsPLF(Hypergraph hg, bint include_global_parentheses=*)
+ string AsPLF(lattice.Lattice lat, bint include_global_parentheses=*)
+ void PLFtoLattice(string plf, lattice.Lattice* pl)
+
+cdef extern from "decoder/hg_intersect.h" namespace "HG":
+ bint Intersect(lattice.Lattice target, Hypergraph* hg)
+
+cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler":
+ cdef cppclass Hypothesis:
+ vector[WordID] words
+ SparseVector[double] fmap
+ prob_t model_score
+ void sample_hypotheses(Hypergraph hg, unsigned n, MT19937* rng, vector[Hypothesis]* hypos)
diff --git a/python/src/kbest.pxd b/python/src/kbest.pxd
new file mode 100644
index 00000000..e339714a
--- /dev/null
+++ b/python/src/kbest.pxd
@@ -0,0 +1,16 @@
+from libcpp.vector cimport vector
+from utils cimport WordID
+cimport hypergraph
+
+cdef extern from "decoder/viterbi.h":
+ cdef cppclass ESentenceTraversal:
+ pass
+ cdef cppclass ETreeTraversal:
+ pass
+
+cdef extern from "decoder/kbest.h" namespace "KBest":
+ cdef cppclass KBestDerivations[T, Traversal]:
+ cppclass Derivation:
+ T _yield "yield"
+ KBestDerivations(hypergraph.Hypergraph hg, unsigned k)
+ Derivation* LazyKthBest(unsigned v, unsigned k)
diff --git a/python/src/lattice.pxd b/python/src/lattice.pxd
new file mode 100644
index 00000000..bdfaba80
--- /dev/null
+++ b/python/src/lattice.pxd
@@ -0,0 +1,16 @@
+from libcpp.vector cimport vector
+from utils cimport WordID
+
+cdef extern from "decoder/lattice.h":
+ cdef cppclass LatticeArc:
+ WordID label
+ double cost
+ int dist2next
+ LatticeArc()
+ LatticeArc(WordID w, double c, int i)
+
+ cdef cppclass Lattice: # (vector[vector[LatticeArc]])
+ Lattice()
+ Lattice(unsigned t)
+ Lattice(unsigned t, vector[LatticeArc] v)
+ bint IsSentence()
diff --git a/python/src/observer.h b/python/src/observer.h
new file mode 100644
index 00000000..d398f2f7
--- /dev/null
+++ b/python/src/observer.h
@@ -0,0 +1,22 @@
+#include "decoder/hg.h"
+#include "decoder/decoder.h"
+#include <iostream>
+
+struct BasicObserver: public DecoderObserver {
+ Hypergraph* hypergraph;
+ BasicObserver() : hypergraph(NULL) {}
+ ~BasicObserver() {
+ if(hypergraph != NULL) delete hypergraph;
+ }
+ void NotifyDecodingStart(const SentenceMetadata& smeta) {}
+ void NotifySourceParseFailure(const SentenceMetadata& smeta) {}
+ void NotifyTranslationForest(const SentenceMetadata& smeta, Hypergraph* hg) {
+ if(hypergraph != NULL) delete hypergraph;
+ hypergraph = new Hypergraph(*hg);
+ }
+ void NotifyAlignmentFailure(const SentenceMetadata& semta) {
+ if(hypergraph != NULL) delete hypergraph;
+ }
+ void NotifyAlignmentForest(const SentenceMetadata& smeta, Hypergraph* hg) {}
+ void NotifyDecodingComplete(const SentenceMetadata& smeta) {}
+};
diff --git a/python/src/utils.pxd b/python/src/utils.pxd
new file mode 100644
index 00000000..786cd265
--- /dev/null
+++ b/python/src/utils.pxd
@@ -0,0 +1,53 @@
+from libcpp.string cimport string
+from libcpp.vector cimport vector
+
+cdef extern from "<iostream>" namespace "std":
+ cdef cppclass istream:
+ pass
+ cdef cppclass ostream:
+ pass
+ cdef cppclass istringstream(istream):
+ istringstream(char*)
+
+cdef extern from "utils/weights.h":
+ ctypedef double weight_t
+
+cdef extern from "utils/logval.h":
+ cdef cppclass LogVal[T]:
+ pass
+
+cdef extern from "utils/prob.h":
+ cdef cppclass prob_t:
+ pass
+
+cdef extern from "utils/wordid.h":
+ ctypedef int WordID
+
+cdef extern from "utils/sparse_vector.h":
+ cdef cppclass SparseVector[T]:
+ pass
+
+cdef extern from "utils/tdict.cc" namespace "TD":
+ cdef string GetString(vector[WordID] st)
+
+cdef extern from "utils/verbose.h":
+ cdef void SetSilent(bint)
+
+cdef extern from "utils/fdict.h" namespace "FD":
+ WordID FDConvert "FD::Convert" (char*)
+ string& FDConvert "FD::Convert" (WordID)
+
+cdef extern from "utils/filelib.h":
+ cdef cppclass ReadFile:
+ ReadFile(string)
+ istream* stream()
+
+cdef extern from "utils/sampler.h":
+ cdef cppclass MT19937:
+ pass
+
+"""
+cdef extern from "<boost/shared_ptr.hpp>" namespace "boost":
+ cdef cppclass shared_ptr[T]:
+ void reset(T*)
+"""
diff --git a/python/test.py b/python/test.py
new file mode 100644
index 00000000..1542dd4f
--- /dev/null
+++ b/python/test.py
@@ -0,0 +1,49 @@
+#coding: utf8
+import cdec
+import gzip
+
+config = 'formalism=scfg'
+weights = '../tests/system_tests/australia/weights'
+grammar_file = '../tests/system_tests/australia/australia.scfg.gz'
+
+# Load decoder width configuration
+decoder = cdec.Decoder(config)
+# Read weights
+decoder.read_weights(weights)
+
+print dict(decoder.weights)
+
+# Read grammar
+with gzip.open(grammar_file) as f:
+ grammar = f.read()
+
+# Input sentence
+sentence = u'澳洲 是 与 北韩 有 邦交 的 少数 国家 之一 。'
+print 'Input:', sentence
+
+# Decode
+forest = decoder.translate(sentence, grammar=grammar)
+
+# Get viterbi translation
+print 'Output[0]:', forest.viterbi().encode('utf8')
+print ' Tree[0]:', forest.viterbi_tree().encode('utf8')
+
+# Get k-best translations
+for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1):
+ print 'Output[%d]:' % i, sentence.encode('utf8')
+ print ' Tree[%d]:' % i, tree.encode('utf8')
+
+# Sample translations from the forest
+for sentence in forest.sample(5):
+ print 'Sample:', sentence.encode('utf8')
+
+# Reference lattice
+lattice = ((('australia',0,1),),(('is',0,1),),(('one',0,1),),(('of',0,1),),(('the',0,4),('a',0,4),('a',0,1),('the',0,1),),(('small',0,1),('tiny',0,1),('miniscule',0,1),('handful',0,2),),(('number',0,1),('group',0,1),),(('of',0,2),),(('few',0,1),),(('countries',0,1),),(('that',0,1),),(('has',0,1),('have',0,1),),(('diplomatic',0,1),),(('relations',0,1),),(('with',0,1),),(('north',0,1),),(('korea',0,1),),(('.',0,1),),)
+
+lat = cdec.Lattice(lattice)
+assert (lattice == tuple(lat))
+
+# Intersect forest and lattice
+forest.intersect(lat)
+# Get best synchronous parse
+print forest.viterbi_tree()