summaryrefslogtreecommitdiff
path: root/python/cdec/sa/features.py
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2014-02-24 23:18:47 -0800
committerMichael Denkowski <mdenkows@cs.cmu.edu>2014-02-24 23:18:47 -0800
commit6b0afcb161141cdb64e249adfb3708682febc089 (patch)
tree40c27903869fcd7bb7f2ff0230719b0cc9734593 /python/cdec/sa/features.py
parentd843587027d815f3a1c9b8dd5394f3fe04ac85fa (diff)
CountExceptLM and CountExceptLex features for online grammar extraction.
Diffstat (limited to 'python/cdec/sa/features.py')
-rw-r--r--python/cdec/sa/features.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/python/cdec/sa/features.py b/python/cdec/sa/features.py
index c8fc1cca..fe3fb2bd 100644
--- a/python/cdec/sa/features.py
+++ b/python/cdec/sa/features.py
@@ -140,3 +140,19 @@ def IsSupportedOnline(ctx): # Occurs in online data?
return (ctx.online.paircount > 0.01)
else:
return False
+
+def CountExceptLM(vocab):
+ def CountExceptLM(ctx): # In bitext (inc online data) but NOT mono text
+ return sum(1 for e in ctx.ephrase.words if e not in vocab)
+ return CountExceptLM
+
+def CountExceptLex(ttable):
+ def CountExceptLex(ctx):
+ count = 0.0
+ for e in ctx.ephrase.words:
+ if not ttable.contains_e_word(e):
+ count += 1
+ return count
+ return CountExceptLex
+
+