nltk.parse.bllip module¶
- class nltk.parse.bllip.BllipParser[source]¶
Bases:
ParserI
Interface for parsing with BLLIP Parser. BllipParser objects can be constructed with the
BllipParser.from_unified_model_dir
class method or manually using theBllipParser
constructor.- __init__(parser_model=None, reranker_features=None, reranker_weights=None, parser_options=None, reranker_options=None)[source]¶
Load a BLLIP Parser model from scratch. You’ll typically want to use the
from_unified_model_dir()
class method to construct this object.- Parameters
parser_model (str) – Path to parser model directory
reranker_features (str) – Path the reranker model’s features file
reranker_weights (str) – Path the reranker model’s weights file
parser_options (dict(str)) – optional dictionary of parser options, see
bllipparser.RerankingParser.RerankingParser.load_parser_options()
for more information.reranker_options (dict(str)) – optional dictionary of reranker options, see
bllipparser.RerankingParser.RerankingParser.load_reranker_model()
for more information.
- classmethod from_unified_model_dir(model_dir, parser_options=None, reranker_options=None)[source]¶
Create a
BllipParser
object from a unified parsing model directory. Unified parsing model directories are a standardized way of storing BLLIP parser and reranker models together on disk. Seebllipparser.RerankingParser.get_unified_model_parameters()
for more information about unified model directories.- Returns
A
BllipParser
object using the parser and reranker models in the model directory.- Parameters
model_dir (str) – Path to the unified model directory.
parser_options (dict(str)) – optional dictionary of parser options, see
bllipparser.RerankingParser.RerankingParser.load_parser_options()
for more information.reranker_options (dict(str)) – optional dictionary of reranker options, see
bllipparser.RerankingParser.RerankingParser.load_reranker_model()
for more information.
- Return type
- parse(sentence)[source]¶
Use BLLIP Parser to parse a sentence. Takes a sentence as a list of words; it will be automatically tagged with this BLLIP Parser instance’s tagger.
- Returns
An iterator that generates parse trees for the sentence from most likely to least likely.
- Parameters
sentence (list(str)) – The sentence to be parsed
- Return type
iter(Tree)
- tagged_parse(word_and_tag_pairs)[source]¶
Use BLLIP to parse a sentence. Takes a sentence as a list of (word, tag) tuples; the sentence must have already been tokenized and tagged. BLLIP will attempt to use the tags provided but may use others if it can’t come up with a complete parse subject to those constraints. You may also specify a tag as
None
to leave a token’s tag unconstrained.- Returns
An iterator that generates parse trees for the sentence from most likely to least likely.
- Parameters
sentence (list(tuple(str, str))) – Input sentence to parse as (word, tag) pairs
- Return type
iter(Tree)