0

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.

4

1 回答 1

3

正如 Dave Reynolds在 Jena 用户的邮件列表中指出rdf:type的那样rdf:Type,与 , 不同(惯例是谓词使用小写,类使用大写)。因此,规则应该是:

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

回复了该消息:

我已将 rdf:Type 更改为 rdf:type,但得到了相同的结果。是否只需要一个人来匹配这个规则(在这种情况下,有2个人)?

规则匹配尽可能多的实例,因此无论匹配多少资源?use,该规则都应该为所有实例触发。如果还有其他问题,它似乎不在您向我们展示的任何代码中。关于该线程的更多讨论表明,在这种情况下,您的完整 Java 代码是:

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;
}

虽然上面的rdf:type/rdf:Type问题导致初始规则未按预期触发,但上面的代码也存在processRules("data/rules/rules.txt", infmodel);仅返回带有规则的推理模型,但实际上并没有启动与它们相关联的推理的问题。添加语句processRules.prepare();会导致推理模型运行规则,产生预期的结果。

于 2013-07-01T12:23:58.940 回答