2013-07-01 31 views
0

我已經開始使用耶拿並且測試了它的基於規則的reasoners,但是我沒有看到我期望的結果。我列出的所有個人聲明,這些都是從我的OWL文件:耶拿規則沒有在預期時發射

[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] 

我要選擇選擇CreditCardPayment,所以我寫了這個規則:

@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') 
] 

但規則不火。我在規則文件中做了什麼錯誤? (我已經測試了

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

和它的作品。

回答

3

由於耶拿用戶的郵件列表戴夫·雷諾茲pointed outrdf:type是不一樣的rdf:Type,(慣例是使用小寫字母。謂詞和類大寫)因此,該規則應該是:

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

replied到消息:

我已將rdf:Type更改爲rdf:type,但得到了相同的結果。它是否只需要一個人匹配這個規則(在這種情況下,有兩個人)?

規則匹配儘可能多的實例,所以無論多少資源匹配?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();會導致推理模型運行規則,從而產生預期結果。