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
cf7dabbd
Commit
cf7dabbd
authored
Feb 15, 2015
by
Long Thanh Duong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add example of
toy_pcfg1 and toy_pcfg2
parent
edf5e138
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
6 deletions
+3
-6
nltk/parse/pchart.py
+3
-6
No files found.
nltk/parse/pchart.py
View file @
cf7dabbd
...
...
@@ -212,7 +212,7 @@ class BottomUpProbabilisticChartParser(ParserI):
# Initialize the chart.
for
edge
in
bu_init
.
apply
(
chart
,
grammar
):
if
self
.
_trace
>
1
:
print
(
'
%-50
s [
%
s]'
%
(
chart
.
p
p
_edge
(
edge
,
width
=
2
),
print
(
'
%-50
s [
%
s]'
%
(
chart
.
p
retty_format
_edge
(
edge
,
width
=
2
),
edge
.
prob
()))
queue
.
append
(
edge
)
...
...
@@ -227,7 +227,7 @@ class BottomUpProbabilisticChartParser(ParserI):
# Get the best edge.
edge
=
queue
.
pop
()
if
self
.
_trace
>
0
:
print
(
'
%-50
s [
%
s]'
%
(
chart
.
p
p
_edge
(
edge
,
width
=
2
),
print
(
'
%-50
s [
%
s]'
%
(
chart
.
p
retty_format
_edge
(
edge
,
width
=
2
),
edge
.
prob
()))
# Apply BU & FR to it.
...
...
@@ -294,7 +294,7 @@ class BottomUpProbabilisticChartParser(ParserI):
split
=
len
(
queue
)
-
self
.
beam_size
if
self
.
_trace
>
2
:
for
edge
in
queue
[:
split
]:
print
(
'
%-50
s [DISCARDED]'
%
chart
.
p
p
_edge
(
edge
,
2
))
print
(
'
%-50
s [DISCARDED]'
%
chart
.
p
retty_format
_edge
(
edge
,
2
))
del
queue
[:
split
]
class
InsideChartParser
(
BottomUpProbabilisticChartParser
):
...
...
@@ -401,7 +401,6 @@ def demo(choice=None, draw_parses=None, print_parses=None):
from
nltk.parse
import
pchart
# Define two demos. Each demo has a sentence and a grammar.
toy_pcfg1
=
PCFG
.
fromstring
(
"""
S -> NP VP [1.0]
NP -> Det N [0.5] | NP PP [0.25] | 'John' [0.1] | 'I' [0.15]
...
...
@@ -439,8 +438,6 @@ def demo(choice=None, draw_parses=None, print_parses=None):
Det -> 'my' [.28]
"""
)
demos
=
[(
'I saw John with my telescope'
,
toy_pcfg1
),
(
'the boy saw Jack with Bob under the table with a telescope'
,
toy_pcfg2
)]
...
...
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