SPARQL:如何结合两个主题在CONSTRUCT中使用



我正在编写一个SPARQL查询,我正在创建一个RDF图。我正在使用SPARQL CONSTRUCT。作为我工作的要求,我必须连接两个主题值并将其与 CONSTRUCT语句一起使用。我尝试执行以下操作(我的RDF图在Virtuoso中):

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 {
?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE 
{ 
<http://www.ndssl.bi.vt.edu/fuse#DataSource> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
<http://www.ndssl.bi.vt.edu/fuse#OracleDataSource>  <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.ndssl.bi.vt.edu/fuse#DataSource>.
?DB <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>   <http://www.ndssl.bi.vt.edu/fuse#OracleDataSource>.
<http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
?Table <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>   <http://www.ndssl.bi.vt.edu/fuse#HouseholdsWithinAdminRegion>.
BIND(CONCAT(?DB, ?Table) AS ?p1)
}

但是,我收到以下错误:

Virtuoso RDF01 Error Bad variable value in CONSTRUCT: "http://www.ndssl.bi.vt.edu/fuse#PROTOPOPhttp://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1" (tag 246 box flags 0) is not a valid subject, only object of a triple can be a literal

请让我知道如何解决它。

错误基本上是说您正在连接两个 URI:

http://www.ndssl.bi.vt.edu/fuse#PROTOPOP
http://www.ndssl.bi.vt.edu/fuse#MIAMI_HOUSEHOLD_2009_1

变成文字。我不知道你到底想做什么,但你真的想连接整个 URI 还是只连接#后的最后一部分?如果要在#之后进行连接,则需要省略命名空间。

bind (concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:))) as ?p)

即使在此阶段,绑定的结果也是需要转换为 URI 的literal

bind (uri(concat(strafter(str(?s),str(fuse:)), strafter(str(?o),str(fuse:)))) as ?p)

通常,我会大大简化您的查询:

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
prefix fuse: <http://www.ndssl.bi.vt.edu/fuse#>
prefix owl:<http://www.w3.org/2002/07/owl#>
CONSTRUCT {
    ?p1 a d2rq:ClassMap
}
FROM <http://www.ndssl.bi.vt.edu/fuse>
WHERE 
{ 
    fuse:DataSource a owl:Class.
    fuse:OracleDataSource  rdfs:subClassOf fuse:DataSource.
    ?DB a   fuse:DataSource.
    fuse:HouseholdsWithinAdminRegion a owl:Class.
    ?Table a  fuse:HouseholdsWithinAdminRegion.
    bind (uri(concat(strafter(str(?DB),str(fuse:)), 
        strafter(str(?Table),str(fuse:)))) as ?p)
}

相关内容

  • 没有找到相关文章

最新更新