I inserted a new user profile's instance into my ontology. However, I cannot properly retrieve it with SPARQL SELECT query.
This query returns nothing.
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
However, if I drop ?class a owl:UserProfile.
, this query returns a correct result:
class birthyear gender
owl:userProf_ES 1984 male
I also tried this query but it also returns an empty result:
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
Why does it happen?
Just to mention that UserProfile
is a sub-class of User
. Also I have the following properties in UserProfile
in Protégé:
This is how I inserted the instance in the ontology:
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 .
}
}