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
90682aee
Commit
90682aee
authored
Jun 19, 2008
by
Steven Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
svn/trunk@6032
parent
9cfd0689
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
+63
-0
papers/acl-08/grammar1.py
+22
-0
papers/acl-08/grammar2.py
+22
-0
papers/acl-08/police.py
+19
-0
No files found.
papers/acl-08/grammar1.py
0 → 100644
View file @
90682aee
import
nltk
def
parse
(
sent
,
grammar
):
gr
=
nltk
.
cfg
.
parse_cfg
(
grammar
)
parser
=
nltk
.
ChartParser
(
gr
,
nltk
.
parse
.
TD_STRATEGY
)
trees
=
parser
.
nbest_parse
(
sent
.
split
())
nltk
.
draw
.
draw_trees
(
*
trees
)
grammar
=
"""
S -> NP VP
VP -> V NP | VP PP
NP -> Det N | NP PP
PP -> P NP
NP -> 'I'
Det -> 'the' | 'a' | 'my'
N -> 'elephant' | 'pajamas' | 'man' | 'park' | 'telescope'
V -> 'shot' | 'saw'
P -> 'in' | 'on' | 'with'
"""
sent
=
'I shot the elephant in my pajamas'
parse
(
sent
,
grammar
)
papers/acl-08/grammar2.py
0 → 100644
View file @
90682aee
import
nltk
def
parse
(
sent
,
grammar
):
gr
=
nltk
.
cfg
.
parse_cfg
(
grammar
)
parser
=
nltk
.
ChartParser
(
gr
,
nltk
.
parse
.
TD_STRATEGY
)
trees
=
parser
.
nbest_parse
(
sent
.
split
())
nltk
.
draw
.
draw_trees
(
*
trees
)
grammar
=
"""
S -> NP VP
VP -> V NP | VP PP
NP -> Det N | NP PP
PP -> P NP
NP -> 'I'
Det -> 'the' | 'a' | 'my'
N -> 'elephant' | 'pajamas' | 'man' | 'park' | 'telescope'
V -> 'shot' | 'saw'
P -> 'in' | 'on' | 'with'
"""
sent
=
'I saw the man in the park with a telescope'
parse
(
sent
,
grammar
)
papers/acl-08/police.py
0 → 100644
View file @
90682aee
import
nltk
def
parse
(
sent
,
grammar
):
gr
=
nltk
.
cfg
.
parse_cfg
(
grammar
)
parser
=
nltk
.
ChartParser
(
gr
,
nltk
.
parse
.
TD_STRATEGY
)
trees
=
parser
.
nbest_parse
(
sent
.
split
())
nltk
.
draw
.
draw_trees
(
*
trees
)
grammar
=
"""
S -> NP V NP
NP -> NP Sbar
Sbar -> NP V
NP -> 'fish' | 'police'
V -> 'fish' | 'police'
"""
sent
=
'police police police police police police police police police'
parse
(
sent
,
grammar
)
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