I'm new to SPARQL and I'm trying to fetch some results from triples in a SQL join fashion.

e.g. I want to fetch the ID of the object a certain image belongs to, and the ID of the author of the object, and possibly more deeply chained relationships.

RDF relations are defined like this:

<image> <isResourceOf> <object> .
<person> <isAuthorOf> <object> .

I tried this:

SELECT ?o ?a 
  myns:myImageID myns:isResourceOf ?o .
  ?a myns:isAuthorOf ?o

But this doesn't fetch any results.


SELECT ?o ?a 
  { myns:myImageID myns:isResourceOf ?o . }
  { ?a myns:isAuthorOf ?o . }

fetches all the authors, since the two ?o variables are not linked together.

How do I get to match the authors ONLY for the first match set?

My RDF engine is Mulgara.

asked 31 Jul '13, 09:43

gattu%20marrudu's gravatar image

gattu marrudu
accept rate: 0%

closed 21 Aug '13, 09:05

Signified's gravatar image

Signified ♦

Thanks for the formatting fix Rob. There is one thing missing though: all the "myns:..." items should be enclosed in angle brackets as they are URIs. When I try to fix this, the preview window appears different from what shows up in the published post.

(31 Jul '13, 12:22) gattu marrudu gattu%20marrudu's gravatar image

This SPARQL is correct. cURIes (myns:blah) should not be wrapped in angle-brackets. only full URIs, http://..., should be wrapped in angle-brackets.

(31 Jul '13, 14:58) TallTed ♦ TallTed's gravatar image

Query seems fine - I presume there's a prefix definition somewhere. try a few simpler queries eg.

SELECT ?o WHERE { myns:myImageID myns:isResourceOf ?o . }

SELECT ?o ?a WHERE { ?a myns:isAuthorOf ?o . }

SELECT ?o ?a WHERE { myns:myImageID myns:isResourceOf ?o . ?s ?p ?o. }

The first two should check each part of the query and the third one should give you all the triples with ?o as an object - check if there is a myns:isAuthorOf in the ?p results

(31 Jul '13, 16:03) Sweet Burlap Sweet%20Burlap's gravatar image

@Sweet Burlap: I ran the queries you suggested and they return what you expected. Yes, the myns prefix is defined somewhere else. @TallTed: I get an error if I don't enclose the short URIs in angle brackets.

I think this might be an issue with how Mulgara implements SPARQL, which is not its native language.

(31 Jul '13, 16:39) gattu marrudu gattu%20marrudu's gravatar image

It seems unlikely to me that something this basic is not working in Mulgara's SPARQL implementation, but if so, you should contact the developers and let them know.

(31 Jul '13, 21:14) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image

I strongly suspect there's something wrong with the namespace prefix definition in your original query, and possibly in your simplified versions as well, given that you're getting errors if the cURIes are not angle-bracket-wrapped.

I suggest that you present complete information to us; else, we will be unable to usefully advise you.

(01 Aug '13, 12:50) TallTed ♦ TallTed's gravatar image

or forget about cURIs until its working - use the full angle wrapped URIs for now

(01 Aug '13, 16:01) Sweet Burlap Sweet%20Burlap's gravatar image

Found the problem: I did not include the full prefix to some relationship objects.

(04 Aug '13, 08:58) gattu marrudu gattu%20marrudu's gravatar image
showing 5 of 9 show 4 more comments

The question has been closed for the following reason "Question resolved by OP." by Signified 21 Aug '13, 09:05

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 31 Jul '13, 09:43

question was seen: 1,191 times

last updated: 21 Aug '13, 09:05