Commit dcd225fa by Steven Bird

fixed some import statements, added test code

parent daf4d0f7
...@@ -209,11 +209,11 @@ def postag( ...@@ -209,11 +209,11 @@ def postag(
# defaults # defaults
baseline_backoff_tagger = baseline_backoff_tagger or REGEXP_TAGGER baseline_backoff_tagger = baseline_backoff_tagger or REGEXP_TAGGER
if templates is None: if templates is None:
from nltk.tag.tbl.task import postagging from nltk.tag.brill import describe_template_sets, brill24
# some pre-built template sets taken from typical systems or publications are # some pre-built template sets taken from typical systems or publications are
# available. Print a list with postagging.describe_template_sets() # available. Print a list with describe_template_sets()
# for instance: # for instance:
templates = postagging.brill24() templates = brill24()
(training_data, baseline_data, gold_data, testing_data) = \ (training_data, baseline_data, gold_data, testing_data) = \
_demo_prepare_data(tagged_data, train, num_sents, randomize, separate_baseline_data) _demo_prepare_data(tagged_data, train, num_sents, randomize, separate_baseline_data)
......
...@@ -60,7 +60,7 @@ class Feature(object): ...@@ -60,7 +60,7 @@ class Feature(object):
>>> Pos(2, 1) >>> Pos(2, 1)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <module>
File "nltk/tag/tbl/template.py", line 306, in __init__ File "nltk/tbl/template.py", line 306, in __init__
raise TypeError raise TypeError
ValueError: illegal interval specification: (start=2, end=1) ValueError: illegal interval specification: (start=2, end=1)
...@@ -258,3 +258,8 @@ class Feature(object): ...@@ -258,3 +258,8 @@ class Feature(object):
:rtype: any (but usually scalar) :rtype: any (but usually scalar)
""" """
raise NotImplementedError raise NotImplementedError
if __name__ == "__main__":
import doctest
doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
...@@ -307,3 +307,8 @@ class Rule(TagRule): ...@@ -307,3 +307,8 @@ class Rule(TagRule):
conditions = (' if ' if self._conditions else "") + ', and '.join( conditions = (' if ' if self._conditions else "") + ', and '.join(
[condition_to_str(f,v) for (f,v) in self._conditions]) [condition_to_str(f,v) for (f,v) in self._conditions])
return replacement + conditions return replacement + conditions
if __name__ == "__main__":
import doctest
doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
...@@ -306,3 +306,6 @@ class Template(BrillTemplateI): ...@@ -306,3 +306,6 @@ class Template(BrillTemplateI):
if __name__ == "__main__":
import doctest
doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment