Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nltk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
nltk
Commits
d7429569
Commit
d7429569
authored
Apr 18, 2014
by
Steven Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more code reorganisation
parent
c313c8e6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
21 additions
and
30 deletions
+21
-30
nltk/__init__.py
+2
-8
nltk/tag/brill.py
+2
-2
nltk/tbl/__init__.py
+1
-5
nltk/tbl/_run_doctests.py
+2
-2
nltk/tbl/api.py
+1
-0
nltk/tbl/demo.py
+1
-1
nltk/tbl/feature.py
+4
-4
nltk/tbl/rule.py
+8
-8
No files found.
nltk/__init__.py
View file @
d7429569
...
...
@@ -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
,
t
bl
,
t
ext
,
tokenize
,
tree
,
treetransforms
,
util
# override any accidentally imported demo
def
demo
():
...
...
nltk/tag/brill.py
View file @
d7429569
...
...
@@ -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 ``
Brill
Rule``
These transformation rules are specified by the ``
Tag
Rule``
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(
Brill
Rule)
:type rules: list(
Tag
Rule)
:param training_stats: A dictionary of statistics collected
during training, for possible later use
...
...
nltk/tbl/__init__.py
View file @
d7429569
...
...
@@ -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
...
...
nltk/tbl/_run_doctests.py
View file @
d7429569
...
...
@@ -10,8 +10,8 @@ import glob, sys, subprocess, os.path
from
os.path
import
abspath
currdir
=
os
.
getcwd
()
if
not
currdir
.
endswith
(
"nltk/t
ag/t
bl"
):
raise
RuntimeError
(
"run me in /<PATH/TO/NLTK>/nltk/t
ag/t
bl/"
)
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
...
...
nltk/tbl/api.py
0 → 100644
View file @
d7429569
nltk/tbl/demo.py
View file @
d7429569
...
...
@@ -18,7 +18,7 @@ import time
from
nltk.corpus
import
treebank
from
nltk.tbl
import
error_list
,
Template
from
nltk.t
bl.task.postagging
import
Word
,
Pos
from
nltk.t
ag.brill
import
Word
,
Pos
from
nltk.tag
import
BrillTaggerTrainer
,
RegexpTagger
,
UnigramTagger
def
demo
():
...
...
nltk/tbl/feature.py
View file @
d7429569
...
...
@@ -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.t
bl.task.postagging
import Word, Pos
>>> from nltk.t
ag.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.t
bl.task.postagging
import Word
>>> from nltk.t
ag.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.t
bl.task.postagging
import Word, Pos
>>> from nltk.t
ag.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.t
bl.task.postagging
import Word, Pos
>>> from nltk.t
ag.brill
import Word, Pos
>>> Word([-3,-2,-1]).intersects(Word([-3,-2]))
True
...
...
nltk/tbl/rule.py
View file @
d7429569
...
...
@@ -14,11 +14,11 @@ from nltk.compat import python_2_unicode_compatible, unicode_repr
from
nltk
import
jsontags
######################################################################
##
Brill
Rules
##
Tag
Rules
######################################################################
class
Brill
Rule
(
object
):
class
Tag
Rule
(
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
Brill
Rule may cause to be replaced."""
"""The tag which this
Tag
Rule may cause to be replaced."""
self
.
replacement_tag
=
replacement_tag
"""The tag with which this
Brill
Rule may replace another tag."""
"""The tag with which this
Tag
Rule 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
(
Brill
Rule
):
class
Rule
(
Tag
Rule
):
"""
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}.
"""
Brill
Rule
.
__init__
(
self
,
original_tag
,
replacement_tag
)
Tag
Rule
.
__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
Brill
Rule
# Inherit docs from
Tag
Rule
# Does the given token have this Rule's "original tag"?
if
tokens
[
index
][
1
]
!=
self
.
original_tag
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment