Java 使用Jena从OWL检索具有特定对象属性的个人

Java 使用Jena从OWL检索具有特定对象属性的个人,java,jena,owl,Java,Jena,Owl,我有一个类CloudService,我创建了这个类的许多个人。这是我的CS.owl的一部分,它显示了CloudService类的一个单独的DropBox <!-- language: xml --> <!-- http://www.semanticweb.org/ontologies/SaaS-24-03-2013.owl#DropBox --> <owl:NamedIndividual rdf:about="&

我有一个类CloudService,我创建了这个类的许多个人。这是我的CS.owl的一部分,它显示了CloudService类的一个单独的DropBox

 <!-- language: xml -->

         <!-- http://www.semanticweb.org/ontologies/SaaS-24-03-2013.owl#DropBox -->
            <owl:NamedIndividual rdf:about="&SaaS-24-03-2013;DropBox">
                <rdf:type rdf:resource="&SaaS-24-03-2013;CloudService"/>
                <hasPriceModel rdf:resource="&SaaS-24-03-2013;Freemium"/>
                <hasDeliveryModel rdf:resource="&SaaS-24-03-2013;Software-as-a-Service"/>
            </owl:NamedIndividual>

我需要使用Jena检索CloudService类的个人(比如DropBox)。我需要用Jena来运行它。这是我的密码

  <!-- language: java -->

                String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
                                "PREFIX owl: <http://www.w3.org/2002/07/owl#> "+
                                    "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "+
                                        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
                                            "PREFIX : <http://www.semanticweb.org/ontologies/SaaS-24-03-2013.owl#> "+
    "SELECT ?Service "+
                                            " WHERE {"+
                                        " ?Service  a   :CloudService "+                   
                                        ". ?Service  :hasPriceModel ?F. FILTER regex(str(?F), 'Freemium') }"; 
                   model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
                        model.read("ontologies/CS.owl");
                Query query = QueryFactory.create(SparqlQuery);
                        QueryExecution qe = QueryExecutionFactory.create(query, model);
                        com.hp.hpl.jena.query.ResultSet results =  qe.execSelect();
    while(results.hasNext()) {
                QuerySolution qs = results.next();
                RDFNode x = qs.get("Service");
                System.out.println(x.asNode().getLocalName()); }
    qe.close();
                }

String query=“前缀rdf:”+
“前缀owl:”+
“前缀xsd:”+
“前缀rdfs:”+
“前缀:”+
“选择?服务”+
“其中{”+
“?服务a:CloudService”+
“?服务:hasPriceModel?F.FILTER regex(str(?F),'Freemium')}”;
model=ModelFactory.createOntologyModel(OntModelSpec.OWL\u MEM\u RULE\u INF);
model.read(“ontologys/CS.owl”);
Query Query=QueryFactory.create(SparqlQuery);
QueryExecution qe=QueryExecutionFactory.create(查询,模型);
com.hp.hpl.jena.query.ResultSet results=qe.execSelect();
while(results.hasNext()){
QuerySolution qs=results.next();
RDFNode x=qs.get(“服务”);
System.out.println(x.asNode().getLocalName());}
qe.close();
}
查询不返回任何内容,甚至不返回列标题 它在Protege上正常工作并返回许多结果(包括DropBox)
我的代码有什么问题?

@andys我创建了一个新问题。您没有打印列标题,因此它们不会出现。使用ResultSetFormatter。该查询没有解决方案。至于原因,上面的片段没有足够的信息。检查数据。检查是否已加载。从一个简单的查询开始,比如
SELECT?Service{?Service:hasPriceModel?F}LIMIT 5
@AndyS当我分别运行?Service a:CloudService或?Service:hasPriceModel?F时,它会返回正确的答案。。。问题是当我试图在一个查询中组合两个条件时?服务a:CloudService?服务:hasPriceModel?F,不返回任何内容,尽管CloudService类的几个个体同时满足这两个条件,例如Dropbox。如果简单事物返回结果而{?服务a:CloudService。?服务:hasPriceModel?F}不返回,则数据中没有任何内容同时匹配这两个条件。检查您的数据。@andys我已经创建了新的问题。您没有打印列标题,因此它们不会出现。使用ResultSetFormatter。该查询没有解决方案。至于原因,上面的片段没有足够的信息。检查数据。检查是否已加载。从一个简单的查询开始,比如
SELECT?Service{?Service:hasPriceModel?F}LIMIT 5
@AndyS当我分别运行?Service a:CloudService或?Service:hasPriceModel?F时,它会返回正确的答案。。。问题是当我试图在一个查询中组合两个条件时?服务a:CloudService?服务:hasPriceModel?F,不返回任何内容,尽管CloudService类的几个个体同时满足这两个条件,例如Dropbox。如果简单事物返回结果而{?服务a:CloudService。?服务:hasPriceModel?F}不返回,则数据中没有任何内容同时匹配这两个条件。检查您的数据。