SPARQL CONCAT() and STR() with CONSTRUCT



我正在使用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一起使用。查询给我一个错误。但是,上述函数可以与单独的选择语句一起正常工作,如下所示:

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}  

请让我知道如何将 fn:concat() 和 str() 函数与 SPARQL CONSTRUCT一起使用。

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

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

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

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

最新更新