summaryrefslogtreecommitdiff
path: root/python/cdec/grammar.pxi
diff options
context:
space:
mode:
authorChris Dyer <cdyer@allegro.clab.cs.cmu.edu>2014-04-07 01:30:17 -0400
committerChris Dyer <cdyer@allegro.clab.cs.cmu.edu>2014-04-07 01:30:17 -0400
commit6051462ad3f161ab129b5a2fb3a9cacd35201a3b (patch)
tree77d013198e3ecebb9a9882f04c45a2c34ac26df6 /python/cdec/grammar.pxi
parente32e9fdd48ef6466fbb257d92e250816f5b69114 (diff)
new version of cythonized code
Diffstat (limited to 'python/cdec/grammar.pxi')
-rw-r--r--python/cdec/grammar.pxi18
1 files changed, 12 insertions, 6 deletions
diff --git a/python/cdec/grammar.pxi b/python/cdec/grammar.pxi
index d523e4d2..b78c86ff 100644
--- a/python/cdec/grammar.pxi
+++ b/python/cdec/grammar.pxi
@@ -49,7 +49,7 @@ cdef TRule convert_rule(_sa.Rule rule):
cdef class TRule:
cdef shared_ptr[grammar.TRule]* rule
- def __init__(self, lhs, f, e, scores, a=None):
+ def __init__(self, lhs, f, e, scores, a=None, text=None):
"""TRule(lhs, f, e, scores, a=None) -> Translation rule.
lhs: left hand side non-terminal
f: source phrase (list of words/NT)
@@ -57,12 +57,18 @@ cdef class TRule:
scores: dictionary of feature scores
a: optional list of alignment points"""
self.rule = new shared_ptr[grammar.TRule](new grammar.TRule())
- self.lhs = lhs
- self.e = e
- self.f = f
- self.scores = scores
+ if lhs:
+ self.lhs = lhs
+ if e:
+ self.e = e
+ if f:
+ self.f = f
+ if scores:
+ self.scores = scores
if a:
- self.a = a
+ self.a = a
+ if text:
+ self.rule.get().ReadFromString(text, 0)
self.rule.get().ComputeArity()
def __dealloc__(self):