-
Couldn't load subscription status.
- Fork 19
Description
Let me explain what I want to do: I want to perform reasoning inside a graph, also called inline inference. Specifically, I want to create a predicate similar to eye —pass-only-new command, receive a graph as subject, and outputs (binding to object) only the new conclusions asserted after reasoning within the graph.
Here's my first try:
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix : <#>.
{?g :conclusionOnlyNew ?g3} <= {
?g log:conclusion ?g2. #using log:inferences instead gives me same result
(?g2 ?g) e:graphDifference ?g3 # remove original graph contents
}.
:mykb rdf:value {
:Socrates a :Human.
{?x a :Human} => {?x a :Mortal}.
{:Socrates a :Mortal} => {:test1 a :succeed}.
{?x a :PostiveNum} <= {?x math:greaterThan 0} .
{123 a :PostiveNum} => {:test2 a :succeed}.
}.
{:mykb!rdf:value :conclusionOnlyNew ?g} => {:newConclusion :is ?g}. # reasoning inside the graph
The expected output is:
:newConclusion :is {
: Socrates a :Mortal.
:test1 a :succeed.
:test2 a :succeed.
}
The actual output is:
:newConclusion :is {
:Socrates a :Mortal.
:test1 a :succeed.
:test2 a :succeed.
true => {
:Socrates a :Human.
}.
{
?U_1 math:greaterThan 0.
} => {
?U_1 a :PostiveNum.
}.
true => {
:Socrates a :Mortal.
}.
true => {
:test1 a :succeed.
}.
true => {
:test2 a :succeed.
}.
}.
Besides the strange sentences of the form true => {...}, there is also { ?U_1 math:greaterThan 0. } => { ?U_1 a :PostiveNum. }, which is outside of my expectation .
So, I did some test, and found that log:conclusion and log:inference incorrectly convert backward rules into forward form in their output (i.e., the bound object ), which causes subsequent processing issues. Nevertheless, they somehow correctly executed the logic of the backward rule, producing :test2 a :succeed.
Namely:
{:mykb!rdf:value log:conclusion ?g} => {:Conclusion :is ?g}.
in my context would yield:
:Conclusion :is {
:Socrates a :Human.
:Socrates a :Mortal.
:test1 a :succeed.
:test2 a :succeed.
{
?U_2 a :Human.
} => {
?U_2 a :Mortal.
}.
{
:Socrates a :Mortal.
} => {
:test1 a :succeed.
}.
{
123 a :PostiveNum.
} => {
:test2 a :succeed.
}.
true => {
:Socrates a :Human.
}.
{
?U_3 math:greaterThan 0. # backward rule turned into a forward form
} => {
?U_3 a :PostiveNum.
}.
true => {
:Socrates a :Mortal.
}.
true => {
:test1 a :succeed.
}.
true => {
:test2 a :succeed.
}.
}.
I also attempted to remove sentences of the form true => {...}, leading to my second version:
{?g :conclusionOnlyNew ?g4 } <= {
?g log:conclusion ?g2.
?g2 e:findall ({true => ?sth } {true => ?sth} ?list). #remove sentences of the form `true => {...}`
#”list" log:trace ?list.
?list log:conjunction ?g3.
(?g2 ?g3) e:graphDifference ?g4.
}.
# Other parts remain unchanged
But this does not work because elements in ?list are appears in the form ?sth <= true, rather than the expected true => ?sth. This is another bug.
Through some experiments, I have found that many built-in predicates have similar problems with backward rules:
log:semantics, when reading other files, transforms backward rules into forward ones. Interestingly, this does not happen when it reads itself (<> log:semantics ?x).log:parsedAsN3has the same issue.e:findall, as mentioned above, turned forward rules of only the formtrue => {:s :p :o}into backward. Compared to the previous problem this is a minor issue.
On the other hand, log:includeand e:graphMember able to distinguish between forward and backward rules correctly (even syntactically incorrect forms like :g1 => :g2 and :g1 <= true), seems treating them as ordinary triples, which is my expectation. Here is a simple example:
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <#>.
:mygraph rdf:value {{:d :e :f} <= {:a :b :c}}.
{:mygraph rdf:value ?g. ?g log:includes {{:d :e :f} ?p ?o} } => {:result :is ?p}.
output:
:result :is log:isImpliedBy.