简体   繁体   English

带有CONSTRUCT的SPARQL CONCAT()和STR()

[英]SPARQL CONCAT() and STR() with CONSTRUCT

I am creating an RDF graph by using SPARQL CONSTRUCT statement. 我正在使用SPARQL CONSTRUCT语句创建RDF图。 Following is my query: 以下是我的查询:

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.

}

} }

I have found that fn:concat() and str() functions are not working with SPARQL CONSTRUCT. 我发现fn:concat()和str()函数不能与SPARQL CONSTRUCT一起使用。 Query is giving me an error. 查询给了我一个错误。 However above mentioned functions works properly with separate select statements like followings: 但是上面提到的函数适用于单独的select语句,如下所示:

fn:concat() 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() 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}  

Please let me know how can I use fn:concat() and str() functions with SPARQL CONSTRUCT. 请告诉我如何在SPARQL CONSTRUCT中使用fn:concat()和str()函数。

The CONSTRUCT clause in a SPARQL query can only contain graph patterns. SPARQL查询中的CONSTRUCT子句只能包含图形模式。 Filters or functions can not be included. 包括过滤器或功能。

To include the output of some function in your CONSTRUCT query result, you need to use a BIND operation in your WHERE clause that assigns the function output to a new variable, and then you can use that new variable in your CONSTRUCT clause. 要在CONSTRUCT查询结果中包含某些函数的输出,需要在WHERE子句中使用BIND操作将函数输出分配给新变量,然后可以在CONSTRUCT子句中使用该新变量。

For example, to use the output of the STR() function, you'd do something like this: 例如,要使用STR()函数的输出,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM