【问题标题】:SPARQL CONCAT() and STR() with CONSTRUCTSPARQL CONCAT() 和 STR() 与 CONSTRUCT
【发布时间】:2016-02-17 20:50:25
【问题描述】:

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

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 CONSTRUCT。查询给了我一个错误。然而,上面提到的函数可以与单独的 select 语句一起正常工作,如下所示:

fn:concat()

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

str()

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 CONSTRUCT 中使用 fn:concat() 和 str() 函数。

【问题讨论】:

  • 你为什么要做 fn:concat?它应该只是连接。执行此操作的常用方法是带有选择子查询的构造查询。还有一些其他问题有有用的例子。
  • 使用选择子查询构造对我不起作用。你能举个例子吗?
  • 我认为其中一些问题有示例,但应该类似于construct { ?s :concatLabel ?labels } where {{ select ?s (group_concat(?label) as ?labels) { ?s rdfs:label ?label } group by ?s }}
  • @user2151087 与此特定问题没有直接关系,但我快速查看了您的个人资料,您在 StackOverflow 上提出了许多问题,但从未将您收到的任何答案标记为已接受.当然,是否这样做是您的选择,但也许您不知道这是一种选择。请参阅what to do if someone answers 了解更多信息。

标签: sparql rdf rdfs sparqlwrapper


【解决方案1】:

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

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

例如,要使用STR() 函数的输出,您可以这样做:

CONSTRUCT { ?s ?p ?string }
WHERE {
        ?s ?p ?o .
        BIND(STR(?o) as ?string)
 }

【讨论】:

  • 如果这回答了 OP 的问题,那么我真的认为这是其他问题之一的重复。
  • 可能,但我没有发现答案显示使用 BIND 的解决方案。如果你有一个我忽略的重复项,请随时投票关闭。
猜你喜欢
  • 1970-01-01
  • 2016-02-02
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-25
相关资源
最近更新 更多