1

I am using this query to search for all labels that contains the word "Medi"

select distinct ?label where 
{ 
    ?concept rdfs:label  ?label 
    filter contains(?label,"Medi") 
    filter(langMatches(lang(?label),"en")) 
}

However, as soon as I change the term from "Medi" to "Medicare" it doesn't work and times out. How do I get it to work with longer words like Medicare i.e. extract all labels which has the word Medicare in it.

1 Answers1

2

Your query has to iterate over all labels in DBpedia - which is quite a large number - and then apply String containment check. This is indeed expensive.

Even a count query leads to an "estimated timeout error":

select count(?label) where 
{ 
    ?concept rdfs:label  ?label 
    filter(regex(str(?label),"Medi")) 
    filter(langMatches(lang(?label),"en")) 
}

Two options:

  1. Virtuoso has some fulltext search support:

    SELECT DISTINCT ?label WHERE { 
      ?concept rdfs:label ?label .
      ?label bif:contains "Medicare"
      FILTER(langMatches(lang(?label),"en"))
    }
    
  2. Since the public DBpedia endpoint is a shared endpoint, the solution is to load the DBpedia dataset into your own triple store, e.g. Virtuoso. There you can adjust the max. estimated execution timeout parameter.
UninformedUser
  • 8,397
  • 1
  • 14
  • 23
  • Hi, I am actually running dbpedia on a local server. And I'd prefer a faster solution, cause being slow would mean bad UX. So, I copy-pasted your Option #1. And got back this : `Virtuoso 37000 Error SP030: SPARQL compiler, line 5: syntax error at '?label' before 'bif:contains' SPARQL query: define sql:big-data-const 0 #output-format:text/html define sql:signal-void-variables 1 SELECT DISTINCT ?label WHERE { ?concept rdfs:label ?label ?label bif:contains "Medicare" FILTER(langMatches(lang(?label),"en")) }` Could you please help me debug :) – Kaustabh Datta Choudhury May 12 '17 at 18:53
  • Ah sorry, I forgot the dot after the first triple pattern. Should work now. – UninformedUser May 12 '17 at 19:11