Jena语法中的SPARQL查询

时间:2017-01-26 02:32:53

标签: sparql jena semantic-web

我有这个SPARQL查询在Protege SPARQL选项卡中运行正常,但它在Jena代码中不起作用。 如果有人用正确的Jena语法提供它,因为我从未在Jena代码中使用嵌套的SELECT子句。

SELECT ?student ?topScore WHERE {
   {
    SELECT (MAX(?score) AS ?topScore) WHERE {
         ?student dd:EnglishPercentage ?score .
    }
   }
    ?student dd:EnglishPercentage  ?topScore .
}

1 个答案:

答案 0 :(得分:0)

这是整个查询。我使用的是Jena的3.x版本

String queryString2 = 
                   "prefix dd:<http://www.semanticweb.org/t/ontologies/2016/7/myOWL#>"+
         "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> "  +

          "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
                     "SELECT  ?student ?highScore " +
          " WHERE {" + " {"+ "select  (max(?score) as ?highScore)" + " { ?student dd:Englishscore ?score" + 
" }" +
"  } " +Englishscore ?highScore"   +     
         "}";    
Query query2 = QueryFactory.create(queryString2);
QueryExecution qexec = QueryExecutionFactory.create(query2, model) ;
ResultSet results2 = qexec.execSelect() ;

Literal r= results2.next().get("highScore").asLiteral();
    JOptionPane.showMessageDialog(null,r.toString());