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
f091002d
Commit
f091002d
authored
Nov 29, 2011
by
Steven Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed demo tests
parent
46eea71f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
18 deletions
+11
-18
nltk/__init__.py
+0
-1
nltk/collocations.py
+4
-4
nltk/grammar.py
+0
-8
nltk/parse/sr.py
+5
-5
nltk/probability.py
+2
-0
No files found.
nltk/__init__.py
View file @
f091002d
...
@@ -100,7 +100,6 @@ from collocations import *
...
@@ -100,7 +100,6 @@ from collocations import *
from
decorators
import
decorator
,
memoize
from
decorators
import
decorator
,
memoize
from
featstruct
import
*
from
featstruct
import
*
from
grammar
import
*
from
grammar
import
*
from
olac
import
*
from
probability
import
*
from
probability
import
*
from
text
import
*
from
text
import
*
from
tree
import
*
from
tree
import
*
...
...
nltk/collocations.py
View file @
f091002d
...
@@ -236,14 +236,14 @@ def demo(scorer=None, compare_scorer=None):
...
@@ -236,14 +236,14 @@ def demo(scorer=None, compare_scorer=None):
if
compare_scorer
is
None
:
if
compare_scorer
is
None
:
compare_scorer
=
BigramAssocMeasures
.
raw_freq
compare_scorer
=
BigramAssocMeasures
.
raw_freq
from
nltk
import
corpus
from
nltk
.corpus
import
stopwords
,
webtext
ignored_words
=
corpus
.
stopwords
.
words
(
'english'
)
ignored_words
=
stopwords
.
words
(
'english'
)
word_filter
=
lambda
w
:
len
(
w
)
<
3
or
w
.
lower
()
in
ignored_words
word_filter
=
lambda
w
:
len
(
w
)
<
3
or
w
.
lower
()
in
ignored_words
for
file
in
corpus
.
webtext
.
file
s
():
for
file
in
webtext
.
fileid
s
():
words
=
[
word
.
lower
()
words
=
[
word
.
lower
()
for
word
in
corpus
.
webtext
.
words
(
file
)]
for
word
in
webtext
.
words
(
file
)]
cf
=
BigramCollocationFinder
.
from_words
(
words
)
cf
=
BigramCollocationFinder
.
from_words
(
words
)
cf
.
apply_freq_filter
(
3
)
cf
.
apply_freq_filter
(
3
)
...
...
nltk/grammar.py
View file @
f091002d
...
@@ -1323,10 +1323,6 @@ def cfg_demo():
...
@@ -1323,10 +1323,6 @@ def cfg_demo():
print
`grammar.productions()`
.
replace
(
','
,
',
\n
'
+
' '
*
25
)
print
`grammar.productions()`
.
replace
(
','
,
',
\n
'
+
' '
*
25
)
print
print
print
'Coverage of input words by a grammar:'
print
grammar
.
covers
([
'a'
,
'dog'
])
print
grammar
.
covers
([
'a'
,
'toy'
])
toy_pcfg1
=
parse_pcfg
(
"""
toy_pcfg1
=
parse_pcfg
(
"""
S -> NP VP [1.0]
S -> NP VP [1.0]
NP -> Det N [0.5] | NP PP [0.25] | 'John' [0.1] | 'I' [0.15]
NP -> Det N [0.5] | NP PP [0.25] | 'John' [0.1] | 'I' [0.15]
...
@@ -1391,10 +1387,6 @@ def pcfg_demo():
...
@@ -1391,10 +1387,6 @@ def pcfg_demo():
print
`grammar.productions()`
.
replace
(
','
,
',
\n
'
+
' '
*
26
)
print
`grammar.productions()`
.
replace
(
','
,
',
\n
'
+
' '
*
26
)
print
print
print
'Coverage of input words by a grammar:'
print
grammar
.
covers
([
'a'
,
'boy'
])
print
grammar
.
covers
([
'a'
,
'girl'
])
# extract productions from three trees and induce the PCFG
# extract productions from three trees and induce the PCFG
print
"Induce PCFG grammar from treebank data:"
print
"Induce PCFG grammar from treebank data:"
...
...
nltk/parse/sr.py
View file @
f091002d
...
@@ -217,14 +217,14 @@ class ShiftReduceParser(ParserI):
...
@@ -217,14 +217,14 @@ class ShiftReduceParser(ParserI):
stack. This is used with trace level 2 to print 'S'
stack. This is used with trace level 2 to print 'S'
before shifted stacks and 'R' before reduced stacks.
before shifted stacks and 'R' before reduced stacks.
"""
"""
s
tr
=
' '
+
marker
+
' [ '
s
=
' '
+
marker
+
' [ '
for
elt
in
stack
:
for
elt
in
stack
:
if
isinstance
(
elt
,
Tree
):
if
isinstance
(
elt
,
Tree
):
s
tr
+=
`Nonterminal(elt.node)`
+
' '
s
+=
`Nonterminal(elt.node)`
+
' '
else
:
else
:
s
tr
+=
`elt`
+
' '
s
+=
`elt`
+
' '
s
tr
+=
'* '
+
string
.
join
(
remaining_text
)
+
']'
s
+=
'* '
+
' '
.
join
(
remaining_text
)
+
']'
print
s
tr
print
s
def
_trace_shift
(
self
,
stack
,
remaining_text
):
def
_trace_shift
(
self
,
stack
,
remaining_text
):
"""
"""
...
...
nltk/probability.py
View file @
f091002d
...
@@ -280,6 +280,8 @@ class FreqDist(dict):
...
@@ -280,6 +280,8 @@ class FreqDist(dict):
:rtype: any or None
:rtype: any or None
"""
"""
if
self
.
_max_cache
is
None
:
if
self
.
_max_cache
is
None
:
if
len
(
self
)
==
0
:
raise
ValueError
(
'A FreqDist must have at least one sample before max is defined.'
)
self
.
_max_cache
=
max
([(
a
,
b
)
for
(
b
,
a
)
in
self
.
items
()])[
1
]
self
.
_max_cache
=
max
([(
a
,
b
)
for
(
b
,
a
)
in
self
.
items
()])[
1
]
return
self
.
_max_cache
return
self
.
_max_cache
...
...
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