gpt4 book ai didi

sparql - SPARQL 查询中两个选择的并集

转载 作者:行者123 更新时间:2023-12-02 04:22:37 27 4
gpt4 key购买 nike

我想做一些类似的事情

{
SELECT ?page, "A" AS ?type WHERE
{
?s rdfs:label "Microsoft"@en;
foaf:page ?page
}
}
UNION
{
SELECT ?page, "B" AS ?type WHERE
{
?s rdfs:label "Apple"@en;
foaf:page ?page
}
}

但这会产生语法错误。如何在 SPARQL 中联合两个选择查询?

最佳答案

你可以像这样联合它们:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT * WHERE
{
{
SELECT ?page ("A" AS ?type) WHERE
{
?s rdfs:label "Microsoft"@en;
foaf:page ?page
}
}
UNION
{
SELECT ?page ("B" AS ?type) WHERE
{
?s rdfs:label "Apple"@en;
foaf:page ?page
}
}
}

(检查 SPARQL validator )

但是,我认为在这种情况下您根本不需要子查询。例如:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?page ?type WHERE
{
?s foaf:page ?page .
{ ?s rdfs:label "Microsoft"@en . BIND ("A" as ?type) }
UNION
{ ?s rdfs:label "Apple"@en . BIND ("B" as ?type) }
}

关于sparql - SPARQL 查询中两个选择的并集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796978/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com