【发布时间】: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