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
commit8c77c634836e56c7b9b3400afeac21277f168238 (patch)
tree197b6b015988979f15b18e74a237f69c48f0d0db /python/cdec/grammar.pxi
parentcb85bfbe908f6001a92b0af99ea03f369416059e (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):