nltk.HunposTagger

class nltk.HunposTagger(path_to_model, path_to_bin=None, encoding='ISO-8859-1', verbose=False)[source]
A class for pos tagging with HunPos. The input is the paths to:
  • a model trained on training data
  • (optionally) the path to the hunpos-tag binary
  • (optionally) the encoding of the training data (default: ISO-8859-1)

Example:

>>> from nltk.tag import HunposTagger
>>> ht = HunposTagger('en_wsj.model')
>>> ht.tag('What is the airspeed of an unladen swallow ?'.split())
[('What', 'WP'), ('is', 'VBZ'), ('the', 'DT'), ('airspeed', 'NN'), ('of', 'IN'), ('an', 'DT'), ('unladen', 'NN'), ('swallow', 'VB'), ('?', '.')]
>>> ht.close()

This class communicates with the hunpos-tag binary via pipes. When the tagger object is no longer needed, the close() method should be called to free system resources. The class supports the context manager interface; if used in a with statement, the close() method is invoked automatically:

>>> with HunposTagger('en_wsj.model') as ht:
...     ht.tag('What is the airspeed of an unladen swallow ?'.split())
...
[('What', 'WP'), ('is', 'VBZ'), ('the', 'DT'), ('airspeed', 'NN'), ('of', 'IN'), ('an', 'DT'), ('unladen', 'NN'), ('swallow', 'VB'), ('?', '.')]

Methods

__init__(path_to_model[, path_to_bin, ...]) Starts the hunpos-tag executable and establishes a connection with it.
close() Closes the pipe to the hunpos executable.
evaluate(gold) Score the accuracy of the tagger against the gold standard.
tag(tokens) Tags a single sentence: a list of words.
tag_sents(sentences) Apply self.tag() to each element of sentences.