SPARQL on REGEX filter name

☆樱花仙子☆ 提交于 2020-01-05 04:18:05

问题


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?


回答1:


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" )) ;
}



回答2:


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



来源:https://stackoverflow.com/questions/39413155/sparql-on-regex-filter-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!