Re: query RDF dataset

Jitao,

I have not totally checked your query. My impression is, however, that you
have made the query unnecessarily complex in its logic. You have claimed too
many free variables for a fairly simple request. Therefore, the entire logic
just becomes nearly untraceable. In analogy, what you have done is to have
used a dozen of "no"s in a sentence; to the end, nearly nobody really knows
whether you mean "no" or "yes".

In particular, please also be aware that in RDF and SPARQL, there is no
difference between when you say "?author dc:country ?country . " or ?bookURI
dc:author ?author2 ." There are too many ambiguities in your query.

Just rewrite your query in the following way.

return: all the books which have no authors UNION all the books which have
authors while every author must have its country be Italy

good luck,

yihong





On Tue, Jun 2, 2009 at 3:51 AM, Jitao Yang <jitao.yang@gmail.com> wrote:

> Dear all,
>
> if I have an RDF file like:
>
> <?xml version="1.0" encoding="utf-8"?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>          xmlns:dc="http://purl.org/dc/elements/1.1/"
>      xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
>
>     <rdf:Description rdf:about="http://example.org/BookJava">
>         <vcard:fullname>Book Java</vcard:fullname>
>         <dc:author>
>             <rdf:Description rdf:about="
> http://example.org/BookJava/authorA">
>                  <dc:fullname>Bob Smith</dc:fullname>
>                  <dc:country>Italy</dc:country>
>              </rdf:Description>
>         </dc:author>
>         <dc:author>
>             <rdf:Description rdf:about="
> http://example.org/BookJava/authorB">
>                  <dc:fullname>Tom Bush</dc:fullname>
>                  <dc:country>Italy</dc:country>
>             </rdf:Description>
>         </dc:author>
>     </rdf:Description>
>
>     <rdf:Description rdf:about="http://example.org/BookCpp">
>         <vcard:fullname>Book Cpp</vcard:fullname>
>         <dc:author>
>             <rdf:Description rdf:about="http://example.org/BookCpp/author2
> ">
>                  <dc:fullname>Mike Luck</dc:fullname>
>                  <dc:country>France</dc:country>
>             </rdf:Description>
>         </dc:author>
>         <dc:author>
>             <rdf:Description rdf:about="http://example.org/BookCpp/author1
> ">
>                  <dc:fullname>Alice Bird</dc:fullname>
>                  <dc:country>Italy</dc:country>
>             </rdf:Description>
>         </dc:author>
>         <dc:author>
>             <rdf:Description rdf:about="
> http://example.org/BookJava/authorB">
>                  <dc:fullname>kobe Mc</dc:fullname>
>                  <dc:country>Italy</dc:country>
>              </rdf:Description>
>         </dc:author>
>     </rdf:Description>
>
>     <rdf:Description rdf:about="http://example.org/BookC">
>         <vcard:fullname>Book C</vcard:fullname>
>     </rdf:Description>
>
> </rdf:RDF>
>
> I want to query "the books whose authors are all Italian" or "the books
> which have no authors",
> so I use SPARQL like:
>
>             PREFIX dc:<http://purl.org/dc/elements/1.1/>
>              PREFIX vcard:<http://www.w3.org/2001/vcard-rdf/3.0#>
>             SELECT DISTINCT ?bookName
>             WHERE {
>                     ?bookURI vcard:fullname ?bookName .
>                     OPTIONAL{
>                             ?bookURI dc:author ?author .
>                             ?author dc:country ?country .
>                             FILTER(?country = \"Italy\") .
>                             OPTIONAL{
>                                     ?bookURI dc:author ?author2 .
>                                     ?author2 dc:country ?country2 .
>                                     FILTER(?country2 != \"Italy\")
>                                     }
>                             FILTER(bound(?country2))
>                             }
>                     FILTER(!bound(?author))
>                   }
>
> I can get the right answers:
> ---------------
> | bookName    |
> ===============
> | "Book C"    |
> | "Book Java" |
> ---------------
> but, my original idea is FILTER(!bound(?country2)) which means filter the
> books which have non-Italian authors,
> however if I use  FILTER(!bound(?country2)), it will return the opposite
> answers:
> --------------
> | bookName   |
> ==============
> | "Book C"   |
> | "Book Cpp" |
> --------------
> I can not understand the reasons?
>
> Thank you very much for your help to explain to me.
>
> Best wishes,
> Jitao
>



-- 
===================================
Yihong Ding

http://yihongs-research.blogspot.com/

Received on Tuesday, 2 June 2009 13:20:05 UTC