Giter Club home page Giter Club logo

Comments (5)

fcbond avatar fcbond commented on July 24, 2024 1

from wn.

goodmami avatar goodmami commented on July 24, 2024

This is odd. I suspect the Sense.synset() method is not creating a synset object in the same way as via the Wordnet.synsets() method, and then the hypernym_paths() method attempts to expand through all installed wordnets. If so, then it should be an easy fix.

edit: here's a shorter MWE:

import wn
en = wn.Wordnet('omw-en:1.4')
en.sense('omw-en-beast-00015388-n').synset().hypernym_paths()

from wn.

goodmami avatar goodmami commented on July 24, 2024

Looks like my guess was correct. Here is Sense.synset():

wn/wn/_core.py

Lines 896 to 905 in a832a63

def synset(self) -> Synset:
"""Return the synset of the sense.
Example:
>>> wn.senses('spigot')[0].synset()
Synset('pwn-03325088-n')
"""
return synset(id=self._synset_id)

Note that it calls the module function wn.synset(), without any limits on the lexicons. The resulting, unconstrained synset will then use any installed lexicon to look for expanded relations on subsequent operations. It would be better to construct a Synset like how Wordnet.synset() does:

wn/wn/_core.py

Lines 1156 to 1162 in a832a63

def synset(self, id: str) -> Synset:
"""Return the first synset in this wordnet with identifier *id*."""
iterable = find_synsets(id=id, lexicon_rowids=self._lexicon_ids)
try:
return Synset(*next(iterable), self)
except StopIteration:
raise wn.Error(f'no such synset: {id}')

But the lexicon_rowids constraint on the call to find_synsets would need to be filled out. If a Wordnet object was used to get the sense, it would just be self._wordnet._lexicon_ids, but not if the query was done in "default mode" (which I thought was documented, but now I don't see it in the docs; see #92 (comment)). Luckily there's a non-public convenience method for this:

wn/wn/_core.py

Lines 266 to 274 in a832a63

def _get_lexicon_ids(self) -> Tuple[int, ...]:
if self._wordnet._default_mode:
return tuple(
{self._lexid}
| set(get_lexicon_extension_bases(self._lexid))
| set(get_lexicon_extensions(self._lexid))
)
else:
return self._wordnet._lexicon_ids

Secondly, the wordnet object of the sense (accessible via the _wordnet attribute) needs to be passed in the Synset constructor instead of just self.

Finally, it looks like Sense.word() has the same issue.

I'm going to assign this to you, @fcbond. If that's ok, please submit a PR and I'll look it over. If not, I can do it.

from wn.

goodmami avatar goodmami commented on July 24, 2024

@fcbond just checking in. Do you think you can do this, or shall I?

from wn.

goodmami avatar goodmami commented on July 24, 2024

The synset issue was apparently resolved in #170. Sense.word() still has the same problem, though.

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.