我正试图在我的词库中获取dbpedia中的一些定义。
虽然可以找到一个国家有一个与我的国家相匹配的标签,但我并没有得到所有的标签。所以我尝试将类似的标签与contains匹配,但它不起作用。
知道为什么吗。
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> ;
如果没有看到您的数据,我们就无法知道为什么您的查询不起作用。但是,使用包含非常简单。这只是包含(字符串,子字符串(的问题。正如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结果