Question

I've started to use Jena and tested its rules-based reasoners, but I'm not seeing the results that I expect. I listed all of individual statement and these are from my OWL files:

[http://www.semanticweb.org/ontologies/2012/6/Ontology1342794465827.owl#CreditCardPayment,        http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2000/01/rdf-schema#Resource]

[http://www.semanticweb.org/ontologies/2012/6/Ontology1342794465827.owl#UseCase, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2000/01/rdf-schema#Resource]

I want to select to select CreditCardPayment, so I wrote this rule:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix base: <http://www.semanticweb.org/ontologies/2012/6/Ontology1342794465827.owl#>
[rule1:
(?use rdf:Type rdfs:Resource)
->
print('test')
]

but the rule doesn't fire. What I did wrong with rule file? (I've already tested on

[rule1:
print('test')
->
print('test')
])

and it works.

Was it helpful?

Solution

As Dave Reynolds pointed out on the Jena users' mailing list, rdf:type is not the same as rdf:Type, (the convention is to use lower case for predicates and upper case for classes). As a result the rule should be:

[rule1: (?use rdf:Type rdfs:Resource) -> print('test') ]

You replied to that message:

I've changed rdf:Type to rdf:type, but I got the same result. Does it required only one individual to match this rule (In this case, there are 2 individuals)?

A rule matches as many instances as possible, so it does not matter how many resources match ?use, the rule should fire for all of them. If there is another problem, it does not appear to be in any of the code that you've shown us. More discussion on that thread revealed that your full Java code in this case was:

public class Main {
    public static void main(String[] args) throws MalformedURLException, IOException {
    // create a basic RAW model that can do no inferencing
    Model rawModel = FileManager.get().loadModel("file:data/design_pattern.owl");

    // create an InfModel that will infer new facts.
    OntModel infmodel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF, rawModel);
        StmtIterator i = infmodel.listStatements();
        System.out.println("====Begin=====");
        while (i.hasNext()) {
            Statement indi = i.next();
            System.out.println(indi);
        }
        System.out.println("=====End=====");
        InfModel processRules = (InfModel) processRules("data/rules/rules.txt", infmodel);
    }
}

public static Model processRules(String fileloc, InfModel modelIn) {
    Model m = ModelFactory.createDefaultModel();
    Resource configuration = m.createResource();
    configuration.addProperty(ReasonerVocabulary.PROPruleSet, fileloc);
    Reasoner reasoner = GenericRuleReasonerFactory.theInstance().create(configuration);
    InfModel infmodel = ModelFactory.createInfModel(reasoner, modelIn);
    return infmodel;
}

While the rdf:type/rdf:Type issue above caused the initial rule to not fire when expected, the code above also has the issue that processRules("data/rules/rules.txt", infmodel); only returns an inference model with the rules, but does not actually start the reasoning associated with them. Adding the statement processRules.prepare(); causes the inference model to run the rules, producing the expected results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top