1

I'm trying to grab some definition in dbpedia inside my thesaurus.

Although can find country that have a label that match my country, i don't get all of them. So i try to match similar label with contains but it does not work.

Any idea why.

SELECT distinct ?idbcountry ?label ?labelDb ?def

WHERE {

            ?idbcountry a skos:Concept .
            ?idbcountry rdfs:label ?label .
            ?idbcountry skos:inScheme iadb:IdBCountries .
            FILTER(lang(?label) = "en") 

    Service <http://dbpedia.org/sparql> {
                ?s a <http://dbpedia.org/ontology/Country> .
                ?s rdfs:label ?labelDb .
                FILTER(CONTAINS (?labelDb, ?label)).
                ?s rdfs:comment ?def .  
                FILTER(lang(?def) = "en") .
                FILTER(lang(?labelDb) = "en") .
    }}

The exact matching query that works is as follows:

SELECT distinct ?idbcountry ?label ?def

WHERE {

            ?idbcountry a skos:Concept .
            ?idbcountry rdfs:label ?label .
            ?idbcountry skos:inScheme iadb:IdBCountries .
            FILTER(lang(?label) = "en") 

    Service <http://dbpedia.org/sparql> {
                ?s a <http://dbpedia.org/ontology/Country> .
                ?s rdfs:label ?label .
                ?s rdfs:comment ?def
                FILTER(lang(?def) = "en")
    }
}

EDIT1

Data Samples:

<http://thesaurus.iadb.org/publicthesauri/10157002136735779158437>
  rdf:type skos:Concept ;
  dct:created "2015-03-27T16:43:48.052-04:00"^^xsd:dateTime ;
  rdfs:label "BO"@en ;
  rdfs:label "Bolivia"@en ;
  rdfs:label "Bolivia"@es ;
  rdfs:label "Bolivie"@fr ;
  rdfs:label "Bolívia"@pt ;
  skos:altLabel "BO"@en ;
  skos:definition "Bolivia (/bəˈlɪviə/, Spanish: [boˈliβja], Quechua: Buliwya, Aymara: Wuliwya), officially known as the Plurinational State of Bolivia (Spanish: Estado Plurinacional de Bolivia locally: [esˈtaðo pluɾinasjoˈnal de βoˈliβja]), is a landlocked country located in western-central South America."@en ;
  skos:inScheme :IdBCountries ;
  skos:prefLabel "Bolivia"@en ;
  skos:prefLabel "Bolivia"@es ;
  skos:prefLabel "Bolivie"@fr ;
  skos:prefLabel "Bolívia"@pt ;
  skos:topConceptOf :IdBCountries ;
  <http://xmlns.com/foaf/0.1/focus> <http://dbpedia.org/resource/Bolivia> ;
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
  • Presumably, the query doesn't work because the value of `?labelDB` does not actually contain the value of `?label` as a substring. But since you haven't shown us your data there is no way to be sure. – Jeen Broekstra Jul 07 '15 at 00:08
  • @JeenBroekstra I know that sub-select queries are evaluated first (innermost to outermost); do you know whether that applies to service forms too? If it does, then ?label might not even have a value within the service block. – Joshua Taylor Jul 07 '15 at 02:26
  • @JoshuaTaylor I'm not 100% sure myself without looking at the spec, but you might be right. If that is the case, a fix would be to move the FILTER clause from inside the SERVICE clause to _behind_ it - though presumably that will make the query a lot less efficient. – Jeen Broekstra Jul 08 '15 at 05:11
  • This is very very strange, because i almost red in every book of sparql that i had a look to, that when you cross-reference, like in my second example, ?label is already bound to the value of the outer most query. Would it means that, in fact what they all says is just the way to read it but not the way it works? – MaatDeamon Jul 10 '15 at 02:46

1 Answers1

6

Without seeing your data, we can't know why your query isn't working. However, using contains is pretty straightforward. It's just a matter of contains(string,substring). As Jeen said, we can't reproduce your problem without knowing what your data looks like, but here's an example of contains in action:

select distinct ?country ?label {
  ?country a dbpedia-owl:Country ;       #-- select countries
           rdfs:label ?label .           #-- and get labels
  filter langMatches(lang(?label),"en")  #-- but only English labels
  filter contains(?label,"land")         #-- containing "land"
}

SPARQL results

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