1
1

Hello,

I'm progressing nicely with my project in RoR, but I'm having a bit of trouble to fine tune the query needed to retrieve information about a specific city or town. I'm relying on DBPedia, and the two test cases are Manchester (in the UK) and OsnaBrück (in Germany)

The idea is to make the query as generic as possible, because it's constructred through Ruby on Rails, so I need to be able to replace the search values later on through variables. The Query i'm trying to tune is this one:

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>

SELECT ?location ?abstract ?thumbnail 
WHERE 
{ 
  { 
    ?location foaf:label ?name .
    FILTER regex(?name, 'Osnabrück')
    ?location a dbo:Town .
  } 
  UNION 
  {  
    ?location a dbo:City;
              dbo:country <http://dbpedia.org/resource/Germany>
    { 
      ?location dbo:name ?name .
      FILTER regex(?name, 'Osnabrück') 
    } 
    UNION 
    {
       ?location foaf:name ?name .
       FILTER regex(?name, 'Osnabrück')
    }
  } 
  OPTIONAL { ?location dbo:thumbnail ?thumbnail . }
  OPTIONAL 
  {
    ?location dbo:abstract ?abstract . 
    FILTER langMatches(lang(?abstract), 'en')
  }
}

The idea behind the query is the following:

  • I have a variable that holds the name of the location
  • I have a variable that holds the URI of the country

I want to select any location that:

  • Is either a dbo:City in a given Country
  • With a specific name as foaf:name or dbo:name property
  • OR is either a dbo:Town
  • With a specific name as foaf:label

If I use the values 'Manchester' and &lt;http://dbpedia.org/resource/United_Kingdom> I'm able to select the City of Manchester in the United Kingdom, but when I use the values 'Osnabrück' and &lt;http://dbpedia.org/resource/Germany> I'm not able to select the town of Osnabrück, despite it having a page in dbpedia.

Could someone point out what I'm missing in my SPARQL query?

asked 24 Aug '11, 09:30

NekoNova's gravatar image

NekoNova
836
accept rate: 0%

edited 24 Aug '11, 11:20

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.5k715

@NekoNova If you're posting SPARQL queries can you use code formatting (the little icon with 1s and 0s) rather than quote formatting as it makes it far more readable, thanks :-)

(24 Aug '11, 11:21) Rob Vesse ♦ Rob%20Vesse's gravatar image

I did, I did, but I think it got a bit messed up with all the spaces & tabs in it :S

(24 Aug '11, 12:52) NekoNova NekoNova's gravatar image

Think I found it:

SELECT * WHERE
{
  ?location rdfs:label 'Osnabrück'@en ;
            a ?type .
  FILTER (?type = dbo:City || ?type = dbo:Town)
  OPTIONAL { ?location dbo:thumbnail ?thumbnail . }   
  OPTIONAL 
  { 
    ?location dbo:abstract ?abstract .
    FILTER langMatches(lang(?abstract),'en')
  }
}

Seems to do exactly what I want

link

answered 24 Aug '11, 10:10

NekoNova's gravatar image

NekoNova
836
accept rate: 0%

edited 24 Aug '11, 11:22

Rob%20Vesse's gravatar image

Rob Vesse ♦
13.5k715

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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

Tags:

×1,162
×244

Asked: 24 Aug '11, 09:30

Seen: 1,318 times

Last updated: 24 Aug '11, 12:52