16

I'm starting to program with NLTK in Python for Natural Italian Language processing. I've seen some simple examples of the WordNet Library that has a nice set of SynSet that permits you to navigate from a word (for example: "dog") to his synonyms and his antonyms, his hyponyms and hypernyms and so on...

My question is: If I start with an italian word (for example:"cane" - that means "dog") is there a way to navigate between synonyms, antonyms, hyponyms... for the italian word as you do for the english one? Or... There is an Equivalent to WordNet for the Italian Language ?

Thanks in advance

2 Answers 2

23

You are in luck. The nltk provides an interface to the Open Multilingual Wordnet, which does indeed include Italian among the languages it describes. Just add an argument specifying the desired language to the usual wordnet functions, e.g.:

>>> cane_lemmas = wn.lemmas("cane", lang="ita")
>>> print(cane_lemmas)
[Lemma('dog.n.01.cane'), Lemma('cramp.n.02.cane'), Lemma('hammer.n.01.cane'),
 Lemma('bad_person.n.01.cane'), Lemma('incompetent.n.01.cane')]

The synsets have English names, because they are integrated with the English wordnet. But you can navigate the web of meanings and extract the Italian lemmas for any synset you want:

>>> hypernyms = cane_lemmas[0].synset().hypernyms()
>>> print(hypernyms)
[Synset('canine.n.02'), Synset('domestic_animal.n.01')]
>>> print(hypernyms[1].lemmas(lang="ita"))
[Lemma('domestic_animal.n.01.animale_addomesticato'), 
 Lemma('domestic_animal.n.01.animale_domestico')]

Or since you mentioned "cattiva_persona" in the comments:

>>> wn.lemmas("bad_person")[0].synset().lemmas(lang="ita")
[Lemma('bad_person.n.01.cane'), Lemma('bad_person.n.01.cattivo')]

I went from the English lemma to the language-independent synset to the Italian lemmas.

12
  • Yes, thanks for the advice but as you can see, it doesn't give me the italian Synonyms but it seems that with "wn.lemmas("cane",lang="ita")" just translate the italian word in english and returns what it found. To be more explicit: I'm expecting that instead of Lemma('bad_berson') it should get back Lemma('cattiva_persona') that is the italian meaning of bad_person.
    – Frank B.
    Commented May 11, 2017 at 14:32
  • I don't speak Italian, but Wordnet is saying that one of the meanings of "cane" is "bad person". Wordnet is built on English, so the meanings have English names but multilingual lemmas. Think of the English side as variable names -- it doesn't matter what they are, what matters is the data they contain. I'll add an example of getting hypernyms.
    – alexis
    Commented May 11, 2017 at 20:10
  • @FrankB.I am working on a similar task, were you able to find a solution ? Commented Mar 16, 2021 at 9:43
  • @tahsintahsin study the answer (edited since Frank's question), it's all explained there. This is the solution.
    – alexis
    Commented Mar 16, 2021 at 12:37
  • 1
    @LamLe don't bother with the original OMW distribution, use the version that the nltk bundles. You'll find it in the interactive nltk.download() dialog, for example. Or just use nltk.download("omw") to download it. You only need to do this once, don't put it in your scripts!
    – alexis
    Commented Apr 21, 2023 at 10:46
9

Since I found myself wondering how to actually use the wordnet resources after reading this question and its answer, I'm going to leave here some useful information:

Here is a link to the nltk guide.

The two necessary commands to download wordnet data and thus proceed with the usage explained in the other answer are:

import nltk

nltk.download('wordnet')
nltk.download('omw')
1
  • I got a LookupError saying "Resource omw-1.4 not found." and suggesting to run nltk.download('omw-1.4'), after this it worked
    – sound wave
    Commented Feb 7, 2023 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.