diff options
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) |