2013-04-17 69 views
2

在我的本體,我有了該數據屬性OWL類表達對數據屬性

hasName "somaName"^^string個人,

然而,當我建立一個類的表達和發送到推理的獲得情況下,我得到一個空集用下面的查詢,

OWLClassExpression x = schema.getFactory().getOWLDataHasValue(schema.getDataProperty("hasName"), schema.getFactory().getOWLLiteral("somaName")); 
System.out.println(reasoner.getInstances(x, true)); 

的getDataProperty只是一個小方法:

public OWLDataProperty getDataProperty(String dataProperty){ 
     return factory.getOWLDataProperty("#"+dataProperty,pm); 
    } 

回答

3

下面的代碼片段的工作原理,將它與您的代碼進行比較,看看有什麼不同。你應該使用支持這種構造的推理器(Hermit)。

//Initiate everything 
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
String base = "http://www.example.org/"; 
OWLOntology ontology = manager.createOntology(IRI.create(base + "ontology.owl")); 
OWLDataFactory factory = manager.getOWLDataFactory(); 
//Add the stuff to the ontology 
OWLDataProperty hasName = factory.getOWLDataProperty(IRI.create(base + "hasName")); 
OWLNamedIndividual john = factory.getOWLNamedIndividual(IRI.create(base + "john")); 
OWLLiteral lit = factory.getOWLLiteral("John"); 
OWLDataPropertyAssertionAxiom ax = 
        factory.getOWLDataPropertyAssertionAxiom(hasName, john, lit); 
AddAxiom addAx = new AddAxiom(ontology, ax); 
manager.applyChange(addAx); 

//Init of the reasoner 
//I use Hermit because it supports the construct of interest 
OWLReasonerFactory reasonerFactory = new Reasoner.ReasonerFactory(); 
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology); 
reasoner.precomputeInferences(); 

//Prepare the expression for the query 
OWLDataProperty p = factory.getOWLDataProperty(IRI.create(base + "hasName")); 
OWLClassExpression ex = 
       factory.getOWLDataHasValue(p, factory.getOWLLiteral("John")); 

//Print out the results, John is inside 
Set<OWLNamedIndividual> result = reasoner.getInstances(ex, true).getFlattened();   
for (OWLNamedIndividual owlNamedIndividual : result) { 
    System.out.println(owlNamedIndividual); 
} 
+0

+1。但是,如何添加'OWLDataPropertyAssertionAxiom ax'到我的'OWLClass unknownClass = factory.getOWLClass(IRI.create(baseIRI +「UnknownClass」));'而不是保存本體?你能幫我嗎??? – Tomas

相關問題