Bob MacGregor wrote:
Hi Lee,

OK, we'll try sparql dev, as long as this is a how to, rather than a "can't be
done".  But it looks to me like
your query returns no bindings if an article does not have a timetag.  I
say this because of the {?a ex:timetag ?maxtime} clause
that comes before the OPTIONAL.  But in that case, it should return
the article.  Can you fix this, or is it not expressible after all?

Right, I did that purposefully to concentrate on the "max" idiom. If you want to include articles with no timetag, it becomes:

PREFIX : <http://example.org/>
SELECT ?a
FROM <http://thefigtrees.net/lee/sw/data/times.ttl>
WHERE {
  ?a a :article .
  OPTIONAL {
    ?a :timetag ?maxtime .
    OPTIONAL {
      ?a :timetag ?othertime . FILTER(?othertime > ?maxtime)
    }
    FILTER (!bound(?othertime))
  }
  FILTER(!bound(?maxtime) || ?maxtime < 5)
}

The key is, I guess, to make the whole "find the max time" part optional and then filter outside that on "there is no maxtime or the maxtime is early enough".

(Note, I put some actual data at the above URL so that you can try this out. To do this I changed the predicate names a bit and used integers instead of datetimes for simplicity. I made "now" equal to 5. :-) ARQ deployed at http://sparql.org is a great place to try it.)

The data is:

@prefix : <http://example.org/> .

:onetimeOK a :article ; :timetag 1 .
:onetimeNotOK a :article ; :timetag 10 .
:twotimesOK a :article ; :timetag 1, 2 .
:twotimesNotOK a :article ; :timetag 1, 10 .
:notimeOK a :article .


... and when I run the above query through ARQ at sparql.org I get:

a:
        <http://example.org/notimeOK>
        <http://example.org/twotimesOK>
        <http://example.org/onetimeOK>


Lee



    In SPARQL, this query is (unedited, untested):

    SELECT ?a
    FROM :model
    WHERE {
      ?a rdf:type ft:article ; ex:timetag ?maxtime .
      OPTIONAL { ?a ex:timetag ?othertime . FILTER(?othertime > ?maxtime) }
      FILTER (!bound(?othertime) && ?maxtime > '...now...')
    }

    Original target:


SELECT ?a
FROM model
WHERE
     (?a rdf:type ft:Article) AND
     UNSAID ((?a ex:timetag ?time) AND
(?time > $NOW))
=====================================
Robert MacGregor
Chief Scientist
Siderean Software, Inc.
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
Mobile: 310-469-2810
=====================================

Reply via email to