查询开放的RDF存储库

时间:2014-05-16 15:50:40

标签: rdf sparql sesame openrdf

我正在尝试查询加载了turtle文件的开放式RDF存储库。当我选择所有查询时 - " SELECT?s WHERE {?s?p?o}&#34 ;;然后一切正常,但当我使用一些复杂的查询时,它不起作用。我附加了查询部分的代码 -

private static void queryingRDF(Repository repo) {
    try{
        RepositoryConnection con = repo.getConnection();
        try{
            String queryString = "SELECT ?s  WHERE { ?s uml:lineOfBusiness cp:lobEQUITIES .}" ;
              TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);

              TupleQueryResult result = tupleQuery.evaluate();
              try {
                   while(result.hasNext()){
                        BindingSet bindingSet = result.next();
                        Value valueOfX = bindingSet.getValue("s");
                        //Value valueOfY = bindingSet.getValue("p");
                        //Value valueOfZ = bindingSet.getValue("o");
                        //System.out.println(valueOfX + "   " + valueOfY + "   " + valueOfZ);
                        System.out.println(valueOfX) ;
                   }

              }

              finally {
                  result.close();
              }
        }
        finally{
            con.close();
        }
    }
    catch(OpenRDFException e){
        System.out.println("Query error");
    }

}

这是不断进入异常部分并抛出错误 - "查询错误"。 什么是错的?

1 个答案:

答案 0 :(得分:2)

您似乎没有定义umlcp前缀。我在你的查询字符串中寻找这样的语句:

PREFIX uml: <http://example.com/uml>

或者像这样调用RepositoryConnection :: setNamespace:

con.setNamespace("uml", "http://example.com/uml");