简体   繁体   English

如何在SPARQL上进行子查询或合并某些查询?

[英]How to subquery or combine some queries on SPARQL?

I'm looking to create a Query on SPARQL to find all alerts which the creation date is superior to the alert whose identified by _messageid = "58002774-4fea-11e4-BDAC" (i Don't know its creation date). 我正在寻找一个在SPARQL上创建查询的查询,以查找所有创建日期均优于_messageid =“ 58002774-4fea-11e4-BDAC”标识的警报的警报(我不知道其创建日期)。

I tested queries below and work fine : 我在下面测试了查询并正常工作:

Query 1 : Display all the alerts and their creation date : 查询1:显示所有警报及其创建日期:

SELECT ?a ?ct
WHERE {
  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?ct.
}

Query 2 : Display the creation date of the alert that is identified by _messageid = "58002774-4fea-11e4-BDAC": 查询2:显示由_messageid =“ 58002774-4fea-11e4-BDAC”标识的警报的创建日期:

SELECT ?a ?ct
WHERE {
  ?a :_messageid "58002774-4fea-11e4-bdac".
  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?ct.
}

Query 3 : Display all alertes having creation date superior to the date "2014-10-09T15:15:00": 查询3:显示所有创建日期早于“ 2014-10-09T15:15:00”的警报:

SELECT ?a ?ct
WHERE {
  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?ct.
  FILTER ( xsd:dateTime(?ct) > xsd:dateTime("2014-10-09T15:15:00") ).
}

the problem is that i don't knew how to combine them to resolve my problem ( find all alerts which the creation date is superior to the alert whose identified by _messageid = "58002774-4fea-11e4-BDAC" ) 问题是我不知道如何结合使用它们来解决我的问题( 找到所有创建日期都优于_messageid =“ 58002774-4fea-11e4-BDAC”的警报的警报

I tested some request (described below) by they don't work : 我测试了一些请求(如下所述),因为它们不起作用:

Query 4 : 查询4:

SELECT ?a ?ct
WHERE {
  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?ct.
  FILTER ( xsd:dateTime(?ct) > {SELECT ?ct2 WHERE { ?a2 :_messageid "58002774-4fea-11e4-bdac". ?a2 :CreateTimeSlot ?cts2. ?cts2 :Text ?ct2 } } )
}

Query 5 : 查询5:

SELECT ?a ?ct
WHERE {
  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?ct.
  FILTER ( xsd:dateTime(?ct) > xsd:dateTime({SELECT ?ct2 WHERE { ?a2 :_messageid "58002774-4fea-11e4-bdac". ?a2 :CreateTimeSlot ?cts2. ?cts2 :Text ?ct2 } }) )
}

Query 6 : 查询6:

SELECT ?a
WHERE
{
  {
    SELECT ?a ?ct1
    WHERE
    {
      ?a :CreateTimeSlot ?cts.
      ?cts :Text ?ct1.
    }
    GROUP BY ?a 
  }.
  {
    SELECT ?a ?ct2
    WHERE
    {
      ?a :_messageid "58002774-4fea-11e4-bdac".
      ?a :CreateTimeSlot ?cts.
      ?cts :Text ?ct2.
    }
    GROUP BY ?a
  }.
  FILTER (xsd:dateTime(?ct1) > xsd:dateTime(?ct2)). 
}

Update 更新

It sounds like you want to retrieve the creation date for the element with the specified messageId, and then get all the elements with a later creation date. 听起来您想检索具有指定messageId的元素的创建日期,然后获取具有更高创建日期的所有元素。 That's just this: 就是这样:

SELECT ?a ?cts ?dc
WHERE {
  ?x :CreateTimeSlot ?y.
  ?y :_messageid "58002774-4fea-11e4-bdac".
  ?y :Text ?xdate.

  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?dc.
  FILTER ( xsd:dateTime(?dc) > xsd:dateTime(?xdate) ).
}

That can be be cleaned up a bit with some blank nodes: 可以使用一些空白节点来清除它:

SELECT ?a ?cts ?dc
WHERE {
  [] :CreateTimeSlot [ :_messageid "58002774-4fea-11e4-bdac" ;
                       :Text ?xdate ] .

  ?a :CreateTimeSlot ?cts.
  ?cts :Text ?dc.
  FILTER ( xsd:dateTime(?dc) > xsd:dateTime(?xdate) ).
}

and if you don't need the ?cts , you can simplify as before with: 如果不需要?cts ,则可以像以前一样简化:

SELECT ?a ?cts ?dc
WHERE {
  [] :CreateTimeSlot [ :_messageid "58002774-4fea-11e4-bdac" ;
                       :Text ?xdate ] .

  ?a :CreateTimeSlot/:Text ?dc.
  FILTER ( xsd:dateTime(?dc) > xsd:dateTime(?xdate) ).
}

Original 原版的

If I understand what you're trying to do, it's just this: 如果我了解您要做什么,就是这样:

SELECT ?a ?cts ?dc
WHERE {
  ?a :CreateTimeSlot ?cts.
  ?a :_messageid "58002774-4fea-11e4-bdac".
  ?cts :Text ?dc.
  FILTER ( xsd:dateTime(?dc) > xsd:dateTime("2014-10-09T15:15:00") ).
}

There was a little bit of confusion about whether the value of the text property was going to be called ?dc or ?ct , so I went with ?dc . 关于text属性的值将被称为?dc还是?ct有点困惑,所以我选择了?dc

There are actually a few ways to clean this up, though. 但是,实际上有几种方法可以解决此问题。 This is just a matter of style, but I'd probably write this as (note the ; syntax to select multiple properties on ?a and the xsd:dateTime literal in the comparison): 这只是一个样式问题,但我可能会这样写(请注意;语法,以选择?a上的多个属性以及比较中的xsd:dateTime文字):

SELECT ?a ?cts ?dc
WHERE {
  ?a :CreateTimeSlot ?cts ; 
     :_messageid "58002774-4fea-11e4-bdac".
  ?cts :Text ?dc
  FILTER ( xsd:dateTime(?dc) > "2014-10-09T15:15:00"^^xsd:dateTime )
}

If you don't actually need the ?cts value, you can simplify this even more: 如果您实际上不需要?cts值,则可以进一步简化它:

SELECT ?a ?cts ?dc
WHERE {
  ?a :CreateTimeSlot/:Text ?dc ;
     :_messageid "58002774-4fea-11e4-bdac".
  FILTER ( xsd:dateTime(?dc) > "2014-10-09T15:15:00"^^xsd:dateTime )
}

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

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