【问题标题】:How to use Sparql Contains to match similar String?如何使用 Sparql Contains 匹配相似的字符串?
【发布时间】:2015-07-06 20:31:00
【问题描述】:

我试图在我的同义词库中的 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> ;

【问题讨论】:

  • 可能是因为?labelDB 的值实际上并不包含?label 的值作为子字符串,所以查询不起作用。但由于您没有向我们展示您的数据,因此无法确定。
  • @JeenBroekstra 我知道首先评估子选择查询(从最内到最外);你知道这是否也适用于服务表格?如果是这样,那么 ?label 甚至可能在服务块中没有值。
  • @JoshuaTaylor 如果不查看规范,我不能 100% 确定自己,但您可能是对的。如果是这种情况,解决方法是将 FILTER 子句从 SERVICE 子句内部移动到 behind 它 - 尽管可能会降低查询效率。
  • 这很奇怪,因为我在我看过的每本 sparql 书中几乎都是红色的,当你交叉引用时,就像在我的第二个示例中一样,?label 已经绑定到最外层查询的值。这是否意味着,事实上他们都说的只是阅读方式而不是工作方式?

标签: sparql triplestore stardog


【解决方案1】:

在没有看到您的数据的情况下,我们无法知道您的查询为何不起作用。但是,使用 contains 非常简单。这只是 contains(string,substring) 的问题。正如 Jeen 所说,我们无法在不知道您的数据是什么样子的情况下重现您的问题,但这里有一个 contains 的示例:

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

【讨论】:

  • Virtuoso 37000 错误 SP030:SPARQL 编译器,第 4 行:在 ';' 之前的 'dbpedia-owl' 处未定义命名空间前缀
  • @hitmaneidos 是的,更改了预定义的名称空间前缀。将 dbpedia-owl 替换为 dbo,一切就绪。
猜你喜欢
  • 1970-01-01
  • 2012-04-12
  • 1970-01-01
  • 1970-01-01
  • 2017-02-04
  • 2015-06-13
  • 2020-11-14
  • 1970-01-01
  • 2016-12-04
相关资源
最近更新 更多