-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get sense/synset relation metadata #216
Comments
We could also change the key type in the returned dictionary from class Relation(str):
def __new__(cls, name: str, type: Optional[str] = None) -> Relation:
obj = cls(name)
obj.type = type
def __str__(self) -> str:
return self.name
def __repr__(self) -> str:
return f"{self.name}({self.type})" if self.type else self.name
def __hash__(self) -> int:
return hash(repr(self)) |
There are issues with the above solution because the base class isn't just Here is an alternative:
I still need to think a bit about how this would work with interlingual searches, subsequent queries, and comparisons (e.g., is a |
Further refining the above... It probably makes more sense to just put the additional attributes and methods on the |
Senses and Synsets now have an `incoming_relation()` method. The value of this method returns a SenseRelation, SenseSynsetRelation, or SynsetRelation object if the Sense/Synset is the result of a relation traversal. Otherwise the method returns `None`. The new relation objects specify the relation name, the source and target IDs of the relation, and the lexicon where the relation originated. Fixes #216 Fixes #167
Ok here's what I have working. @fcbond and @jmccrae, do you agree with the proposed API? Senses and Synsets now have a >>> import wn
>>> oewn = wn.Wordnet('oewn:2024')
>>> dog = oewn.synsets('dog')[0]
>>> dog.incoming_relation() # None; no relation was traversed
>>> dog.hypernyms()[0].incoming_relation()
SynsetRelation('hypernym', 'oewn-02086723-n', 'oewn-02085998-n')
>>> dog.hypernyms()[0].incoming_relation().lexicon()
<Lexicon oewn:2024 [en]>
>>> dog.hypernyms()[0].incoming_relation().metadata()
{}
>>> oewn.senses('ally', pos="v")[0].get_related("other")[0].incoming_relation().metadata()
{'type': 'agent'} This also works with interlingual traversals. Even though the source and target are in one lexicon, the lexicon of the relation may be different. For instance: >>> es = wn.Wordnet('omw-es') # depends on omw-en by default
>>> perro = es.synsets("perro")[0] # Spanish for 'dog'
>>> perro.hypernyms()[0] # hypernym is a Spanish omw-es synset
Synset('omw-es-02083346-n')
>>> perro.hypernyms()[0].words()
[Word('omw-es-cánido-n')]
>>> perro.hypernyms()[0].incoming_relation() # relation traverses English omw-en synsets
SynsetRelation('hypernym', 'omw-en-02084071-n', 'omw-en-02083346-n')
>>> perro.hypernyms()[0].incoming_relation().lexicon()
<Lexicon omw-en:1.4 [en]> |
I am not sure that I like that a synset returns a different result for Wouldn't it be easier just to add a new method, like |
@jmccrae thanks for the feedback.
That bothered me, too, even though two synsets or senses that differed only by the traversal (if any) to arrive at them would still compare equal.
That would be ok, but I wanted something that integrated with the normal ways of traversing relations. In the proposed implementation above, all the existing relation methods ( Another alternative is a method like |
My preference is still for a different traversal method, it seems much simple, but perhaps @fcbond has another opinion? |
I can think of three reasons for getting the relation objects that aren't solved by the existing API:
(1) and (2) are easily solved with a method like If we don't want to make Sense and Synset objects more stateful than the already are, here's an alternative that expands on the Synset.relation_map() -> dict[SynsetRelation, Synset]: ... |
Hi,
I think I like this approach better. But I am not sure what happens when,
e.g., you have two hypernyms. In this case the SynsetRelation has the
same RelationType, but some other property (an internal ID) that
distinguishes them from each other? Will we make this ID accessible?
Presumably then you can get the metadata from the SynsetRelation key?
I hope the question makes sense, ...
…On Sun, 24 Nov 2024 at 22:03, Michael Wayne Goodman < ***@***.***> wrote:
I can think of three reasons for getting the relation objects that aren't
solved by the existing API:
1. To inspect the metadata on a relation
2. To distinguish relations with the same source, target, and relation
name with different metadata (related to (1))
3. Given a target sense/synset from an interlingual query, to discover
where the relation came from, especially when the target is *INFERRED*
(1) and (2) are easily solved with a method like .relation_objects(), but
(3) is not (you'd need to go back to the source synset or sense, iterate
over its relation objects, and find one or more that match the relname +
target). Furthermore, in interlingual queries, the targets of synset
relations are not in the same lexicon as the one being queried (e.g.,
searching for hypernyms of a synset in omw-fr uses relations from omw-en,
then the target ILIs are resolved in omw-fr).
If we don't want to make Sense and Synset objects more stateful than the
already are, here's an alternative that expands on the .relation_objects()
method: .relation_map(). It returns a dictionary where the keys are the
relation objects and they map 1-to-1 to resolved targets. This way you can
deterministically identify the relation used to arrive at some target.
Synset.relation_map() -> dict[SynsetRelation, Synset]: ...
—
Reply to this email directly, view it on GitHub
<#216 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIPZRXA6G7RGT5IDESJI332CI5LJAVCNFSM6AAAAABRBJQCTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJWGIZTKOBSGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Francis Bond <https://fcbond.github.io/>
|
Is your feature request related to a problem? Please describe.
There is currently no way to get the metadata for a sense relation or synset relation. It exists in the database, but as relations are not modeled with classes there is nowhere to place a
metadata()
method.Describe the solution you'd like
It should be possible to get metadata for any relation. This could be something like adding a
with_metadata=True
parameter to methods likeSense.relations()
, and the return value would map relations to lists of tuples of (Sense, relation-metadta). This is not ideal, though, because it changes the return type.It should also be possible to filter relations based on metadata (at least
dc:type
). E.g.,sense.relations("other", type="material")
could only get relations matching the reltype and thedc:type
attribute.Describe alternatives you've considered
One can get the metadata through the non-public
wn._queries.get_metadata()
function, but they'd have to know the table name and the db-internal rowid of the relation they want the metadata for.Additional context
This is more urgent now that (as of the Open English Wordnet 2023) the
dc:type
metadata attribute is used to distinguishother
relations (see also #215).The text was updated successfully, but these errors were encountered: