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 | 1d481414a2fa8505a2591c88e2b7b8f86a682ca2 (patch) | |
tree | ed5e9dff569d89da453578ce3d109991623d9303 /python/cdec/sa/extractor.py | |
parent | b317e0efd2398d75d70e027bb1e2cf442e683981 (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.py | 7 |
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) |