簡體   English   中英

如何使用Sparql包含來匹配相似的字符串?

[英]How to use Sparql Contains to match similar String?

我正在嘗試在同義詞庫中的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")
    }
}

編輯1

數據樣本:

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

如果不查看您的數據,我們將無法知道您的查詢為什么不起作用。 但是,使用包含非常簡單。 這只是contains(string,substring)的問題 正如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結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM