Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL regex filter

I'm trying to match one word in SPARQL by using regex filter, but without success... :/ I'm sending the query to the endpoint located at "http://dbtune.org/musicbrainz/sparql". Well, the following query works:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX mo: <http://purl.org/ontology/mo/>
SELECT ?artist ?name
WHERE {
    ?artist a mo:MusicArtist
    . ?artist foaf:name "Switchfoot"
    . ?artist foaf:name ?name
    . FILTER(regex(str(?name), "switchfoot", "i"))
}

But, if I remove the line 7 (. ?artist foaf:name "Switchfoot"), the following query does not match:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX mo: <http://purl.org/ontology/mo/>
SELECT ?artist ?name
WHERE {
    ?artist a mo:MusicArtist
    . ?artist foaf:name ?name
    . FILTER(regex(str(?name), "switchfoot", "i"))
}

I don't know if I am doing something wrongly or it's a bug of endpoint...

Can somebody help me?

like image 381
Gustavo José Sousa Avatar asked Jul 06 '12 14:07

Gustavo José Sousa


1 Answers

In your second query, there's no graph pattern to index against. The only way the query processor can satisfy that query is to retrieve the name of every single artist in the triple store, and then apply a regular expression match to each one. It's no wonder you're hitting some sort of resource limit, whether that's CPU time or elapsed time.

If you want to do free text searches like that, I would suggest downloading the dataset to a local endpoint, and using a free-text index such as LARQ. Your queries will be faster and your users will thank you for it!

like image 118
Ian Dickinson Avatar answered Oct 17 '22 23:10

Ian Dickinson