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

时间:2016-02-29 07:15:04

标签: 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="&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();
                }

查询不返回任何内容,甚至不返回列标题 虽然它在Protege上正常工作并返回许多结果(包括DropBox) 我的代码出了什么问题?

0 个答案:

没有答案