SWRLルールを使用して推論するオントロジーを構築します。ProtegeでSQWRLクエリを実行すると、正常に機能します。問題は、JenaでPelletを使用したい場合、PelletがクエリにSWRLルールを含めていないように見えることです。私はこのようにペレットを含めます:
InputStream in = new FileInputStream(new File("D:\\Fakultet\\WeatherHealthcast1.owl"));
Model model = ModelFactory.createDefaultModel();
model.read(in, null);
OntModel ontology = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, model);
// Create a new query
String queryString =
"PREFIX WeatherHealthcast: <http://www.semanticweb.org/ontologies/2011/2/WeatherHealthcast.owl#> " +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"SELECT ?disease " +
"WHERE { " +
" ?person rdf:type WeatherHealthcast:Person." +
" ?person foaf:firstName ?fn." +
" ?person foaf:lastName ?ln." +
" FILTER regex(str(?fn), \"Viktor\")." +
" FILTER regex(str(?ln), \"Taneski\")." +
" ?disease rdf:type WeatherHealthcast:Disease. " +
" ?person WeatherHealthcast:suffersFrom ?disease." +
"}";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, ontology);
ResultSet resultSet = qe.execSelect();
System.out.println("TEST");
while (resultSet.hasNext())
{
QuerySolution result = resultSet.next();
RDFNode disease = result.get("disease");
Resource resource = disease.asResource();
System.out.println(" { Suffers from: " + resource.getLocalName() + " . }");
}
私もこれを試しました:
Reasoner r = PelletReasonerFactory.theInstance().create();
InfModel inferenceModel = ModelFactory.createInfModel(r, model);
しかし、進歩はありません。何か案は?私の卒業論文にはこれが必要です。ありがとう