Giter Club home page Giter Club logo

Comments (5)

chlor avatar chlor commented on June 26, 2024

I 've tested it with Italian, French an Spanish and found no examples.

from wn.

fcbond avatar fcbond commented on June 26, 2024

from wn.

chlor avatar chlor commented on June 26, 2024

Thanks for the quick reply, how can I read antonyms from OWN networks? The code fragments I mentioned are not sufficient.

from wn.

fcbond avatar fcbond commented on June 26, 2024

Hi,

Not optimized at all, but this should work.  It gets the antonym relations from English and then looks them up in Japanese.

import wn
en = wn.Wordnet('omw-en:1.4')
ja = wn.Wordnet('omw-ja:1.4')

### a set of tuples of ili ids of antonyms,
### sorted internally (so we only get one way: id1 < id2)
antonyms = set()

### store ilis for antonym pairs
for synset in en.synsets():
    ### check synsets (there aren't any)
    if syn_anto := synset.get_related('antonym'):
        print(synset, syn_anto)
    ### check senses
    for sense in synset.senses():
        if sen_anto := sense.get_related('antonym'):
            for anto in sen_anto:
                antonyms.add(tuple(sorted([sense.synset().ili.id,
                                           anto.synset().ili.id])))
### print for Japanese
for (a1, a2) in antonyms:
    s1 = ja.synsets(ili=a1)
    s2 = ja.synsets(ili=a2)
    print(s1,s2)

from wn.

chlor avatar chlor commented on June 26, 2024

Thanks, it works!
Here is my extension to get antoynms:


import wn
en = wn.Wordnet('omw-en:1.4')
ja = wn.Wordnet('omw-ja:1.4')

### a set of tuples of ili ids of antonyms,
### sorted internally (so we only get one way: id1 < id2)
antonyms = set()
antonyms_txt = set()

### store ilis for antonym pairs
for synset in en.synsets():
    if syn_anto := synset.get_related('antonym'):
        print(synset, syn_anto)
    for sense in synset.senses():
        if sen_anto := sense.get_related('antonym'):
            for anto in sen_anto:
                antonyms.add(tuple(sorted([sense.synset().ili.id, anto.synset().ili.id])))

dict_ant = {}

for (a1, a2) in antonyms:
    s1 = ja.synsets(ili=a1)
    s2 = ja.synsets(ili=a2)
    for s in s1:
        for lem in s.lemmas():
            got_ants = [s.lemmas() for s in s2]
            if got_ants:
                dict_ant[lem] = got_ants

for d in dict_ant:
    print(d, *itertools.chain.from_iterable(dict_ant[d]))

print(len(dict_ant))

from wn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.