Skip to content

Commit 582e6e3

Browse files
authored
Merge pull request nltk#3148 from TiMauzi/wsd/languages
added the option to change the wordnet's language
2 parents 13bf2bd + a107a51 commit 582e6e3

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
- M.K. Pawelkiewicz <https://github.com/hamiltonianflow>
297297
- Steven Thomas Smith <https://github.com/essandess>
298298
- Jan Lennartz <https://github.com/Madnex>
299+
- Tim Sockel <https://github.com/TiMauzi>
299300

300301
## Others whose work we've taken and included in NLTK, but who didn't directly contribute it:
301302

nltk/wsd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
from nltk.corpus import wordnet
1111

1212

13-
def lesk(context_sentence, ambiguous_word, pos=None, synsets=None):
13+
def lesk(context_sentence, ambiguous_word, pos=None, synsets=None, lang="eng"):
1414
"""Return a synset for an ambiguous word in a context.
1515
1616
:param iter context_sentence: The context sentence where the ambiguous word
1717
occurs, passed as an iterable of words.
1818
:param str ambiguous_word: The ambiguous word that requires WSD.
1919
:param str pos: A specified Part-of-Speech (POS).
2020
:param iter synsets: Possible synsets of the ambiguous word.
21+
:param str lang: WordNet language.
2122
:return: ``lesk_sense`` The Synset() object with the highest signature overlaps.
2223
2324
This function is an implementation of the original Lesk algorithm (1986) [1].
@@ -36,7 +37,7 @@ def lesk(context_sentence, ambiguous_word, pos=None, synsets=None):
3637

3738
context = set(context_sentence)
3839
if synsets is None:
39-
synsets = wordnet.synsets(ambiguous_word)
40+
synsets = wordnet.synsets(ambiguous_word, lang=lang)
4041

4142
if pos:
4243
synsets = [ss for ss in synsets if str(ss.pos()) == pos]

0 commit comments

Comments
 (0)