From bba0a5e078ac0372becb082b3256440d9cf4ab2b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 18 Jan 2016 22:37:24 +0100 Subject: [PATCH] * Handle string paths in default_vocab, default_parser, default_entity in Language class --- spacy/language.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index 8efcc618e..454d11126 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -140,19 +140,32 @@ class Language(object): def default_vocab(cls, package, get_lex_attr=None): if get_lex_attr is None: get_lex_attr = cls.default_lex_attrs() - return Vocab.from_package(package, get_lex_attr=get_lex_attr) + if hasattr(package, 'dir_path'): + return Vocab.from_package(package, get_lex_attr=get_lex_attr) + else: + return Vocab.load(package, get_lex_attr) @classmethod def default_parser(cls, package, vocab): - data_dir = package.dir_path('deps') + if hasattr(package, 'dir_path'): + data_dir = package.dir_path('deps') + else: + data_dir = package if data_dir and path.exists(data_dir): return Parser.from_dir(data_dir, vocab.strings, ArcEager) + else: + return None @classmethod def default_entity(cls, package, vocab): - data_dir = package.dir_path('ner') + if hasattr(package, 'dir_path'): + data_dir = package.dir_path('ner') + else: + data_dir = package if data_dir and path.exists(data_dir): return Parser.from_dir(data_dir, vocab.strings, BiluoPushDown) + else: + return None def __init__(self, data_dir=None,