2013-04-17 2 views
2

В моей онтологии, у меня есть лицо, которое имеет это свойство данныхOWL Expression Класса для свойств данных

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

Следующий фрагмент кода работает, сравните его с вашим кодом, чтобы узнать, что другое. Вы должны использовать аргумент, который поддерживает этот тип конструкции (Отшельник).

//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