Rule using inferred triples does not work


(Johan Kumps) #1

Hi all,

I’m trying to build a Stardog rule which makes use of inferred triples by another rule. Apparently the rule does not match. I know that Stardog does not materialize inferred triples but I thought that when using SWRL syntax rules using inferred triples did work.

Would you be so kind to help me out?

Kind regards,
Johan,


(zachary.whitley) #2

It should. Can you share your data, rules, ontology, query that isn’t working, what you expected, what you got, how you loaded the data, database options, and the version of Stardog you’re using?


(Johan Kumps) #3

Hi,
Thanks for your reply. Sharing my data / ontology is a litle difficult due to privacy. If we can’t find the issue with the info below I’ll have to create a testcase.

These 2 rules are working:

Rule 1:

IF {
	?o a sosa:Observation .
	?o sosa:observedProperty <http://www.mycompany.com/resources#Humidity> .
    ?o sosa:hasFeatureOfInterest ?foi .
    ?o sosa:phenomenonTime ?t .
    ?o sosa:hasResult ?r .
    ?r qudt:numericValue ?v .
    FILTER (?v > 40) .
    FILTER (?v < 70) .
}
THEN {
    ?foi resources:hasHumidity <http://www.mycompany.com/samples/weather#AverageHumidity>
}

Rule 2:

IF {
	?o a sosa:Observation .
	?o sosa:observedProperty <http://www.mycompany.com/resources#Temperature> .
    ?o sosa:hasFeatureOfInterest ?foi .
    ?o sosa:phenomenonTime ?t .
    ?o sosa:hasResult ?r .
    ?r qudt:numericValue ?v .
    FILTER (?v < 0) .
}
THEN {
    ?foi resources:hasTemperature <http://www.mycompany.com/samples/weather#Frosty>
}

Rule 3 should match in case the same ?foi hasTemperature Frosty and hasHumidity AverageHumidity or MoistHumidity or VeryMoistHumidity :

IF {
	  ?foi a sosa:FeatureOfInterest .
        ?foi resources:hasTemperature weather:Frosty .
        ?foi resources:hasHumidity ?hum .
        FILTER (?hum = weather:AverageHumidity || ?hum = weather:MoistHumidity || ?hum = weather:VeryMoistHumidity)
}
THEN {
    ?foi resources:hasPhenomenon <http://www.mycompany.com/samples/weather#PotentiallyIcy>
}

As rule 1 and rule 2 are working (I can select ?foi that have the hasTemperature and HasHumidity predicates with the correct values, the issue should be in rule 3.

Thanks for helping me out.
Johan,


(Johan Kumps) #4

This ‘combining’ rule is also working :

IF {
	  ?foi a sosa:FeatureOfInterest .
        ?foi resources:hasTemperature weather:Frosty .
        ?foi resources:hasHumidity weather:AverageHumidity .
}
THEN {
    ?foi resources:hasPhenomenon <http://www.mycompany.com/samples/weather#PotentiallyIcy>
}

So the question is how to model the weather:AverageHumidity or weather:MoistHumidity or weather:VeryMoistHumidity

Thanks again!

Johan,


(zachary.whitley) #5

I haven’t had a chance to look at what you sent yet but I forgot to ask if there were any errors or warnings in the log. I suspect that the most likely thing you’ll find are warnings about cycles in your rules but that’s a guess at this point.


(Johan Kumps) #6

Hi,

After some more testing and rewriting of my rule it finally works:

IF {
	  ?foi a sosa:FeatureOfInterest .
        ?foi resources:hasTemperature weather:Frosty .
        { ?foi resources:hasHumidity weather:MoistHumidity }
        UNION { ?foi resources:hasHumidity weather:VeryMoistHumidity }
        UNION { ?foi resources:hasHumidity weather:AverageHumidity } .
}
THEN {
    ?foi resources:hasPhenomenon <http://www.mycompany.com/samples/weather#PotentiallyIcy>
}

It had to do with the way I refer to the inferred triples and the OR constuction I tried to make.

Thanks anyway for helping me.
Johan,


(zachary.whitley) #7

Glad to hear you got it working. So what exactly was the problem with your rule construction? Was it the use of equality in the filter? Would it have worked if you had used the sameterm function?


(Johan Kumps) #8

Hi,

Yes it had to do with the way I was checking whether resources:hasHumidity is pointing to AverageHumidity, MoistHumidity or VeryMoistHumidity.

I think sameterm would work too. Currently I use UNION as follows:

IF {
?foi a sosa:FeatureOfInterest .
?foi resources:hasTemperature weather:Frosty .
{ ?foi resources:hasHumidity weather:MoistHumidity }
UNION { ?foi resources:hasHumidity weather:VeryMoistHumidity }
UNION { ?foi resources:hasHumidity weather:AverageHumidity } .
}
THEN {
?foi resources:hasPhenomenon http://www.mycompany.com/samples/weather#PotentiallyIcy
}

Would the use of sameterm be more efficient?

Johan,


(zachary.whitley) #9

Not sure. I’m just trying to understand why your first try wouldn’t work and learn from your experience. I’m not sure that using sameTerm would actually work but it might be interesting to give it a try and if it works look at any differences in the query plan. Now that I think about it I"m not sure if using sameTerm to compare a uri’s is any different from simple equality.