trueagi-io / metta-examples

Discussion of MeTTa programming with examples
MIT License
20 stars 18 forks source link

How to find patterns/atoms with the same attributes/types? #56

Open CICS-Oleg opened 1 week ago

CICS-Oleg commented 1 week ago

I need to implement the following procedure/rule.

The rule infers that if two eventualities are direct instantiations of the same abstract eventuality (i.e., they both describe the same action/state with the same thematic roles) but for at least one thematic role, for which it is asserted that one of the two eventualities has a certain value on that thematic role while the other one does not, then the two eventualities are connected by the "not" property.

Typed variant:

(: Seal Eventuality)
(: Unseal Eventuality)
(: Pay Eventuality)
(: not1 Eventuality)

(: has-agent ThematicRole)

(Seal (has-agent User))
(Seal (has-agent))
(Unseal (has-agent User))
(Pay (has-agent))

Tupled variant:

(Eventuality Seal)
(Eventuality Unseal)
(Eventuality Pay)
(Eventuality not1)

(ThematicRole has-agent)

(Seal (has-agent User))
(Seal (has-agent))
(Unseal (has-agent User))
(Pay (has-agent))

Expected result:

(not1 (Seal (has-agent User)) (Seal (has-agent)))
(not1 (Unseal (has-agent User)) (Seal (has-agent)))
(not1 (Unseal (has-agent User)) (Pay (has-agent)))
(not1 (Seal (has-agent User)) (Pay (has-agent)))

Reference sparql code:

CONSTRUCT{?e1 :not ?e2}
  WHERE{?e1 rdf:type ?c. ?e2 rdf:type ?c. ?c rdf:type :Eventuality. FILTER(?e1!=?e2)
    ?trn rdf:type :ThematicRole. ?e1 ?trn ?vn. ?r rdf:type :false,:hold; rdf:subject ?e2; rdf:predicate ?trn; rdf:object ?vn.
    NOT EXISTS{?tr rdf:type :ThematicRole. FILTER(?tr!=?trn) ?e1 ?tr ?tv1. NOT EXISTS{?e2 ?tr ?tv2}}
    NOT EXISTS{?tr rdf:type :ThematicRole. FILTER(?tr!=?trn) ?e2 ?tr ?tv2. NOT EXISTS{?e1 ?tr ?tv1}}
    NOT EXISTS{?tr rdf:type :ThematicRole. FILTER(?tr!=?trn) ?e1 ?tr ?tv1. ?e2 ?tr ?tv2. FILTER(?tv1!=?tv2)}}
Necr0x0Der commented 5 days ago

I'm not sure I got the description.

if two eventualities are direct instantiations of the same abstract eventuality

What is the abstract eventuality here? What are direct instantiations? What does (has-agent) mean? Why does has-agent have another arity in case of (has-agent User)? Why the type is defined as (: Seal Eventuality) while (Seal (has-agent)) looks like Seal should have an arrow type? Do you have an example of query doing what you need? Or what is the issue?