summaryrefslogtreecommitdiff
path: root/python/cdec/sa/extractor.py
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-27 22:25:15 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-27 22:25:15 -0400
commit9961abf8f756279ac6d839e0b3de2b0d83431965 (patch)
tree2defad3f49df2921ff68a48a07a9ca0693a1f0f7 /python/cdec/sa/extractor.py
parent733e1b1507d27d4f53055f740e8098f56215ab8f (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/extractor.py')
-rw-r--r--python/cdec/sa/extractor.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/python/cdec/sa/extractor.py b/python/cdec/sa/extractor.py
index c97b3c6f..bb912e16 100644
--- a/python/cdec/sa/extractor.py
+++ b/python/cdec/sa/extractor.py
@@ -1,4 +1,6 @@
from itertools import chain
+import os
+import cdec.configobj
from cdec.sa.features import EgivenFCoherent, SampleCountF, CountEF,\
MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE
import cdec.sa
@@ -8,7 +10,10 @@ MAX_INITIAL_SIZE = 15
class GrammarExtractor:
def __init__(self, config):
- # TODO if str, read config
+ if isinstance(config, str) or isinstance(config, unicode):
+ if not os.path.exists(config):
+ raise IOError('cannot read configuration from {0}'.format(config))
+ config = cdec.configobj.ConfigObj(config, unrepr=True)
alignment = cdec.sa.Alignment(from_binary=config['a_file'])
self.factory = cdec.sa.HieroCachingRuleFactory(
# compiled alignment object (REQUIRED)