Selva Balaji
Selva Balaji

Reputation: 455

SPARQL on REGEX filter name

SPARQL on REGEX filter name works when I use direct search query. It is not working on regex using query.

PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://dublincore.org/2010/10/11/dcterms.rdf#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX grs: <http://www.georss.org/georss/point>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select distinct ?iri ?logo ?description 
  {
    values ?hasLogo { foaf:depiction dbpedia-owl:thumbnail }
    values ?hasName { foaf:name rdfs:label }
    ?iri a                    dbpedia-owl:Company ;
         dbpedia-owl:abstract ?description ;
         filter(regex(?Name, "Lufthansa", "i" )) ;
        ?hasLogo              ?logo .
        filter( langMatches(lang(?description),"en") )
    }

Above code was not working because of filter(regex(?Name, "Lufthansa", "i" )) ;

If I used direct search ?Name "Lufthansa"@en ; it works fine.

Why is this?

Upvotes: 1

Views: 7849

Answers (2)

Selva Balaji
Selva Balaji

Reputation: 455

select distinct ?iri ?name ?description {
?iri a dbpedia-owl:Company ;
rdfs:label ?label ;
foaf:name ?name ;
dbpedia-owl:abstract ?description .
#foaf:depiction|dbpedia-owl:thumbnail ?logo .
filter(regex(?name, "\\blufthansa\\b","i" )) .
filter(regex(?label, "\\blufthansa\\b","i" ))
# filter( langMatches(lang(?description),"en") )
}
limit 100

Upvotes: 3

Joshua Taylor
Joshua Taylor

Reputation: 85913

Try running your query through the sparql.org's query validator. It's not legal. It looks like you want the following. You still have to get the variable bindings in the usual way. Only then can you add the additional filter. You can't just put a filter expression in place of (part of) a triple pattern.

select distinct ?iri ?logo ?description  {
  values ?hasLogo { foaf:depiction dbpedia-owl:thumbnail }
  values ?hasName { foaf:name rdfs:label }
  ?iri a dbpedia-owl:Company ;
       dbpedia-owl:abstract ?description ;
       ?hasName ?Name ;
       ?hasLogo ?logo .

  filter langMatches(lang(?description),"en")
  filter(regex(?Name, "Lufthansa", "i" )) ;
}

Upvotes: 4

Related Questions