简体   繁体   English

在sparql查询中使用联合

[英]use union in sparql query

I've got this SPARQL query between 2 DBpedia resources: France and Alstom 我在2个DBpedia资源之间得到了SPARQL查询:法国和阿尔斯通

select * where{
<http://dbpedia.org/resource/France> ?pre ?obj.

?obj ?pre1 <http://dbpedia.org/resource/Alstom>
}

and it returns nothing 它什么也没返回

but if I reverse the subject and the object like this: 但是如果我这样颠倒主题和对象:

select * where{
<http://dbpedia.org/resource/Alstom> ?pre ?obj.
?obj ?pre1 <http://dbpedia.org/resource/France>
}

the query returns some results.. 查询返回一些结果。

SPARQL Result SPARQL结果

is there any way to merge the two queries using UNION? 有什么办法可以使用UNION合并两个查询?

Based on your comment, you just need a straightforward union with the following syntax: 根据您的评论,您只需要使用以下语法的直接结合:

prefix dbpedia: <http://dbpedia.org/resource/>
select * where{
{
    dbpedia:France ?pre ?obj.
    ?obj ?pre1 dbpedia:Alstom.
}
Union {
    dbpedia:Alstom ?pre ?obj.
?obj ?pre1 dbpedia:France
}
}

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

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