如何使用Sparql Contains匹配类似的String?

时间:2015-07-06 20:31:00

标签: sparql triplestore stardog

我试图在我的词库中找到dbpedia中的一些定义。

虽然可以找到与我的国家/地区匹配的国家/地区,但我并不能全部获得。所以我尝试匹配类似的标签与包含,但它不起作用。

知道为什么。

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

有效的完全匹配查询如下:

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

数据样本:

<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> ;

1 个答案:

答案 0 :(得分:4)

如果没有查看您的数据,我们就无法知道您的查询无效的原因。但是,使用包含非常简单。这只是包含(字符串,子串)的问题。正如Jeen所说,我们无法在不知道您的数据是什么的情况下重现您的问题,但这里有一个包含的示例:

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