2016-02-17 32 views
1

我正在使用SPARQL CONSTRUCT语句创建RDF图。以下是我的查询:SPARQL CONCAT()和STR()with CONSTRUCT

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:但是上述功能与独立select语句像以下正常工作()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} 

请让我知道我可以使用FN:CONCAT ()和str()函数与SPARQL构造。

+0

你为什么要这么做FN:CONCAT?它应该是concat。通常的做法是使用select子查询构造查询。还有一些其他问题有很好的例子。 –

+1

例如,请参阅http://stackoverflow.com/questions/33475950/use-aggregates-min-max-avg-in-construct-query –

+0

构建select select子查询不适用于我。你能否给我举个例子? –

回答

3

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

为了在你构造查询结果的一些函数的输出,需要在指定的输出功能,以一个新的变量您WHERE子句中使用一个BIND操作,然后你可以使用新的变量在您的CONSTRUCT条款。

例如,使用STR()函数的输出,你会做这样的事情:

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

如果这回答OP的问题,那么我真的认为这是其他问题之一的重复。 –

+0

可能,但我没有发现答案显示BIND解决方案的地方。我有一个我忽略的重复,随时可以投票结束。 –