class documentation

A class for dependency parsing with MaltParser. The input is the paths to: - a maltparser directory - (optionally) the path to a pre-trained MaltParser .mco model file - (optionally) the tagger to use for POS tagging before parsing - (optionally) additional Java arguments

Example:
>>> from nltk.parse import malt
>>> # With MALT_PARSER and MALT_MODEL environment set.
>>> mp = malt.MaltParser('maltparser-1.7.2', 'engmalt.linear-1.7.mco') # doctest: +SKIP
>>> mp.parse_one('I shot an elephant in my pajamas .'.split()).tree() # doctest: +SKIP
(shot I (elephant an) (in (pajamas my)) .)
>>> # Without MALT_PARSER and MALT_MODEL environment.
>>> mp = malt.MaltParser('/home/user/maltparser-1.7.2/', '/home/user/engmalt.linear-1.7.mco') # doctest: +SKIP
>>> mp.parse_one('I shot an elephant in my pajamas .'.split()).tree() # doctest: +SKIP
(shot I (elephant an) (in (pajamas my)) .)
Method __init__ An interface for parsing with the Malt Parser.
Method generate_malt_command This function generates the maltparser command use at the terminal.
Method parse_sents Use MaltParser to parse multiple sentences. Takes a list of sentences, where each sentence is a list of words. Each sentence will be automatically tagged with this MaltParser instance's tagger.
Method parse_tagged_sents Use MaltParser to parse multiple POS tagged sentences. Takes multiple sentences where each sentence is a list of (word, tag) tuples. The sentences must have already been tokenized and tagged.
Method train Train MaltParser from a list of DependencyGraph objects
Method train_from_file Train MaltParser from a file :param conll_file: str for the filename of the training input data :type conll_file: str
Instance Variable additional_java_args Undocumented
Instance Variable malt_jars Undocumented
Instance Variable model Undocumented
Instance Variable tagger Undocumented
Instance Variable working_dir Undocumented
Static Method _execute Undocumented
Instance Variable _trained Undocumented

Inherited from ParserI:

Method grammar No summary
Method parse When possible this list is sorted from most likely to least likely.
Method parse_all No summary
Method parse_one No summary
def __init__(self, parser_dirname, model_filename=None, tagger=None, additional_java_args=None): (source)

An interface for parsing with the Malt Parser.

contains the maltparser-1.x.jar :type parser_dirname: str :param model_filename: The name of the pre-trained model with .mco file extension. If provided, training will not be required. (see http://www.maltparser.org/mco/mco.html and see http://www.patful.com/chalk/node/185) :type model_filename: str :param tagger: The tagger used to POS tag the raw string before formatting to CONLL format. It should behave like nltk.pos_tag :type tagger: function :param additional_java_args: This is the additional Java arguments that one can use when calling Maltparser, usually this is the heapsize limits, e.g. additional_java_args=['-Xmx1024m'] (see http://goo.gl/mpDBvQ) :type additional_java_args: list

Parameters
parser_dirnameThe path to the maltparser directory that
model_filenameUndocumented
taggerUndocumented
additional_java_argsUndocumented
def generate_malt_command(self, inputfilename, outputfilename=None, mode=None): (source)

This function generates the maltparser command use at the terminal.

Parameters
inputfilename:strpath to the input file
outputfilename:strpath to the output file
modeUndocumented
def parse_sents(self, sentences, verbose=False, top_relation_label='null'): (source)

Use MaltParser to parse multiple sentences. Takes a list of sentences, where each sentence is a list of words. Each sentence will be automatically tagged with this MaltParser instance's tagger.

Parameters
sentencesInput sentences to parse
verboseUndocumented
top_relation_labelUndocumented
sentence:list(list(str))Undocumented
Returns
iter(DependencyGraph)
def parse_tagged_sents(self, sentences, verbose=False, top_relation_label='null'): (source)

Use MaltParser to parse multiple POS tagged sentences. Takes multiple sentences where each sentence is a list of (word, tag) tuples. The sentences must have already been tokenized and tagged.

representation of each sentence

Parameters
sentencesInput sentences to parse
verboseUndocumented
top_relation_labelUndocumented
sentence:list(list(tuple(str, str)))Undocumented
Returns
iter(iter(DependencyGraph)) the dependency graph
def train(self, depgraphs, verbose=False): (source)

Train MaltParser from a list of DependencyGraph objects

Parameters
depgraphs:DependencyGraphlist of DependencyGraph objects for training input data
verboseUndocumented
def train_from_file(self, conll_file, verbose=False): (source)

Train MaltParser from a file :param conll_file: str for the filename of the training input data :type conll_file: str

additional_java_args = (source)

Undocumented

malt_jars = (source)

Undocumented

Undocumented

Undocumented

working_dir = (source)

Undocumented

@staticmethod
def _execute(cmd, verbose=False): (source)

Undocumented

_trained: bool = (source)

Undocumented