gpt4 book ai didi

在 jena 中运行 sparql 查询时出现 java.lang.InstantiationError

转载 作者:行者123 更新时间:2023-11-30 07:23:24 24 4
gpt4 key购买 nike

亲爱的 friend 们,我正在使用 Jena 框架和 virtuoso 的 RDF 数据库模型在我的项目中。我的 jena 版本是 jena-core2.7.2 和 jena-arq-2.9.2

这是我的代码,它给我错误

public JsonArray getCountryAutoSuggestData()
{
JsonArray countryArray = new JsonArray();
Model model = DataModel.getModel();
String mystr = " PREFIX plcontologyurl:<http://www.plcontology.com/#> "
+ " PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "select ?cn"
+ " where "
+ " { "
+ " ?d plcontologyurl:Country_Name ?cn . "
+ "}";
Query query = QueryFactory.create(mystr);
QueryExecution qe = QueryExecutionFactory.create(query, model);
QuerySolutionMap qMap = new QuerySolutionMap();
qe.setInitialBinding(qMap);
ResultSet rs = qe.execSelect();
while(rs.hasNext())
{
qMap = (QuerySolutionMap)rs.next();
countryArray.add(new JsonPrimitive(qMap.getLiteral("cn").getString()));
}
return countryArray;
}

错误是java.lang.InstantiationError: com.hp.hpl.jena.sparql.engine.binding.BindingMap 在线while(rs.hasNext())

我尝试查找问题并找到一个 relevant discussion

他们说现在 com.hp.hpl.jena.sparql.engine.binding.BindingMap 不是一个简单的这个版本现在是类,但现在是一个接口(interface)。

如果是这样,那么如何在当前版本中运行 sparql 查询。请根据我分享的代码举一个例子。提前致谢。

最佳答案

您在类路径上混合了多个版本。

您链接到的信息是正确的 - BindingMap 成为一个接口(interface),因此如果您看到 java.lang.InstantiationError,则表示调用代码来自早期版本的 ARQ。

检查您在类路径中没有超过一份 Jena 代码副本,并且在 JVM 认可的目录中没有副本。

关于在 jena 中运行 sparql 查询时出现 java.lang.InstantiationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12036674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com