diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-27 22:25:15 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-27 22:25:15 -0400 |
commit | 9961abf8f756279ac6d839e0b3de2b0d83431965 (patch) | |
tree | 2defad3f49df2921ff68a48a07a9ca0693a1f0f7 /python/cdec/sa/features.py | |
parent | 733e1b1507d27d4f53055f740e8098f56215ab8f (diff) |
[python] conversion from cdec.sa.Rule to cdec.TRule
+ remove configobj dependency
+ re-structure packages (no more top-level library)
+ "const" stuff
+ use __new__ instead of constructor for some objects
Diffstat (limited to 'python/cdec/sa/features.py')
-rw-r--r-- | python/cdec/sa/features.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/python/cdec/sa/features.py b/python/cdec/sa/features.py index 8d35d8e6..325b9e13 100644 --- a/python/cdec/sa/features.py +++ b/python/cdec/sa/features.py @@ -1,6 +1,5 @@ from __future__ import division import math -import cdec.sa MAXSCORE = 99 @@ -22,11 +21,10 @@ def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): def MaxLexEgivenF(ttable): def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = [cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)] + fwords = fphrase.words fwords.append('NULL') - ewords = (cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)) def score(): - for e in ewords: + for e in ephrase.words: maxScore = max(ttable.get_score(f, e, 0) for f in fwords) yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE return sum(score()) @@ -34,11 +32,10 @@ def MaxLexEgivenF(ttable): def MaxLexFgivenE(ttable): def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = (cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)) - ewords = [cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)] + ewords = ephrase.words ewords.append('NULL') def score(): - for f in fwords: + for f in fphrase.words: maxScore = max(ttable.get_score(f, e, 1) for e in ewords) yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE return sum(score()) |