Thomas,

I've also tried to write the query in pure SPARQL but failed.
I'm afraid that in that case you need SPARQL-BI extensions, not pure
SPARQL. Like this:

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?yr ?name ?document
WHERE {
    ?document rdf:type ?class ;
      dc:creator ?author ;
      dcterms:issued ?yr .
    ?class rdf:type foaf:Document .
    ?author foaf:name ?name .
      { select ?author (min (?yr2)) as ?yr
        where {
            ?document2 rdf:type ?class2 ;
              dc:creator ?author ;
              dcterms:issued ?yr2 .
            ?class2 rdf:type foaf:Document } }
  }

Or even shorter (but more obfuscated)

SELECT ?yr ?author+>foaf:name ?document
WHERE {
    ?document a [ a foaf:Document ] ;
      dc:creator ?author ;
      dcterms:issued ?yr .
      { select ?author (min (?document2+>dcterms:issued)) as ?yr
        where {
            ?document2 a [ a foaf:Document ] ;
              dc:creator ?author } }
  }

Note: I've written these queries but not tested.

Best Regards,

Ivan Mikhailov,
OpenLink Software.

On Thu, 2008-02-21 at 17:09 +0100, Thomas Hornung wrote:
> Hello Ivan,
> 
> I am sorry. To make the problem easier to spot I simplified our query 
> somewhat. The original query is as follows:
> 
> SELECT ?yr ?name ?document
> WHERE {
>    ?class rdf:type foaf:Document.
>    ?document rdf:type ?class.
>    ?document dcterms:issued ?yr.
>    ?document dc:creator ?author.
>    ?author foaf:name ?name.
>    OPTIONAL {
>      ?class2 rdf:type foaf:Document.
>      ?document2 rdf:type ?class2.
>      ?document2 dcterms:issued ?yr2.
>      ?document2 dc:creator ?author2.
>      FILTER (?author=?author2 && ?yr2<?yr).
>    }
>    FILTER (!bound(?author2)).
> }
> 
> 
> 
> Here pushing the filter outside the OPTIONAL clause is not a viable option.
> 
> Cheers,
> Thomas
> 
> 
> 
> Ivan Mikhailov schrieb:
> > Thomas,
> > 
> > Yes, this is an intentional parser error. To make the FILTER condition
> > meaningful, it should reside outside OPTIONAL, like this:
> > 
> > PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> > PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> > PREFIX dc: <http://purl.org/dc/elements/1.1/>
> > PREFIX dcterms: <http://purl.org/dc/terms/>
> > 
> > SELECT ?name1 ?name2 ?document
> > FROM <http://my_graph>
> > WHERE {
> >    ?document dc:creator ?author1.
> >    ?author1 foaf:name ?name1.
> >    OPTIONAL {
> >      ?document dc:creator ?author2.
> >      ?author2 foaf:name ?name2.
> >    }
> >    FILTER (?author1!=?author2) .
> > }
> > 
> > Variable ?author1 is never bound inside the OPTIONAL clause, so FILTER 
> > (?author1!=?author2) does not differ from
> > FILTER (?any_unused_variable_name != ?author2) . This is probably not what 
> > do you want.
> > Semantics of SPARQL FILTER condition differs from semantics of SQL WHERE 
> > condition.
> > We've decided that error message that violates The Spec is better than 
> > running query that match The Spec in an unusual way.
> > 
> > You can add additional compile-time checks by placing
> > define sql:signal-void-variables 1
> > line at the very beginning of the SPARQL statement (before all PREFIX and 
> > BASE declarations if present).
> > 
> > Best Regards,
> > 
> > Ivan Mikhailov,
> > OpenLink Software.
> > 
> > On Tue, 2008-02-19 at 16:14 +0100, Thomas Hornung wrote:
> >> Hi,
> >>
> >> I have seen in a recent post a question regarding the SPARQL conformance 
> >> of Virtuoso. There you said, that "Virtuoso SPARQL does not match W3C 
> >> recommendation 100%".
> >>
> >> Right now I get a parser error message for a query, which is answered by 
> >> other SPARQL engines correctly.
> >>
> >> Is the parser error intentional or a bug?
> >>
> >> Here the query:
> >>
> >> PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> >> PREFIX dc: <http://purl.org/dc/elements/1.1/>
> >> PREFIX dcterms: <http://purl.org/dc/terms/>
> >>
> >> SELECT ?name1 ?name2 ?document
> >> FROM <http://my_graph>
> >> WHERE {
> >>    ?document dc:creator ?author1.
> >>    ?author1 foaf:name ?name1.
> >>    OPTIONAL {
> >>      ?document dc:creator ?author2.
> >>      ?author2 foaf:name ?name2.
> >>      FILTER (?author1!=?author2).
> >>    }
> >> }
> >>
> >> This is the error message:
> >>
> >> *** Error 37000: [Virtuoso Driver][Virtuoso Server]SQ074: Line 17 (...): 
> >> SP031: SPARQL compiler: Variable 'author1' is used in subexpressions of 
> >> the query but not assigned at ';' immediately before end of statement...
> >>
> >>
> >> Thanks in advance,
> >> Thomas
> >>
> >>
> >> -------------------------------------------------------------------------
> >> This SF.net email is sponsored by: Microsoft
> >> Defy all challenges. Microsoft(R) Visual Studio 2008.
> >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> >> _______________________________________________
> >> Virtuoso-users mailing list
> >> Virtuoso-users@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/virtuoso-users
> > 
> 
> 
> -- 
> --------------------------------------------------------------------------
> Dipl.-Inf. Thomas Hornung
> 
> Institute of Computer Science
> Albert-Ludwigs University
> Georges-Koehler-Allee, Building 051, Room 01-028
> D-79110 Freiburg im Breisgau
> 
> phone:  +49 (761) 203-8128
> fax:    +49 (761) 203-8122
> e-mail: hornu...@informatik.uni-freiburg.de
> web:    http://dbis.informatik.uni-freiburg.de/index.php?person=hornungt/
> --------------------------------------------------------------------------
> 


Reply via email to