查询Jena TDB商店 [英] Query Jena TDB store

查看:174
本文介绍了查询Jena TDB商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在java中查询jena TDB。我的代码如下。我的TDB数据集似乎是空的,因为 model.size()(其中 model 是数据集的默认模型)返回0.我确定它不是空的,因为我可以用Fuseki用我的sparqlEndpoint查询它。

I'm trying to query jena TDB in java. My code follows. It seems that my TDB dataset is empty because model.size() (where model is the dataset default model) return 0. I'm sure it isn't empty, though, because I can query it with Fuseki with my sparqlEndpoint.

String directory = "//var//www//fuseki//TDB" ;
Dataset dataset = TDBFactory.createDataset(directory) ;

Model model  = dataset.getDefaultModel();
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;

Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, model);

ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(results) ;

qexec.close();
System.err.printf("Model size is: %s\n", model.size());


推荐答案


这似乎是我的TDB是空的,因为model.size()返回0.我确定
不为空,因为我可以使用fuseki和我的sparqlEndpoint查询它。

It's seems my TDB is empty because model.size() return 0. I'm sure it isn't empty because I can query it with fuseki with my sparqlEndpoint.

没有内容就可以存在。字符串的长度为0,但它仍然是一个字符串。您没有显示查询结果

Things can exist without having contents. The length of the string "" is 0, but it's still a string. You didn't show the results of your query

SELECT (count(*) AS ?count) { ?s ?p ?o }

它返回0还是别的?此外,当你这样做时

Did it return 0, or something else? Also, when you do

Model model  = dataset.getDefaultModel();

您只获取数据集的默认模型,但数据集可以包含多个命名数据集图表,以及默认图表。如果您的数据集中有三元组,它们可能位于命名图形中,在这种情况下,您可以执行类似

you're only getting the default model of the dataset, but a dataset can contain a number of named graphs, in addition to the default graph. If you do have triples in your dataset, they might be in named graphs, in which case you could do something like

select (count(*) as ?count) { graph ?g { ?s ?p ?o } }

我不知道Fuseki如何处理默认图形,但可能是数据集的默认图形(我认为可以自定义)被配置为命名图形的联合数据集。在这种情况下, getDefaultModel 的结果可能仍然是空模型。我正在推测这一点,但是这是一种可以想象的方式,你可以从默认图表中获得结果,同时仍然将默认模型设为空。

I don't know offhand how Fuseki handles the default graph, but it might be that the default graph of the dataset is configured (I think this can be customized) to be the union of the named graphs in the dataset. When that's the case, the result of getDefaultModel might still be an empty model. I'm speculating on that point, but it's a conceivable way that you could get results from the default graph while still having the default model be empty.

这篇关于查询Jena TDB商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆