0

I did create the following simple ontology as seen in the picture and code below. My ontology But I am not able to query this ontology.

I would like to make an AKS query, if this one is true than an SELECT query, if false a CONSTRUCT query. I would like to see if a class machine (later a subclass) is connected by a data property with part (later a subclass) and then pull the comment of the part. I tried to combine those answers: Answer1 and Answer2. My question is probably extremely basic but it seems that I can't get my head around this problem. Thank you for your help and patience

My queries look at the moment like this (I put the prefix here only once):

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
ASK { ?machine base:partOf ?part .
  ?part rdfs:comment ?comment}


SELECT ?machine ?part ?comment
WHERE {
  ?machine base:partOf ?part .
  ?part rdfs:comment ?comment. 
}


CONSTRUCT {?part rdfs:comment ?comment}
    WHERE { ?machine base:partOf ?part .
  ?part rdfs:comment ?comment}

Onology

<!-- http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#partOf -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#partOf">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#part"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#machine"/>
</owl:ObjectProperty>


<!-- http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#machine -->

<owl:Class rdf:about="http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#machine"/>



<!-- http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#part -->

<owl:Class rdf:about="http://www.semanticweb.org/linus/ontologies/2019/5/untitled-ontology-11#part"/>

Thank you for your help and patience!

  • what does not work with the queries? – UninformedUser Jul 05 '19 at 09:04
  • Protege is throwing an error: org.protege.editor.owl.rdf.SparqlReasonerException: org.openrdf.query.MalformedQueryException: org.openrdf.query.parser.sparql.ast.VisitorException: QName 'base:partOf' uses an undefined prefix at org.protege.editor.owl.rdf.repository.BasicSparqlReasoner.executeQuery(BasicSparqlReasoner.java:90) at org.protege.editor.owl.rdf.SparqlQueryView.lambda$createBottomComponent$0(SparqlQueryView.java:67) and so on – TheCabbageBaggage Jul 05 '19 at 09:06
  • well, you have to define the prefix `base:` obviously... – UninformedUser Jul 05 '19 at 09:08
  • add `prefix base: ` to your queries – Damyan Ognyanov Jul 05 '19 at 09:08
  • and "partOf" is an *object property* **not** a *data property*. And as you can see from the data, classes are not directly connected via an object property. This only holds for individuals. In your data, you can see that domain and range of the property are the classes, so `base:partOf rdfs:domain ?cls1 ; rdfs:range ?cls2 .` – UninformedUser Jul 05 '19 at 09:09
  • Okay, not adding a prefix was dump, but I stell get an empty answer. :-/ But I believe I should get a result – TheCabbageBaggage Jul 05 '19 at 09:10
  • How to best connect classes? Should I use individuals? – TheCabbageBaggage Jul 05 '19 at 09:14
  • Likely because you do not have instances related with `base:partOf` and these do not have values for `rdfs:comment` property. – Damyan Ognyanov Jul 05 '19 at 09:14
  • Instances are Individuals for you. A quick google search did not yield meaningful results for me. – TheCabbageBaggage Jul 05 '19 at 09:24
  • I corrected the problem with the comment, I always added them to the template and they weren't saved. (obviously) – TheCabbageBaggage Jul 05 '19 at 09:25
  • it still doesn't work for classes. I showed you how your classes are "connected": `base:partOf rdfs:domain ?cls1 ; rdfs:range ?cls2 .` - for your queries you have to add individuals, i.e. concrete machines and parts. And then connect those. like `:machine1 rdf:type :Machine . :part1 rdf:type :Part . :part1 :partOf :machine1 .` By the way, your property `partOf` goes from part to machine, in your query you're using confusing variable names when you say `?machine base:partOf ?part .` – UninformedUser Jul 05 '19 at 09:31
  • I did everything in Protege, but the lines `:machine1 rdf:type :Machine . :part1 rdf:type :Part . :part1 :partOf :machine1` suggest that I should just add them to owl file. Can I just add them at the end? I ask because the syntax does look a bit different though. – TheCabbageBaggage Jul 05 '19 at 09:45
  • I added two individuals to try it out but I probably did not create the right connections. – TheCabbageBaggage Jul 05 '19 at 09:46
  • No, I just used this syntax for explanation, you can't add Turtle syntax at the end of an RDF/XML file. Just do it via Protege, you're using it anyways, or not? Create two individuals, add them to the corresponding classes, and then create an object property assertion between both individuals. And don't forget `rdfs:comment` values for the individuals, otherwise it will of course not work with the query - or put the `rdfs:comment` in an `OPTIONAL`, i.e. `SELECT ?machine ?part ?comment WHERE { ?part base:partOf ?machine . OPTIONAL {?part rdfs:comment ?comment.} }` – UninformedUser Jul 05 '19 at 10:09
  • 1
    Sry, for the late answer. It did work and I really have to thank you for your patience! I will now try make the ASK and CONSTRUCT query work and then expand my ontology. Again thanks! – TheCabbageBaggage Jul 05 '19 at 13:04

0 Answers0