Sparql query in protege on own ontology

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Sparql query in protege on own ontology

Martin Bazelt

Hello at all,

I created a little ontology in protege and tried to use SPARQL queries for questioning it. When I choose the "SPARQL Query"-tab in protege 4.2 beta, there is automatically the following query:

PREFIX rdf: http://www.w3.org./1999/02/22-rdf-syntax-ns#
PREFIX owl: http://www.w3.org./2002/07/owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX rdfs: http://www.w3.org./2000/01/rdf-schema#
SELECT ?subject ?object
WHERE { ?subject rdfs:subClassOf ?obect}

(In protege I did not forget the < and > in the PREFIX-lines. )

When I execute this query, I get all subclasses and their classes in my ontology.

When I change the where-part in

WHERE { ?subject rdfs:comment ?object}

I get all my classes, where I set a "comment"-annotation-property.

But when I try to add the following line

PREFIX test: "http://www.semanticweb.org/mattin/ontologies/2012/7/Person"

(which is the IRI of my ontology, according to the "active-ontology"-tab) and try the following query:

PREFIX rdf: http://www.w3.org./1999/02/22-rdf-syntax-ns#
PREFIX owl: http://www.w3.org./2002/07/owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX rdfs: http://www.w3.org./2000/01/rdf-schema#
PREFIX test: http://www.semanticweb.org/mattin/ontologies/2012/7/Person
SELECT ?subject ?object
WHERE { ?subject test:hasName ?obect}

I get no results.

There is the same Problem when I try to query a own created property annotation, e.g.

WHERE { ?subject test:secondComment ?obect}

where I saved further information for a class or property.

Also when I try to query another ontology from the web, e.g. the pizza-ontology (http://www.co-ode.org/ontologies/pizza/pizza.owl) I can't run any queries on its properties or classes.

Can anybody help me?

Can you explain me, what the four existing PREFIX-lines do, and wherefore I need them. Do I have to do a kind of import with my own ontology, that I can run SPARQL-queries on it?

Thank you very much!!

Kind regards
Martin


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Timothy Redmond

(which is the IRI of my ontology, according to the "active-ontology"-tab) and try the following query:

PREFIX rdf: http://www.w3.org./1999/02/22-rdf-syntax-ns#
PREFIX owl: http://www.w3.org./2002/07/owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX rdfs: http://www.w3.org./2000/01/rdf-schema#
PREFIX test: http://www.semanticweb.org/mattin/ontologies/2012/7/Person
SELECT ?subject ?object
WHERE { ?subject test:hasName ?obect}

I get no results.


The most likely reason is that you have no entities in your ontology with a full name of

     http://www.semanticweb.org/mattin/ontologies/2012/7/PersonhasName

You probably wanted to put a '#' after the prefix declaration that you added so that test:hasName would expand to

      http://www.semanticweb.org/mattin/ontologies/2012/7/Person#hasName

instead.  The purpose of the abbreviation is to let you use a shorthand for the full name of the entities in your ontology.

-Timothy



On 08/22/2012 04:59 AM, Martin Bazelt wrote:

Hello at all,

I created a little ontology in protege and tried to use SPARQL queries for questioning it. When I choose the "SPARQL Query"-tab in protege 4.2 beta, there is automatically the following query:

PREFIX rdf: http://www.w3.org./1999/02/22-rdf-syntax-ns#
PREFIX owl: http://www.w3.org./2002/07/owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX rdfs: http://www.w3.org./2000/01/rdf-schema#
SELECT ?subject ?object
WHERE { ?subject rdfs:subClassOf ?obect}

(In protege I did not forget the < and > in the PREFIX-lines. )

When I execute this query, I get all subclasses and their classes in my ontology.

When I change the where-part in

WHERE { ?subject rdfs:comment ?object}

I get all my classes, where I set a "comment"-annotation-property.

But when I try to add the following line

PREFIX test: "http://www.semanticweb.org/mattin/ontologies/2012/7/Person"

(which is the IRI of my ontology, according to the "active-ontology"-tab) and try the following query:

PREFIX rdf: http://www.w3.org./1999/02/22-rdf-syntax-ns#
PREFIX owl: http://www.w3.org./2002/07/owl#
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
PREFIX rdfs: http://www.w3.org./2000/01/rdf-schema#
PREFIX test: http://www.semanticweb.org/mattin/ontologies/2012/7/Person
SELECT ?subject ?object
WHERE { ?subject test:hasName ?obect}

I get no results.

There is the same Problem when I try to query a own created property annotation, e.g.

WHERE { ?subject test:secondComment ?obect}

where I saved further information for a class or property.

Also when I try to query another ontology from the web, e.g. the pizza-ontology (http://www.co-ode.org/ontologies/pizza/pizza.owl) I can't run any queries on its properties or classes.

Can anybody help me?

Can you explain me, what the four existing PREFIX-lines do, and wherefore I need them. Do I have to do a kind of import with my own ontology, that I can run SPARQL-queries on it?

Thank you very much!!

Kind regards
Martin



_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Martin Bazelt
In reply to this post by Martin Bazelt

Hi Timothy,

first of all, thanks for your answer.

You're right, when I use the hash, I finally get results for some SPARQL queries.

Now there remain some different problems, and I hope you can help me one more time.

In my ontology, there is a class "Person" and the datatype property "hasName" with range "string" and a domain "Person".

I defined, that every Person must have a name: so I added "hasName some string".

Now my question: Why does the query

PREFIX pers:<http://www.sematicweb. org/mattin/ontologies/2012/7/Person#> SELECT ?person ?name WHERE {?person pers:hasName ?name}

deliver no results? I'd expected the hasName property as predicate, and further a result like: Person, string.

Hopefully you understand what I tried to explain and can tell me where my mistake is.

Thank you very much and have a nice day.


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Timothy Redmond

SPARQL is not an easy syntax to use for OWL queries.  You have to have a detailed understanding of how various things would be serialized into RDF.  In particular, the serialization of the OWL axiom

Class: test:Person
    SubClassOf: 
        test:hasName some xsd:string

looks like this in turtle:

:Person rdf:type owl:Class ;        
        rdfs:subClassOf [ rdf:type owl:Restriction ;
                          owl:onProperty :hasName ;
                          owl:someValuesFrom xsd:string
                        ] .

I don't know how well you can read turtle but test:hasName does not appear in this serialization as an rdf predicate.  Instead it appears as the object in a triple whose subject is a blank node, whose predicate is owl:onProperty and whose object is test:hasName.  So if you rewrite the query as follows:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX test: <http://www.semanticweb.org/mattin/ontologies/2012/7/Person#>
SELECT ?subject ?property ?dataRange
	WHERE { ?subject rdfs:subClassOf ?restriction.
                                ?restriction owl:onProperty ?property ;
                                                 owl:someValuesFrom ?dataRange }

then you will get the result you were expecting.

-Timothy


On 08/29/2012 02:15 AM, Martin Bazelt wrote:

Hi Timothy,

first of all, thanks for your answer.

You're right, when I use the hash, I finally get results for some SPARQL queries.

Now there remain some different problems, and I hope you can help me one more time.

In my ontology, there is a class "Person" and the datatype property "hasName" with range "string" and a domain "Person".

I defined, that every Person must have a name: so I added "hasName some string".

Now my question: Why does the query

PREFIX pers:<http://www.sematicweb. org/mattin/ontologies/2012/7/Person#> SELECT ?person ?name WHERE {?person pers:hasName ?name}

deliver no results? I'd expected the hasName property as predicate, and further a result like: Person, string.

Hopefully you understand what I tried to explain and can tell me where my mistake is.

Thank you very much and have a nice day.



_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

Person.owl (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Wynne, Robert (NIH/NLM/LHC) [C]
> SPARQL is not an easy syntax to use for OWL queries.  

I will wholeheartedly agree with this.  Tim, could you point us to a decent SPARQL primer that may or may not focus on OWL?  My bookmarks are not good.

Rob

From: Timothy Redmond [mailto:[hidden email]]
Sent: Wednesday, August 29, 2012 8:54 AM
To: [hidden email]
Subject: Re: [protege-owl] Sparql query in protege on own ontology


SPARQL is not an easy syntax to use for OWL queries.  You have to have a detailed understanding of how various things would be serialized into RDF.  In particular, the serialization of the OWL axiom
Class: test:Person
    SubClassOf:
        test:hasName some xsd:string

looks like this in turtle:
:Person rdf:type owl:Class ;        
        rdfs:subClassOf [ rdf:type owl:Restriction ;
                          owl:onProperty :hasName ;
                          owl:someValuesFrom xsd:string
                        ] .

I don't know how well you can read turtle but test:hasName does not appear in this serialization as an rdf predicate.  Instead it appears as the object in a triple whose subject is a blank node, whose predicate is owl:onProperty and whose object is test:hasName.  So if you rewrite the query as follows:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX test: <http://www.semanticweb.org/mattin/ontologies/2012/7/Person#>
SELECT ?subject ?property ?dataRange
        WHERE { ?subject rdfs:subClassOf ?restriction.
                                ?restriction owl:onProperty ?property ;
                                                 owl:someValuesFrom ?dataRange }

then you will get the result you were expecting.

-Timothy


On 08/29/2012 02:15 AM, Martin Bazelt wrote:
Hi Timothy,
first of all, thanks for your answer.
You're right, when I use the hash, I finally get results for some SPARQL queries.
Now there remain some different problems, and I hope you can help me one more time.
In my ontology, there is a class "Person" and the datatype property "hasName" with range "string" and a domain "Person".
I defined, that every Person must have a name: so I added "hasName some string".
Now my question: Why does the query
PREFIX pers:<http://www.sematicweb. org/mattin/ontologies/2012/7/Person#> SELECT ?person ?name WHERE {?person pers:hasName ?name}
deliver no results? I'd expected the hasName property as predicate, and further a result like: Person, string.
Hopefully you understand what I tried to explain and can tell me where my mistake is.
Thank you very much and have a nice day.



_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Alan Ruttenberg-2
You might investigate supporting the terp syntax that C&P developed,
which makes writing restrictions reasonable. See
http://weblog.clarkparsia.com/2010/04/01/pellet-21-introducing-terp/

On Fri, Aug 31, 2012 at 7:15 AM, Wynne, Robert (NIH/NCI) [C]
<[hidden email]> wrote:

>> SPARQL is not an easy syntax to use for OWL queries.
>
> I will wholeheartedly agree with this.  Tim, could you point us to a decent SPARQL primer that may or may not focus on OWL?  My bookmarks are not good.
>
> Rob
>
> From: Timothy Redmond [mailto:[hidden email]]
> Sent: Wednesday, August 29, 2012 8:54 AM
> To: [hidden email]
> Subject: Re: [protege-owl] Sparql query in protege on own ontology
>
>
> SPARQL is not an easy syntax to use for OWL queries.  You have to have a detailed understanding of how various things would be serialized into RDF.  In particular, the serialization of the OWL axiom
> Class: test:Person
>     SubClassOf:
>         test:hasName some xsd:string
>
> looks like this in turtle:
> :Person rdf:type owl:Class ;
>         rdfs:subClassOf [ rdf:type owl:Restriction ;
>                           owl:onProperty :hasName ;
>                           owl:someValuesFrom xsd:string
>                         ] .
>
> I don't know how well you can read turtle but test:hasName does not appear in this serialization as an rdf predicate.  Instead it appears as the object in a triple whose subject is a blank node, whose predicate is owl:onProperty and whose object is test:hasName.  So if you rewrite the query as follows:
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX owl: <http://www.w3.org/2002/07/owl#>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
> PREFIX test: <http://www.semanticweb.org/mattin/ontologies/2012/7/Person#>
> SELECT ?subject ?property ?dataRange
>         WHERE { ?subject rdfs:subClassOf ?restriction.
>                                 ?restriction owl:onProperty ?property ;
>                                                  owl:someValuesFrom ?dataRange }
>
> then you will get the result you were expecting.
>
> -Timothy
>
>
> On 08/29/2012 02:15 AM, Martin Bazelt wrote:
> Hi Timothy,
> first of all, thanks for your answer.
> You're right, when I use the hash, I finally get results for some SPARQL queries.
> Now there remain some different problems, and I hope you can help me one more time.
> In my ontology, there is a class "Person" and the datatype property "hasName" with range "string" and a domain "Person".
> I defined, that every Person must have a name: so I added "hasName some string".
> Now my question: Why does the query
> PREFIX pers:<http://www.sematicweb. org/mattin/ontologies/2012/7/Person#> SELECT ?person ?name WHERE {?person pers:hasName ?name}
> deliver no results? I'd expected the hasName property as predicate, and further a result like: Person, string.
> Hopefully you understand what I tried to explain and can tell me where my mistake is.
> Thank you very much and have a nice day.
>
>
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

Re: Sparql query in protege on own ontology

Timothy Redmond
On 08/31/2012 12:46 PM, Alan Ruttenberg wrote:
> You might investigate supporting the terp syntax that C&P developed,
> which makes writing restrictions reasonable. See
> http://weblog.clarkparsia.com/2010/04/01/pellet-21-introducing-terp/

I wasn't aware of this but it sounds very similar to the types of syntax
that Matthew has suggested in the past.

-Timothy


>
> On Fri, Aug 31, 2012 at 7:15 AM, Wynne, Robert (NIH/NCI) [C]
> <[hidden email]> wrote:
>>> SPARQL is not an easy syntax to use for OWL queries.
>> I will wholeheartedly agree with this.  Tim, could you point us to a decent SPARQL primer that may or may not focus on OWL?  My bookmarks are not good.
>>
>> Rob
>>
>> From: Timothy Redmond [mailto:[hidden email]]
>> Sent: Wednesday, August 29, 2012 8:54 AM
>> To: [hidden email]
>> Subject: Re: [protege-owl] Sparql query in protege on own ontology
>>
>>
>> SPARQL is not an easy syntax to use for OWL queries.  You have to have a detailed understanding of how various things would be serialized into RDF.  In particular, the serialization of the OWL axiom
>> Class: test:Person
>>      SubClassOf:
>>          test:hasName some xsd:string
>>
>> looks like this in turtle:
>> :Person rdf:type owl:Class ;
>>          rdfs:subClassOf [ rdf:type owl:Restriction ;
>>                            owl:onProperty :hasName ;
>>                            owl:someValuesFrom xsd:string
>>                          ] .
>>
>> I don't know how well you can read turtle but test:hasName does not appear in this serialization as an rdf predicate.  Instead it appears as the object in a triple whose subject is a blank node, whose predicate is owl:onProperty and whose object is test:hasName.  So if you rewrite the query as follows:
>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> PREFIX owl: <http://www.w3.org/2002/07/owl#>
>> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
>> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
>> PREFIX test: <http://www.semanticweb.org/mattin/ontologies/2012/7/Person#>
>> SELECT ?subject ?property ?dataRange
>>          WHERE { ?subject rdfs:subClassOf ?restriction.
>>                                  ?restriction owl:onProperty ?property ;
>>                                                   owl:someValuesFrom ?dataRange }
>>
>> then you will get the result you were expecting.
>>
>> -Timothy
>>
>>
>> On 08/29/2012 02:15 AM, Martin Bazelt wrote:
>> Hi Timothy,
>> first of all, thanks for your answer.
>> You're right, when I use the hash, I finally get results for some SPARQL queries.
>> Now there remain some different problems, and I hope you can help me one more time.
>> In my ontology, there is a class "Person" and the datatype property "hasName" with range "string" and a domain "Person".
>> I defined, that every Person must have a name: so I added "hasName some string".
>> Now my question: Why does the query
>> PREFIX pers:<http://www.sematicweb. org/mattin/ontologies/2012/7/Person#> SELECT ?person ?name WHERE {?person pers:hasName ?name}
>> deliver no results? I'd expected the hasName property as predicate, and further a result like: Person, string.
>> Hopefully you understand what I tried to explain and can tell me where my mistake is.
>> Thank you very much and have a nice day.
>>
>>
>>
>> _______________________________________________
>> protege-owl mailing list
>> [hidden email]
>> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
>>
>> _______________________________________________
>> protege-owl mailing list
>> [hidden email]
>> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03