在SPARQL查询中指定具有多个值的交点 [英] Specifying an intersection with multiple values in a SPARQL query

查看:85
本文介绍了在SPARQL查询中指定具有多个值的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个查询,该查询返回具有两个命名参与者的事件.这些参与者的姓名是使用名字和姓氏的值指定的. 到目前为止,这是我能够提出的唯一可行的解​​决方案:

I'm trying to build a query that returns events that have two named participants. The names of these participants are specified using values for the first name and last name. So far, this is the only working solution I have been able to come up with:

SELECT ?event
WHERE {
    ?event con:hasParticipant ?personA .
    ?personA con:hasFirstName "Bob"^^xsd:string .
    ?personA con:hasLastName "Smith"^^xsd:string .
    ?event con:hasParticipant ?personB .
    ?personB con:hasFirstName "The"^^xsd:string .
    ?personB con:hasLastName "Bear"^^xsd:string .
}

...但是我想知道是否有更好的方法?

...but I'm wondering if there is a better way of doing this?

任何帮助将不胜感激!

推荐答案

这几乎与缩小SPARQL查询,但在此条件中要寻找的人有更多特定条件(在另一条件中,任务是找到参与者,主持人或荣誉客人).那里的答案会有所帮助.在这种情况下,您可以使其更简单.您可以使用逗号分隔多个对象(例如,?event hasParticipant?p1,?p2 ).您可以使用空白节点来避免为人员绑定变量,并且可以(可能)消除字符串上的数据类型:

This is almost identical to Narrowing down on SPARQL query, except that there are more specific conditions on who you're looking for in this one (in the other one, the task was to find participants, moderators, or guests of honor). The answer there will help. In this case, you can make this a bit simpler. You can separate multiple objects with commas (e.g., ?event hasParticipant ?p1, ?p2). You can use blank nodes to avoid binding variables for the people, and you can (probably) eliminate the datatypes on the strings:

SELECT ?event {
    ?event con:hasParticipant [ con:hasFirstName "Bob" ;
                                con:hasLastName "Smith" ] ,
                              [ con:hasFirstName "The" ;
                                con:hasLastName "Bear" ] .
}

这篇关于在SPARQL查询中指定具有多个值的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆