def load_parser_model(self, model_dir, **parser_options): """Load the parsing model from model_dir and set parsing options. In general, the default options should suffice but see the set_parser_options() method for details. Note that the parser does not allow loading multiple models within the same process (calling this function twice will raise a RuntimeError).""" if self._parser_model_loaded: raise RuntimeError('Parser is already loaded and can only be loaded once.') if not exists(model_dir): raise ValueError('Parser model directory %r does not exist.' % model_dir) self._parser_model_loaded = True self.parser_model_dir = model_dir parser.loadModel(model_dir) self.set_parser_options(**parser_options)
def load_parsing_model(self, model_dir, language='En', case_insensitive=False, nbest=50, small_corpus=True, overparsing=21, debug=0, smoothPos=0): """Load the parsing model from model_dir and set parsing options. In general, the default options should suffice. Note that the parser does not allow loading multiple models within the same process.""" if self._parser_model_loaded: raise ValueError('Parser is already loaded and can only be loaded once.') if not os.path.exists(model_dir): raise ValueError('Parser model directory %r does not exist.' % model_dir) self._parser_model_loaded = True parser.loadModel(model_dir) self.parser_model_dir = model_dir parser.setOptions(language, case_insensitive, nbest, small_corpus, overparsing, debug, smoothPos)
def load_parser_model(self, model_dir, terms_only=False, heads_only=False, **parser_options): """Load the parsing model from model_dir and set parsing options. In general, the default options should suffice but see the set_parser_options() method for details. Note that the parser does not allow loading multiple models within the same process (calling this function twice will raise a RuntimeError). If terms_only is True, we will not load the full parsing model, just part of speech tag information (intended for tools which only call things like Tree.evaluate()). If heads_only is True, we will only load head finding information (for things like Tree.dependencies(). If both are set to True, both of these will be loaded but the full parsing model will not.""" if RerankingParser._parser_model_loaded: raise RuntimeError('Parser is already loaded and can only ' 'be loaded once.') try: model_dir = str(model_dir) except UnicodeEncodeError: raise ValueError('Parser model directory %r must be an ASCII ' 'string.' % model_dir) if not exists(model_dir): raise ValueError('Parser model directory %r does not exist.' % model_dir) if not (terms_only or heads_only): RerankingParser._parser_model_loaded = True RerankingParser._parser_heads_loaded = True RerankingParser._parser_terms_loaded = True self.parser_model_dir = model_dir parser.loadModel(model_dir) self.set_parser_options(**parser_options) else: if terms_only: RerankingParser._parser_terms_loaded = True parser.loadTermsOnly(model_dir) if heads_only: RerankingParser._parser_heads_loaded = True parser.loadHeadInfoOnly(model_dir)
def load_parsing_model(self, model_dir, language='En', case_insensitive=False, nbest=50, small_corpus=True, overparsing=21, debug=0, smoothPos=0): """Load the parsing model from model_dir and set parsing options. In general, the default options should suffice. Note that the parser does not allow loading multiple models within the same process.""" if self._parser_model_loaded: raise ValueError( 'Parser is already loaded and can only be loaded once.') if not os.path.exists(model_dir): raise ValueError('Parser model directory %r does not exist.' % model_dir) self._parser_model_loaded = True parser.loadModel(model_dir) self.parser_model_dir = model_dir parser.setOptions(language, case_insensitive, nbest, small_corpus, overparsing, debug, smoothPos)