简体   繁体   中英

SPARQL CONCAT() and STR() with CONSTRUCT

I am creating an RDF graph by using SPARQL CONSTRUCT statement. 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. Query is giving me an error. However above mentioned functions works properly with separate select statements like followings:

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}  

Please let me know how can I use fn:concat() and str() functions with SPARQL CONSTRUCT.

The CONSTRUCT clause in a SPARQL query can only contain graph patterns. 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.

For example, to use the output of the STR() function, you'd do something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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