Ok Dave. Here is a minimal example:
*Java Code*
String rdfPath = "dataset/rdf/sample.rdf";
String inRuleBase = "rules/sampleRule.txt";
Model model = ModelFactory.createDefaultModel();
FileInputStream fis = new FileInputStream(rdfPath);
model.read(fis,"ticket");
Reasoner reasoner = new GenericRuleReasoner( Rule.rulesFromURL(inRuleBase));
InfModel infModel = ModelFactory.createInfModel( reasoner, model );
StmtIterator si = infModel.listStatements();
while ( si.hasNext() )
{
Statement stmt = si.nextStatement();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
System.out.println(subject.toString() + " " + predicate.toString() + " " +
object.toString());
}
*RDF File** (sample.rdf)*
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:aa="
http://www.abcd.org/ofdf#" xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:rdfs="
http://www.w3.org/2000/01/rdf-schema#">
<owl:Class rdf:about="http://www.abcd.org/ofdf#folder">
</owl:Class>
<owl:Class rdf:about="http://www.abcd.org/ofdf#file">
</owl:Class>
<rdf:Description rdf:about="http://www.abcd.org/ofdf#folder/001">
<aa:createdBy>MisterX</aa:createdBy>
<rdf:type rdf:resource="http://www.abcd.org/ofdf#folder"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.abcd.org/ofdf#file/AAA">
<aa:processedIn>http://www.abcd.org/ofdf#folder/001</aa:processedIn>
<rdf:type rdf:resource="http://www.abcd.org/ofdf#file"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.abcd.org/ofdf#folder/002">
<aa:createdBy>MisterY</aa:createdBy>
<rdf:type rdf:resource="http://www.abcd.org/ofdf#folder"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.abcd.org/ofdf#file/AAA">
<aa:processedIn>http://www.abcd.org/ofdf#folder/002</aa:processedIn>
<rdf:type rdf:resource="http://www.abcd.org/ofdf#file"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.abcd.org/ofdf#file/BBB">
<aa:processedIn>http://www.abcd.org/ofdf#folder/002</aa:processedIn>
<rdf:type rdf:resource="http://www.abcd.org/ofdf#file"/>
</rdf:Description>
</rdf:RDF>
*Rule** (**sampleRule.txt)*
@prefix aa: <http://www.abcd.org/ofdf#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
[ruleX:
(?file1 aa:processedIn ?fld1)
(?file1 aa:processedIn ?fld2)
notEqual(?fld1, ?fld2)
(?fld1 aa:createdBy ?auth1)
(?fld2 aa:createdBy ?auth2)
notEqual(?auth1, ?auth2)
->
(?file1 rdf:type aa:fileRequiringConflictCheck)
]
[ruleY:
(?file1 aa:processedIn ?fld1)
(?file1 aa:processedIn ?fld2)
notEqual(?fld1, ?fld2)
->
(?file1 rdf:type aa:fileInManyFolders)
]
RuleY is properly recognized and I can see the following statement added to
the Inference model:
*http://www.abcd.org/ofdf#file/AAA <http://www.abcd.org/ofdf#file/AAA>
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
http://www.abcd.org/ofdf#fileInManyFolders
<http://www.abcd.org/ofdf#fileInManyFolders>*
Nothing however for ruleX and this is what I struggle with. Thanks in
advance for the help.
On Sun, Aug 21, 2016 at 3:44 PM, Dave Reynolds <[email protected]>
wrote:
> On 21/08/16 12:37, lookman sanni wrote:
>
>> Hi all,
>>
>> I am struggling with the definition of jena rules. I have an RDF file
>> where
>> I am defining:
>>
>> - a "folder" class with a property "createdBy"
>> - a "file" class with a property "processedIn" of type "folder"
>>
>> My RDF file contains resources from the two classes. I am trying to define
>> a Jena rule for querying files appearing in more than a folder, having
>> different authors.
>>
>> To that end, I added to my RDF the specification of a class
>> "fileRequiringConflictCheck" a subclass of the class "file" and then
>> specified the following jena rule:
>>
>> [ruleX:
>> (?file1 aa:processedIn ?fld2)
>> (?file1 aa:processedIn ?fld1)
>> notEqual(?fld1, ?fld2)
>> (?fld1 aa:createdBy ?auth1)
>> (?fld2 aa:createdBy ?auth2)
>> notEqual(?auth1, ?auth2)
>> ->
>> (?file1 rdf:type aa:fileRequiringConflictCheck)
>> ]
>>
>> Outcome is that the rule is likely never met whenever expected as per my
>> sample dataset. Any idea what I might be missing ?
>>
>
> Looks reasonable, check your namespaces are correct. If you can't get it
> working then post a minimal example of the data and someone might be able
> to spot the problem.
>
> Dave
>
>
--
Best Regards
Lookman SANNI