我建立了一个使用SWRL规则进行推理的本体。当我在Protege中执行SQWRL查询时,它工作正常。问题是,当我想将Pellet与Jena一起使用时,Pellet似乎在查询中不包括SWRL规则。我像这样包含Pellet:

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


但没有进展。有任何想法吗?我的毕业论文需要这个。谢谢

最佳答案

据我所知,颗粒不能支持SQWRL。另一方面,它支持SWRL,但有一些限制(请参见http://clarkparsia.com/pellet/faq/rules)。

关于jena - Pellet不包含我的SWRL规则,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7146469/

10-14 22:49