Commit d7429569 by Steven Bird

more code reorganisation

parent c313c8e6
......@@ -111,12 +111,6 @@ from nltk.util import *
from nltk.jsontags import *
from nltk.align import *
# don't import contents into top-level namespace:
from nltk import ccg
from nltk import data
from nltk import help
###########################################################
# PACKAGES
###########################################################
......@@ -170,9 +164,9 @@ else:
# from a subpackage)
from nltk import align, ccg, chunk, classify, collocations
from nltk import data, featstruct, grammar, inference, metrics
from nltk import data, featstruct, grammar, help, inference, metrics
from nltk import misc, parse, probability, sem, stem
from nltk import tag, text, tokenize, tree, treetransforms, util
from nltk import tag, tbl, text, tokenize, tree, treetransforms, util
# override any accidentally imported demo
def demo():
......
......@@ -192,7 +192,7 @@ class BrillTagger(TaggerI):
initial tagger (such as ``tag.DefaultTagger``) to assign an initial
tag sequence to a text; and then apply an ordered list of
transformational rules to correct the tags of individual tokens.
These transformation rules are specified by the ``BrillRule``
These transformation rules are specified by the ``TagRule``
interface.
Brill taggers can be created directly, from an initial tagger and
......@@ -210,7 +210,7 @@ class BrillTagger(TaggerI):
:param rules: An ordered list of transformation rules that
should be used to correct the initial tagging.
:type rules: list(BrillRule)
:type rules: list(TagRule)
:param training_stats: A dictionary of statistics collected
during training, for possible later use
......
......@@ -15,14 +15,10 @@ A general purpose package for Transformation Based Learning,
currently used by nltk.tag.BrillTagger.
"""
#here goes imports which are re-exported for convenient top-level import
#(as nltk.tag.tbl.*)
from nltk.tbl.template import Template
#API: Template(...), Template.expand(...)
from nltk.tbl.task.api import Feature
from nltk.tbl.feature import Feature
#API: Feature(...), Feature.expand(...)
from nltk.tbl.rule import Rule
......
......@@ -10,8 +10,8 @@ import glob, sys, subprocess, os.path
from os.path import abspath
currdir = os.getcwd()
if not currdir.endswith("nltk/tag/tbl"):
raise RuntimeError("run me in /<PATH/TO/NLTK>/nltk/tag/tbl/")
if not currdir.endswith("nltk/tbl"):
raise RuntimeError("run me in /<PATH/TO/NLTK>/nltk/tbl/")
sys.path.insert(0, "../../..")
#a list of all the python files in this dir and two levels of subdirs
......
......@@ -18,7 +18,7 @@ import time
from nltk.corpus import treebank
from nltk.tbl import error_list, Template
from nltk.tbl.task.postagging import Word, Pos
from nltk.tag.brill import Word, Pos
from nltk.tag import BrillTaggerTrainer, RegexpTagger, UnigramTagger
def demo():
......
......@@ -41,7 +41,7 @@ class Feature(object):
Construct a Feature which may apply at C{positions}.
#For instance, importing some concrete subclasses (Feature is abstract)
>>> from nltk.tbl.task.postagging import Word, Pos
>>> from nltk.tag.brill import Word, Pos
#Feature Word, applying at one of [-2, -1]
>>> Word([-2,-1])
......@@ -114,7 +114,7 @@ class Feature(object):
target feature at [0])
#For instance, importing a concrete subclass (Feature is abstract)
>>> from nltk.tbl.task.postagging import Word
>>> from nltk.tag.brill import Word
#First argument gives the possible start positions, second the
#possible window lengths
......@@ -168,7 +168,7 @@ class Feature(object):
other positions in addition).
#For instance, importing a concrete subclass (Feature is abstract)
>>> from nltk.tbl.task.postagging import Word, Pos
>>> from nltk.tag.brill import Word, Pos
>>> Word([-3,-2,-1]).issuperset(Word([-3,-2]))
True
......@@ -198,7 +198,7 @@ class Feature(object):
and there is some overlap in the positions they look at.
#For instance, importing a concrete subclass (Feature is abstract)
>>> from nltk.tbl.task.postagging import Word, Pos
>>> from nltk.tag.brill import Word, Pos
>>> Word([-3,-2,-1]).intersects(Word([-3,-2]))
True
......
......@@ -14,11 +14,11 @@ from nltk.compat import python_2_unicode_compatible, unicode_repr
from nltk import jsontags
######################################################################
## Brill Rules
## Tag Rules
######################################################################
class BrillRule(object):
class TagRule(object):
"""
An interface for tag transformations on a tagged corpus, as
performed by tbl taggers. Each transformation finds all tokens
......@@ -29,16 +29,16 @@ class BrillRule(object):
depend on the token under consideration, as well as any other
tokens in the corpus.
Brill rules must be comparable and hashable.
Tag rules must be comparable and hashable.
"""
def __init__(self, original_tag, replacement_tag):
self.original_tag = original_tag
"""The tag which this BrillRule may cause to be replaced."""
"""The tag which this TagRule may cause to be replaced."""
self.replacement_tag = replacement_tag
"""The tag with which this BrillRule may replace another tag."""
"""The tag with which this TagRule may replace another tag."""
def apply(self, tokens, positions=None):
"""
......@@ -96,7 +96,7 @@ class BrillRule(object):
@python_2_unicode_compatible
@jsontags.register_tag
class Rule(BrillRule):
class Rule(TagRule):
"""
A Rule checks the current corpus position for a certain set of conditions;
if they are all fulfilled, the Rule is triggered, meaning that it
......@@ -134,7 +134,7 @@ class Rule(BrillRule):
token in M{n} + p in positions is C{value}.
"""
BrillRule.__init__(self, original_tag, replacement_tag)
TagRule.__init__(self, original_tag, replacement_tag)
self._conditions = conditions
self.templateid = templateid
......@@ -151,7 +151,7 @@ class Rule(BrillRule):
return cls(obj['templateid'], obj['original'], obj['replacement'], obj['conditions'])
def applies(self, tokens, index):
# Inherit docs from BrillRule
# Inherit docs from TagRule
# Does the given token have this Rule's "original tag"?
if tokens[index][1] != self.original_tag:
......
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