2

如果我连接cxn到一个空的 Triplestore,我会说:

val CheckSparql = "select (count(?s) as ?scount) where { ?s ?p ?o . }"

val PreparedSparql = cxn.prepareTupleQuery(QueryLanguage.SPARQL, CheckSparql)
val Result = PreparedSparql.evaluate()
val ResBindSet = Result.next()
val TripleCount = ResBindSet.getValue("scount")

println(TripleCount.toString())

我明白了

"0"^^<http://www.w3.org/2001/XMLSchema#integer>

是否有一种 RDF4J 方法可以仅检索该文字的值?

我只想要 0 或“0”,没有数据类型

我想如果可能的话,我应该尝试在没有字符串操作/正则表达式的情况下做到这一点。

4

1 回答 1

2

Literals util 类是你的朋友:

int scount = Literals.getIntValue(ResBindSet.getValue("scount"))

或者如果您更喜欢字符串:

String scount =  Literals.getLabel(ResBindSet.getValue("scount"))

您还可以选择添加一个备用参数,例如,如果提供的参数结果不是文字。

于 2017-10-26T00:05:01.293 回答