[英]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一起使用。 查询给了我一个错误。 但是上面提到的函数适用于单独的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()函数。
SPARQL查询中的CONSTRUCT
子句只能包含图形模式。 不包括过滤器或功能。
要在CONSTRUCT查询结果中包含某些函数的输出,需要在WHERE
子句中使用BIND
操作将函数输出分配给新变量,然后可以在CONSTRUCT
子句中使用该新变量。
例如,要使用STR()
函数的输出,您可以执行以下操作:
CONSTRUCT { ?s ?p ?string }
WHERE {
?s ?p ?o .
BIND(STR(?o) as ?string)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.