Everyone,
I’m not sure this is the place for my question but I’m trying.
I’ve an ontology that’s describing some vehicles and some clients. The ontology is based on three major classes, which are “Vehicle” , “Client” and a class joining Vehicle and Client (named “VehicleToClient”).
Anyway, in the “Client” class I have a property isTruckDriver (boolean). In the “Vehicle” class, I have a property kindOfVehicle (string, can be Truck, Car, …).
Now, and there’s why I’m posting there, I want to use the reasoning property of Stardog to determine if a Client is a “lyer” or not, based on his answer on isTruckDriver and on the value of kindOfVehicle (if it’s different he’s a lyer, we can trust him if not (this is an example, we won’t do that)).
The problem is : I don’t know where to start. I’ve read the whole documentation of Reasoning, Rules, … of Stardog but I don’t know where to start :
Am I supposed to start writing rules on Protégé (Ontology editor) ?
Am I supposed to use the “IF THEN” thing on my turtle file ?
And more important, how to do that ? I’m loosing my mind on it :’(
The easiest way to accomplish what you're looking for would be to use Stardog Rules. Adding the IF...THEN syntax into your turtle files easily lets you accomplish this:
IF {
?client :isTruckDriver true .
?client :kindOfVehicle "Car"
}
THEN {
?client a :Lyer
}
Loading this in one of your Turtle files and then running a query with reasoning enabled should give you results that use the rule.
This request sends me what I want: this is a basic request. So to answer your question: I’m seeing what I’m expecting to see.
As I said, now I want to use the reasoning tool. To use it, it looks like the most simple way is to add rules into the turtle file.
The .ttl I posted doesn’t have rules. When I add rules onto the turtle file, Stardog doesn’t like it and says : ‘The file is invalid. Please ensure that the file is correctly’
Is there an additional message in your stardog.log file that might show a syntax error in your rules? I am able to add a very simple rule to the file you provided and then load it with no issues:
<http://www.fluidops.com/resource/V2_CLIENT-provider/1514291476361/Provider> a System:Context ;
System:contextType "Provider" ;
System:contextSrc :V2_CLIENT-provider ;
System:contextState "Published" ;
dc:date "2017-12-26T13:31:16.361" ;
rdfs:label "Provider run" ;
System:editable "false"^^xsd:boolean .
IF {
?c a <http://www.covea.eu/VoitureConnectee#Client> ;
<http://www.covea.eu/VoitureConnectee#estConducteurDeTypeRoute> "EXTRA_URBAN" ;
<http://www.covea.eu/VoitureConnectee#estConducteurVille> "N"
}
THEN {
?c a <http://www.covea.eu/VoitureConnectee#Match>
}
Stephens-iMac:community stephen$ stardog query -r clement "select * {?c a <http://www.covea.eu/VoitureConnectee#Match>} limit 5"
+---------------------------------------------------+
| c |
+---------------------------------------------------+
| http://www.fluidops.com/resource/V2CLIENT/E767682 |
| http://www.fluidops.com/resource/V2CLIENT/2782748 |
| http://www.fluidops.com/resource/V2CLIENT/G429992 |
| http://www.fluidops.com/resource/V2CLIENT/J045010 |
| http://www.fluidops.com/resource/V2CLIENT/E946626 |
+---------------------------------------------------+
Query returned 5 results in 00:00:00.065
What version of Stardog are you running? You only mentioned that you thought you were running the latest version. Inline rules in turtle files was only recently added in the latest 5.1 release.
You should be able to get the version by running stardom-admin server status
Stephen, thanks a lot. This is what I was looking for. A simple and understable answer !
Zachary : you found to solution to my problem ! I was in 5.0.3. In 5.1, it worked like a charm. My bad : I was sure I was on the latest update (that’s why I said that to Stephen …)
I cannot try a very good example of reasoning because I doesn’t have remote access to my company server (I’ll be back there if any problems )
Another question (because you look strong on this subject) :
Do you think this is the best way to write rules ? (writing rules in the turtle file)
If no, can you show me those ways you think are better ?
I'm going to assume you're talking about Stephen here because I'm just here to make suggestions like, "Did you check to make sure there's gas in the car?" but I'll give it a go anyway.
Inline rules in turtle is new so I haven't had a chance to play with it too much but I can give you my initial impressions. This is the kind of practical extension to a standard that I really appreciate from the Stardog people. They have a strong focus on supporting standards but know where to extend them when it means making it easier to get things done. Technically it's not turtle anymore once you add the rules so that's something to keep in mind if you're planning on sharing the files with anyone not working with Stardog but converting it to turtle should be as easy as loading the data and exporting it back out was turtle. (I'll have to check if there is an option to export as turtle+rules. sturtle? Searching for "turtle dog" on google is amusing if you want to give it a try)
If that's something you plan on doing you can always save your stardog turtle rules in a separate file since you can always load or add multiple files. What it really means is unimposing options and options are nice things to have.
I would definitely recommend using the Stardog rules syntax (IF...THEN..) over SWRL. This is the, going beyond the standards thing that I was mentioning earlier. I like to think that people have a zero -sum cognitive budget to spend on their problems and some semantic web technologies spend way too much of it on the tech and don't leave enough for the problem you're working on. The Stardog enhancements change that equation and I love it. (ICV, PATHS, Stardog Rules Syntax, etc)