我将新用户配置文件的实例插入到本体中。但是,我无法使用SPARQL SELECT查询正确检索它。
此查询不返回任何内容。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://test.com/my-ontology.owl#>
SELECT DISTINCT ?class ?birthyear ?gender
WHERE {
?class a owl:UserProfile.
OPTIONAL { ?class owl:birthyear ?birthyear}
OPTIONAL { ?class owl:gender ?gender}
}
LIMIT 25
但是,如果我放下?class a owl:UserProfile.
,此查询将返回正确的结果:
class birthyear gender
owl:userProf_ES 1984 male
我也尝试过此查询,但它也返回空结果:
SELECT DISTINCT ?class ?type ?birthyear ?gender
WHERE {
?class rdf:type ?type.
?type rdfs:subClassOf owl:User.
OPTIONAL { ?class owl:birthyear ?birthyear}
OPTIONAL { ?class owl:gender ?gender}
}
LIMIT 25
为什么会发生?
只需提及UserProfile
是User
的子类。此外,Protégé的UserProfile
具有以下属性:
这是我将实例插入本体的方式:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test.com/my-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
INSERT {
owl:userProf_ES owl:name 'Roger' .
owl:userProf_ES owl:nationalityCode 'ES' .
owl:userProf_ES owl:languageCode 'es_ES' .
owl:userProf_ES owl:gender 'male' .
owl:userProf_ES owl:birthyear 1984 .
owl:userProf_ES owl:purchasingPower 'medium' .
owl:userProf_ES owl:buyingBehaviour 'bargain' .
owl:userProf_ES owl:travelingBehaviour 'traveler' .
owl:userProf_ES owl:lblSporty true .
owl:userProf_ES owl:lblFamily true .
owl:userProf_ES owl:lblWorker false .
owl:userProf_ES owl:lblHealthy true .
owl:userProf_ES owl:lblGamer false .
owl:userProf_ES owl:hasNationality owl:ES .
owl:userProf_ES owl:hasSpokenLanguage owl:es_ES .
owl:userProf_ES owl:hasTravelingBehaviour owl:traveler .
owl:userProf_ES owl:hasBuyingBehaviour owl:bargain .
owl:userProf_ES owl:hasPurchasingPower owl:medium .
}
WHERE {
FILTER NOT EXISTS {
owl:userProf_ES rdf:type owl:UserProfile .
}
}
答案 0 :(得分:0)
如AKSW用户所提到的,INSERT
部分缺少三元组owl:userProf_ES rdf:type owl:UserProfile .
,将缺失的部分添加到INSERT
子句后,一切开始正常工作。