0

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é:

enter image description here

enter image description here

enter image description here

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 . 
  } 
} 
ScalaBoy
  • 3,254
  • 13
  • 46
  • 84
  • In the ontology definition your properties are always starting with `has...`, whereas in the data you dropped this part. – Sirko Dec 01 '18 at 13:52
  • @Sirko: Thank you for a prompt reply. I will be very thankful if you elaborate your feedback with an example. The properties such as `nationalityCode`, `gender`, etc. are Data Properties. The properties that start with `has...` are Object Properties. In my other tests, everything works fine if I do not use Object Properties at all. Please see my update for more information about my Data Properties and Object Properties. – ScalaBoy Dec 01 '18 at 13:55
  • What is it you actually want to say with your definition of `UserProfile`? Furthermore, are you aware that your data in the last 5 lines of the insert block assigns annotations to the properties themselves and not to the `owl:userProf_ES` instance? – Sirko Dec 01 '18 at 15:09
  • @Sirko: No, I didn't know that it assigns annotations to the properties. Thanks. But then how can I assign `owl:hasNationality owl:Nationality owl:ES` to `UserProfile` instance? I want to say "A given profile has the ES nationality". With the definition of `UserProfile` I want to define the profile of a user. For example, Spanish male of 30 years old etc... – ScalaBoy Dec 01 '18 at 15:36
  • @Sirko: I made a relevant update. – ScalaBoy Dec 01 '18 at 15:54
  • Still not working? From a quick glance it should work now, although the current modeling leaves room for improvement. – Sirko Dec 01 '18 at 15:57
  • @Sirko No:( I tried both queries mentioned in the post. None of them works... It only works when I drop `?class a owl:UserProfile.`. I don't really understand why it happens. Is there any trick to debug/validate? – ScalaBoy Dec 01 '18 at 16:01
  • well, I can't see any instance of class `owl:UserProfile` - where do you see this? – UninformedUser Dec 01 '18 at 16:02
  • it's obvious that with your `INSERT` query you did **not** add this information to the ontology! – UninformedUser Dec 01 '18 at 16:05
  • @AKSW: Probably I do not have sufficient experience with SPARQL. But I was assuming that my INSERT statement creates an instance of `UserProfile` because of `owl:userProf_ES rdf:type owl:UserProfile .`. If not, how can I create an instance of `UserProfile`? – ScalaBoy Dec 01 '18 at 16:05
  • I don't get it. The `INSERT` part adds anything else but not the triple `owl:userProf_ES rdf:type owl:UserProfile .` - you just mentioned it in the `WHERE` part which is by the way used for pattern matching. Your whole query doesn't make sense here. What is the purpose of the `WHERE` part if there is no variable at all? If you just want to add static data, then use [`INSERT DATA`](https://www.w3.org/TR/sparql11-update/#insertData) instead of `INSERT ... WHERE ...` – UninformedUser Dec 01 '18 at 16:07
  • @AKSW: Oh, I get the point. Now it works! Thank you so much. – ScalaBoy Dec 01 '18 at 16:10
  • Great, if you don't mind, please add the solution as an answer here. Might help others as well. And don't forget to click on "Accept" for your answer then to mark it as resolved – UninformedUser Dec 01 '18 at 16:11
  • Side note: why did you pick `owl:` as the abbreviation for your own ontology? This forced you to use `oo:` for the OWL namespace, which is usually shortened to `owl:`. Swapping the choices around would make it easier for other users to glance at your ontology and figure out what belongs to which namespace. – Ignazio Dec 04 '18 at 20:44

1 Answers1

0

As mentioned by AKSW user, the INSERT part lacked the triple owl:userProf_ES rdf:type owl:UserProfile . After adding this missing part into INSERT clause, everything started working.

TallTed
  • 9,069
  • 2
  • 22
  • 37
ScalaBoy
  • 3,254
  • 13
  • 46
  • 84