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
036ec1a4
Commit
036ec1a4
authored
May 18, 2014
by
Steven Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed unit test bugs for wsd
parent
520148f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
nltk/test/wsd.doctest
+4
-6
nltk/wsd.py
+3
-3
No files found.
nltk/test/wsd.doctest
View file @
036ec1a4
...
...
@@ -17,22 +17,20 @@ a the definitions of the ambiguous word.
Given an ambiguous word and the context in which the word occurs, Lesk returns
a Synset with the highest number of overlapping words between the context
sentence and different definitions f
or
m each Synset.
sentence and different definitions f
ro
m each Synset.
>>> from nltk.wsd import lesk
>>> from nltk.wsd import lesk
>>> sent = "I went to the bank to deposit money."
>>> word = "bank"
>>> pos = "n"
>>> print
lesk(sent, word, pos
)
>>> print
(lesk(sent, word, pos)
)
Synset('depository_financial_institution.n.01')
The definitions for "bank" are:
>>> from nltk.corpus import wordnet as wn
>>> for ss in wn.synsets('bank'):
... print ss, ss.definition()
...
... print(ss, ss.definition())
Synset('bank.n.01') sloping land (especially the slope beside a body of water)
Synset('depository_financial_institution.n.01') a financial institution that accepts deposits and channels the money into lending activities
Synset('bank.n.03') a long ridge or pile
...
...
nltk/wsd.py
View file @
036ec1a4
...
...
@@ -43,11 +43,11 @@ def lesk(context_sentence, ambiguous_word, pos=None, dictionary=None):
>>> sent = word_tokenize("I went to the bank to deposit money.")
>>> word = "bank"
>>> pos = "n"
>>>
wsd
(sent, word, pos)
>>>
lesk
(sent, word, pos)
Synset('depository_financial_institution.n.01')
:param context_sentence: The context sentence where the ambiguous word occurs.
:param ambiguous: The ambiguous word that requires WSD.
:param ambiguous
_word
: The ambiguous word that requires WSD.
:param pos: A specified Part-of-Speech (POS).
:param dictionary: A list of words that 'signifies' the ambiguous word.
:return: ``lesk_sense`` The Synset() object with the highest signature overlaps.
...
...
@@ -56,7 +56,7 @@ def lesk(context_sentence, ambiguous_word, pos=None, dictionary=None):
dictionary
=
{}
for
ss
in
wn
.
synsets
(
ambiguous_word
):
dictionary
[
ss
]
=
ss
.
definition
()
.
split
()
best_sense
=
_compare_overlaps_greedy
(
context_sentence
,
\
best_sense
=
_compare_overlaps_greedy
(
context_sentence
,
dictionary
,
pos
)
return
best_sense
...
...
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