SPARQL 中的幂(指数)和其他数学函数支持
我正在尝试编写一个 SPARQL 查询,我想在其中过滤某个值的平方,但我根本无法弄清楚如何计算数字的平方 (x2) (当然,除了与自身相乘之外)。我猜想有一个名为 math:sqrt()
的平方根函数可以工作,但像 math:pow
这样的函数似乎不存在。
如何在 SPARQL 中获取某个值的平方,更重要的是,我在哪里可以阅读有关它以及 SPARQL 中的其他数学函数(例如 math:sqrt
)的信息?
注意:这与我之前的问题有关:反向维基百科地理标记查找。
I am trying to write a SPARQL query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x2) (except by multiplying it with itself, of course). I guessed a square root function called math:sqrt()
which works, yet nothing like math:pow
seems to exist.
How do I get the square of something in SPARQL and, more importantly, where can I read about it and other math functions such as math:sqrt
in SPARQL?
Note: This is related to my previous question: Reverse wikipedia geotagging lookup .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几年过去了,SPARQL 1.1 查询语言已经发布。它包含比原始 SPARQL 查询语言更多的内置函数。除了字符串、RDF 术语等方面的大量函数之外,还有许多数字函数(部分编号表示链接标准中的部分):
这里仍然没有
square
函数,最快的实现方法是使用*
,所以 laalto 的答案仍然有效。 17.3 运算符映射中描述了 SPARQL 支持的运算符,以及 XPath算术仍然只是+
、-
、*
和/
的集合。It's now a few years later and the SPARQL 1.1 Query Language has been published. It includes many more built-in functions than the original SPARQL query language. In addition to lots of functions on strings, RDF terms, &c., there are a number of numeric functions (the section numbers indicate the section in the linked standard):
There's still no
square
function here, and the quickest way to implement that will be using*
, so laalto's answer still stands. The operators that SPARQL supports are described in 17.3 Operator Mapping, and for XPath arithmetic is still just the set of+
,-
,*
, and/
.SPARQL 支持一些 XPath 算术函数,例如
+ - * /
。它们在 SPARQL 规范中进行了描述。规格不支持电源功能。无论如何,
x*x
是比pow(x,2)
更有效的平方计算方法。SPARQL supports some XPath arithmetic functions such as
+ - * /
. They are described in the SPARQL spec.The power function is not supported by the spec. And in any case
x*x
is more efficient way to compute squares thanpow(x,2)
would be.