Update the term relations with the latest types.

It was discovered that HYPERNYM does the same inference as HOLONYM.  But
others types of inference were not properly captured.

The 'infer.rst' explains futher the three inferences schemas.
parent ac76e5fb
Pipeline #2005 failed with stages
in 1 minute and 1 second
......@@ -54,7 +54,11 @@ class Distinguishable:
return res
class Subject(Distinguishable):
class Entity(Distinguishable):
pass
class Subject(Entity):
'''The role of an object as the `subject` of a `Triplet`:class:.
We create a different sub-type for each role an object can have in the KOS
......@@ -67,7 +71,7 @@ class Subject(Distinguishable):
'''
class Object(Distinguishable):
class Object(Entity):
'''The role of an object as the `object` of a triplet.'''
......@@ -112,46 +116,14 @@ class Fact(Triplet):
class TERM_RELATIONSHIP_KIND:
'''Hierarchical relationships are used to indicate terms which are narrower
and broader in scope.'''
class _Kind(object):
# type: TERM_RELATIONSHIP_KIND
def __invert__(self):
return TERM_RELATIONSHIP_KIND._REVERSE[self]
def __str__(self):
return f'TERM_RELATIONSHIP_KIND.{type(self).__name__}'
def __repr__(self):
return f'<{self!s}>'
@call
class HYPERNYM(_Kind):
'A more general term in a taxonomy.'
class UPWARDS:
'The verb goes from subject to object in the CAUSE'
@call
class HYPONYM(_Kind):
'A more specific term in a taxonomy.'
class DOWNWARDS:
'The verb goes from object to subject in the CAUSE'
@call
class HOLONYM(_Kind):
'A container (whole) in a meronomy.'
@call
class MERONYM(_Kind):
'A part in a meronomy.'
del _Kind
_REVERSE = {
MERONYM: HOLONYM,
HOLONYM: MERONYM,
HYPONYM: HYPERNYM,
HYPERNYM: HYPONYM,
}
_MORE_GENERAL = (HYPERNYM, HOLONYM)
class FLIPS:
'Flips object and subject'
# Make it like an Enum.
......@@ -163,14 +135,6 @@ class TermRelationship(metaclass=TermRelationsStore):
kind: TERM_RELATIONSHIP_KIND
tail: Relation
def __invert__(self):
# type: () -> TermRelationship
return type(self).get_or_create(
tail=self.head,
kind=~self.kind,
head=self.tail
)
class Conclusion(Triplet):
'''A triplet which is inferred. '''
......@@ -180,7 +144,4 @@ class Conclusion(Triplet):
because: TermRelationship
def validate(self) -> None:
base = self.base
assert self.distance > 0
assert self.subject == base.subject and self.relation == base.relation
assert self.object == self.cause.object
===========================================================
Inference algorithm over triplets with term relationships
===========================================================
In this document a triplet is shown diagrammatically as::
[ID:] subject ------ verb ---------> object
Each triplet is always shown horizontally. We optionally, put a unique (per
graph) identifier for each triplet.
Relationship between terms is pictured::
term 1
^
|
| kind
|
|
term 2
Any relationship between terms is always oriented vertically and the arrow is
*usually directed upwards* if kind is `hypernym` or `holynym`.
In written form, we say that the term in the tail of the arrow has "kind-al"
relationship with the term in the head.
Integrated example::
Camagüey --- is part of -----> Cuba
^
| holonym
|
Florida ---- is part of -----> Camagüey
^
| holonym
|
Yurdik ----- lives in -----> Florida
.. note:: In order to maintain the horizontal/vertical division for the
triplets and term relationships, I have to repeat some terms, objects and
or relationships.
In the example we have:
- two terms (verbal forms):
- ``lives in``
- ``is part of``
- three triplets:
- Florida is part of Camagüey
- Camagüey is part of Cuba
- Yurdik lives in Florida
- two term relationships:
- ``is part of`` has a meronymical relationship with itself
- ``lives in`` has an holonymical relationship with ``is part of``.
Inference
=========
If you don't place **any meaning** at all to the relationships, you wouldn't
be able to extract more information from what's given already.
We don't name the relationships between terms. The only valid relations are
those going *upwards* (hypernym, holonym).
Operational meaning of term relationships
-----------------------------------------
Upwards inference
~~~~~~~~~~~~~~~~~
Given the following graph::
T2: O1 ---- v1 ---> O2
^
| UPWARDS
|
T1: S1 ---- v2 ---> O1
We may also infer that::
T3: S1 ---- v2 ----> O2
.. rubric:: Definition of `base` and `cause`.
We say that `T3` has *base* `T1` and *cause* `T2`: The inferred triplet has
the same subject and verbal form its base has, and shares the object with its
cause.
In the example given above we would be able to infer that:
- Florida is part of Cuba,
- Yurdik lives in Camagüey, and
- Yurdik lives in Cuba.
Downwards inference
~~~~~~~~~~~~~~~~~~~
Given the following triplets::
T2: Apple ---- is a subclass of ----> Fruit
T1: Manu ----- doesn't like ---------> Fruit
We should be able to infer::
T3: Manu ----- doesn't like ----------> Apple
With the current implementation there's no way we can relate 'is a subclass
of' with 'does not like'. The workaround is two "flip" T1::
T1': Fruit ----- is not liked by -----> Manu
^
| UPWARDS
|
T2: Apple ---- is a subclass of ----> Fruit
This may pose a problem is we need to state such knowledge (T1) frequently.
The scheme could be given by::
T2: M1 ---- v1 ---> O1
|
| DOWNWARDS
v
T1: S1 ---- v2 ---> O1
We may also infer that::
T3: M1 ---- v1 ---> S1
.. warning:: Notice we changed the sense of the arrow connecting the verbs.
However, this is NOT the inverse of the relation that is represented with
an arrow heading upwards.
We say that `T3` has *base* `T2` and *cause* `T1`. The base shares the
subject and verb, and cause shares its subject as the object of the inferred
triplet.
*Flipped* inference
~~~~~~~~~~~~~~~~~~~
From the triplet::
T2: Apple ---- is a subclass of ----> Fruit
^
| FLIPS
|
is superclass of
We should be able to infer::
T3: Fruit ---- is superclass of ----> Apple
This case, we say that T2 is both the base and cause.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment