我正在使用SPARQL构造语句创建一个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构造。查询给了我一个错误。但是,上面提到的函数在单独的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斯塔尔()
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()函数。
发布于 2016-02-18 02:54:24
SPARQL查询中的CONSTRUCT子句只能包含图形模式。不能包括过滤器或函数。
要在构造查询结果中包含某些函数的输出,需要在WHERE子句中使用WHERE操作,该操作将函数输出分配给一个新变量,然后可以在CONSTRUCT子句中使用该新变量。
例如,要使用STR()函数的输出,可以执行如下操作:
CONSTRUCT { ?s ?p ?string }
WHERE {
?s ?p ?o .
BIND(STR(?o) as ?string)
}https://stackoverflow.com/questions/35467458
复制相似问题