首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SPARQL CONCAT()和STR()与构造

SPARQL CONCAT()和STR()与构造
EN

Stack Overflow用户
提问于 2016-02-17 20:50:25
回答 1查看 4.6K关注 0票数 3

我正在使用SPARQL构造语句创建一个RDF图。以下是我的查询:

代码语言:javascript
复制
prefix map: <#> 
prefix db: <> 
prefix vocab: <vocab/> 
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
prefix xsd: <http://www.w3.org/2001/XMLSchema#> 
prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> 
prefix jdbc: <http://d2rq.org/terms/jdbc/>
prefix fn: <http://www.w3.org/2005/xpath-functions#> 

CONSTRUCT { 
map:database a fn:concat('d2rq:Database', ';').
map:database d2rq:jdbcDriver str(?o1).
map:database d2rq:jdbcDSN ?o2.
map:database d2rq:username ?o3.
map:database d2rq:password ?o4.
}
FROM <http://www.ndssl.vbi.vt.edu/epidl>
WHERE 
{ 
<http://www.ndssl.vbi.vt.edu/epidl#NDSSLDB> <http://www.ndssl.vbi.vt.edu/epidl#driver> ?o1.
<http://www.ndssl.vbi.vt.edu/epidl#NDSSLDB> <http://www.ndssl.vbi.vt.edu/epidl#dsn> ?o2.
<http://www.ndssl.vbi.vt.edu/epidl#NDSSLDB> <http://www.ndssl.vbi.vt.edu/epidl#username> ?o3.
<http://www.ndssl.vbi.vt.edu/epidl#NDSSLDB> <http://www.ndssl.vbi.vt.edu/epidl#password> ?o4.

}

}

我发现fn:concat()和str()函数不适用于SPARQL构造。查询给了我一个错误。但是,上面提到的函数在单独的select语句中正常工作,如下所示:

fn:concat()

代码语言:javascript
复制
prefix fn: <http://www.w3.org/2005/xpath-functions#> 
select (fn:concat('d2rq:jdbcDriver', ';') AS ?p) where {?s ?p ?o} LIMIT 1

斯塔尔()

代码语言:javascript
复制
select str(?o) from <http://www.ndssl.vbi.vt.edu/epidl> 
where {<http://www.ndssl.vbi.vt.edu/epidl#NDSSLDB> <http://www.ndssl.vbi.vt.edu/epidl#dsn> ?o}  

请让我知道如何在SPARQL构造中使用fn:concat()和str()函数。

EN

回答 1

Stack Overflow用户

发布于 2016-02-18 02:54:24

SPARQL查询中的CONSTRUCT子句只能包含图形模式。不能包括过滤器或函数。

要在构造查询结果中包含某些函数的输出,需要在WHERE子句中使用WHERE操作,该操作将函数输出分配给一个新变量,然后可以在CONSTRUCT子句中使用该新变量。

例如,要使用STR()函数的输出,可以执行如下操作:

代码语言:javascript
复制
CONSTRUCT { ?s ?p ?string }
WHERE {
        ?s ?p ?o .
        BIND(STR(?o) as ?string)
 }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35467458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档