如何使用sparql查询从本体显示特定的个体?

时间:2016-06-04 05:25:33

标签: sparql

实际上我想显示同一类型的3个人以及他们的数据类型。我尝试了一些代码,但它仍然无效。哪里可能是错的?

这里是我的jsp文件中的代码

<%
            model=FileManager.get().loadModel("data.rdf");
            out.print("<tr><th scope='row'><b>Sarapan Pagi</b></th>");
            out.print("<th scope='row'>");
            queryString=
                    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax=ns#>"+
                    "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +        
                    "prefix owl: <http://www.w3.org/2002/07/owl#>" +
                    "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>"  +
                    "prefix ab: <http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#>"  +

                    "SELECT ?x   " +
                    "WHERE{"+
                    " ?x rdf:type ab:KumpBijirin." +
                    " FILTER (? x= :BiskutKrimKraker)." + 
                    "}";

                    query=QueryFactory.create(queryString);
                    qexec=QueryExecutionFactory.create(query,model);
                    try{
                        ResultSet results=qexec.execSelect();

                        while (results.hasNext()){
                            QuerySolution soln=results.nextSolution();
                            Literal name=soln.getLiteral("x");
                            out.print(name);

                        }
                    }finally{
                        qexec.close();
                    }out.print("</th></tr>"); %>

这是我的一些data.rdf文件。

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AcarTimun">
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpSayur"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuHidanganSampingan"/>
    <hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">33.3</hasKalori>
    <hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">7.7</hasKarbohidrat>
    <hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.2</hasLemak>
    <hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.7</hasProtein>
    <hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1hidangan</hasSaizHidangan>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AirKosong -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AirKosong">
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMinumMalam"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMinumPagi"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuMinuman"/>
    <hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasKalori>
    <hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasKarbohidrat>
    <hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasLemak>
    <hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasProtein>
    <hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#float">1gelas</hasSaizHidangan>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#Anggur -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#Anggur">
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpBuah"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuPencuciMulut"/>
    <hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">63.2</hasKalori>
    <hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">15.0</hasKarbohidrat>
    <hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.0</hasLemak>
    <hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.8</hasProtein>
    <hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">8biji</hasSaizHidangan>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AsamLaksaPenang -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#AsamLaksaPenang">
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanMalam"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#JenisMakanTengahHari"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#KumpBijirin"/>
    <rdf:type rdf:resource="http://www.semanticweb.org/user/ontologies/2016/3/untitled-ontology-23#MenuHidanganUtama"/>
    <hasKalori rdf:datatype="http://www.w3.org/2001/XMLSchema#float">432.0</hasKalori>
    <hasKarbohidrat rdf:datatype="http://www.w3.org/2001/XMLSchema#float">53.0</hasKarbohidrat>
    <hasLemak rdf:datatype="http://www.w3.org/2001/XMLSchema#float">2.0</hasLemak>
    <hasProtein rdf:datatype="http://www.w3.org/2001/XMLSchema#float">21.1</hasProtein>
    <hasSaizHidangan rdf:datatype="http://www.w3.org/2001/XMLSchema#int">1mangkuk</hasSaizHidangan>
</owl:NamedIndividual>

0 个答案:

没有答案