0

I'm pretty new to SPARQL, I was wondering if it is possible to start at a URI, say dbpedia.org/resource/Steve_Jobs and then go through every URI linked to that start point, and return all names of every person he was linked to and limit it to 50 answers? I would have thought it would be possible to do this but I can't seem to find any resources on the web (maybe looking in the wrong place). So I guess the SPARQL query will be similar to a spider in the sense that it crawls through the links.

Any help much appreciated and thanks for your time.

daniel3412
  • 327
  • 1
  • 4
  • 13

1 Answers1

1

It depends what exactly you need. You can't do arbitrary recursive queries in SPARQL. See, for instance,

However, you do have access to property paths, which can include repetition. So you can do things like:

select ?person where {
  dbpedia:Steve_Jobs (<>|!<>)* ?person .
  ?person a dbpedia-owl:Person .
}
limit 10

Part of the trick here is that (<>|!<>) acts as a property wildcard, since every property is either <> or it isn't. That query, I think, should do roughly what you want. However, Virtuoso's SPARQL endpoint doesn't like it, and returns the error:

Virtuoso 37000 Error SP031: SPARQL compiler: Variable '_::trans_subj_4_0' is used in the query result set but not assigned

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 define input:default-graph-uri <http://dbpedia.org> select * where {
  dbpedia:Steve_Jobs (<>|!<>)* ?person .
  ?person a dbpedia-owl:Person .
}
limit 10

The query captures what you'd want it to, but you might have to check with the Virtuoso developers to figure out what to do to make it work. If you don't use the wildcard properties, then you'll get result, so if you have a particular set of properties that you care about, you could use it instead. E.g.,

select ?person where {
  dbpedia:Steve_Jobs (dbpedia-owl:child|dbpedia-owl:influenced|^dbpedia-owl:child|^dbpedia-owl:influenced)* ?person .
}
limit 10

SPARQL results

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353