SPARQL query - single class or single subclass of many subclasses

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

SPARQL query - single class or single subclass of many subclasses

Lyman, Daniel [USA]

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: SPARQL query - single class or single subclass of many subclasses

Lorenz Buehmann
Hello Daniel,

rdfs:Class and owl:Class are not predicates/properties, thus, it doesn't make sense to use them in predicate position.
You have to query for entities that are of type owl:Class or rdfs:Class, i.e.

SELECT ?s WHERE {{?s a owl:Class} UNION {?s a rdfs:Class}}

Kind regards,
Lorenz

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 



_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lyman, Daniel [USA]

This makes perfect sense.  Thanks for your help, Lorenz.

May I ask a quick naïve follow on question?

I think the query SELECT ?s WHERE {{?s a owl:Class} UNION {?s a rdfs:Class}} will retrieve all classes in my model.

How should I extend this query to retrieve only a particular, specific class (or instance) (y)?

Again, thanks very much.

Dan

From: protege-user [mailto:[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Monday, October 06, 2014 11:20 AM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

rdfs:Class and owl:Class are not predicates/properties, thus, it doesn't make sense to use them in predicate position.
You have to query for entities that are of type owl:Class or rdfs:Class, i.e.

SELECT ?s WHERE {{?s a owl:Class} UNION {?s a rdfs:Class}}

Kind regards,
Lorenz



As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: SPARQL query - single class or single subclass of many subclasses

Csongor Nyulas-2
Administrator
In reply to this post by Lyman, Daniel [USA]
Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 



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


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lyman, Daniel [USA]

Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [mailto:[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 




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

 


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lorenz Buehmann
Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz

Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 




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

 



_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lyman, Daniel [USA]

Hi Lorenz,

Using SPARQL, how do I retrieve only Class 3 (or only Instance 2) for example from the given model?

I know that I can use the “subClassOf” or “type” predicates as follows.

if I SPARQL query the given model using the “subClassOf” predicate with { ?x rdfs:subClassOf :Class 2 .}, I’ll retrieve siblings Class 3, Class 4 and Class 5.

Similarly, if I query the given model using the “type” predicate with { ?x rdf:type :Class 4 .}, I’ll retrieve siblings Instance 1, Instance 2 and Instance 3.

But, for my current purposes, I don’t want to retrieve all the subclasses of Class 2 (ie, siblings 3, 4 and 5) or all of the sibling Instances 1, 2 and 3.

 

Is there a way to retrieve, for example, just Class 3 or just Instance 2 (without siblings)?

 

Queries with the “subClassOf” or “type” predicates do not seem to be the correct strategy for my purposes, but I can’t figure out the correct SPARQL syntax to retrieve just the individual entity Class 3, or just Instance 2, for example.

 

I realize that questions about SPARQL are probably better suited to another forum and greatly appreciate your time and assistance.

 

Thank you

 

 

From: protege-user [mailto:[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Wednesday, October 08, 2014 9:48 AM
To: [hidden email]
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz



Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 





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

 




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lorenz Buehmann
Sorry, I don't get the use case. If you know that you want only Class 3, why do want to query for it? How should a query engine know which of the classes you want?
On 08.10.2014 16:48, Lyman, Daniel [USA] wrote:

Hi Lorenz,

Using SPARQL, how do I retrieve only Class 3 (or only Instance 2) for example from the given model?

I know that I can use the “subClassOf” or “type” predicates as follows.

if I SPARQL query the given model using the “subClassOf” predicate with { ?x rdfs:subClassOf :Class 2 .}, I’ll retrieve siblings Class 3, Class 4 and Class 5.

Similarly, if I query the given model using the “type” predicate with { ?x rdf:type :Class 4 .}, I’ll retrieve siblings Instance 1, Instance 2 and Instance 3.

But, for my current purposes, I don’t want to retrieve all the subclasses of Class 2 (ie, siblings 3, 4 and 5) or all of the sibling Instances 1, 2 and 3.

 

Is there a way to retrieve, for example, just Class 3 or just Instance 2 (without siblings)?

 

Queries with the “subClassOf” or “type” predicates do not seem to be the correct strategy for my purposes, but I can’t figure out the correct SPARQL syntax to retrieve just the individual entity Class 3, or just Instance 2, for example.

 

I realize that questions about SPARQL are probably better suited to another forum and greatly appreciate your time and assistance.

 

Thank you

 

 

From: protege-user [[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Wednesday, October 08, 2014 9:48 AM
To: [hidden email]
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz



Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 





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

 




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center


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


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

samsontu
In reply to this post by Lyman, Daniel [USA]
Hi,

I think people are wondering why you need to make a query for a class when you have the IRI for the class already. I suppose such a query would be useful when you want to check whether a particular class exists in the ontology. You can extend the previous query for classes to filter for the specific class class3: 

SELECT ?s WHERE {{?s a owl:Class} UNION {?s a rdfs:Class} Filter(?s=<IRI-of-class3>)} 

This query should return the IRI of class3  if it exists in the ontology.

With best regards,
Samson

On Oct 8, 2014, at 7:48 AM, Lyman, Daniel [USA] <[hidden email]> wrote:

Hi Lorenz,

Using SPARQL, how do I retrieve only Class 3 (or only Instance 2) for example from the given model?

I know that I can use the “subClassOf” or “type” predicates as follows.

if I SPARQL query the given model using the “subClassOf” predicate with { ?x rdfs:subClassOf :Class 2 .}, I’ll retrieve siblings Class 3, Class 4 and Class 5.

Similarly, if I query the given model using the “type” predicate with { ?x rdf:type :Class 4 .}, I’ll retrieve siblings Instance 1, Instance 2 andInstance 3.

But, for my current purposes, I don’t want to retrieve all the subclasses of Class 2 (ie, siblings 3, 4 and 5) or all of the sibling Instances 1, 2 and 3.
 
Is there a way to retrieve, for example, just Class 3 or just Instance 2 (without siblings)?
 
Queries with the “subClassOf” or “type” predicates do not seem to be the correct strategy for my purposes, but I can’t figure out the correct SPARQL syntax to retrieve just the individual entity Class 3, or just Instance 2, for example.
 
I realize that questions about SPARQL are probably better suited to another forum and greatly appreciate your time and assistance.
 
Thank you
 

 

From: protege-user [[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Wednesday, October 08, 2014 9:48 AM
To: [hidden email]
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz



Thank you Csongor,
 
I’m afraid I didn’t quite understand your response.
 
Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.
In case of the later, let me revise the question as follows.
 
Given the following RDF(/XML) model of classes and instances, for example:
Class 1
                Class 2
                                Class 3
                                Class 4
                                                Instance 1
                                                Instance 2
                                                Instance 3
                                Cass 5
 
What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?
 
Thanks again very much.
Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:
As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as
{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),
for example.
 
This query will retrieve all the subclasses (or instances) of class (y) in my model of course.
 
I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as
{ ?x rdfs:Class :y .}
or { ?x owl:Class :y .}, for example.
 
I have tried these queries, which do not appear to work (no match).
 
The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by
{ ?x rdfs:subClassOf :z .}.
 
But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).

Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?
Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?
 
Thanks very much for your assistance
Dan Lyman
 

 





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



_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Lyman, Daniel [USA]

Thank you Samson,

 

I see you point.

 

Thank you for the query syntax suggestion; it makes sense.

 

With regard to my use case, it is a bit more complicated than I had indicated.

Suppose I wanted to query for Class 3 (without siblings) and also for subclasses of Class 3. “subClassOf” gets me subclasses of Class 3. But, I also need syntax to get Class 3 as well. Hope this makes sense, but perhaps I am approaching the problem wrong.

 

Thanks again very much to everyone for your patience and assistance.

Dan

 

From: protege-user [mailto:[hidden email]] On Behalf Of Samson Tu
Sent: Wednesday, October 08, 2014 12:51 PM
To: User support for WebProtege and Protege Desktop
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hi,

 

I think people are wondering why you need to make a query for a class when you have the IRI for the class already. I suppose such a query would be useful when you want to check whether a particular class exists in the ontology. You can extend the previous query for classes to filter for the specific class class3: 

 

SELECT ?s WHERE {{?s a owl:Class} UNION {?s a rdfs:Class} Filter(?s=<IRI-of-class3>)} 

 

This query should return the IRI of class3  if it exists in the ontology.

 

With best regards,

Samson

 

On Oct 8, 2014, at 7:48 AM, Lyman, Daniel [USA] <[hidden email]> wrote:



Hi Lorenz,

Using SPARQL, how do I retrieve only Class 3 (or only Instance 2) for example from the given model?

I know that I can use the “subClassOf” or “type” predicates as follows.

if I SPARQL query the given model using the “subClassOf” predicate with { ?x rdfs:subClassOf :Class 2 .}, I’ll retrieve siblings Class 3, Class 4 and Class 5.

Similarly, if I query the given model using the “type” predicate with { ?x rdf:type :Class 4 .}, I’ll retrieve siblings Instance 1, Instance 2 andInstance 3.

But, for my current purposes, I don’t want to retrieve all the subclasses of Class 2 (ie, siblings 3, 4 and 5) or all of the sibling Instances 1, 2 and 3.

 

Is there a way to retrieve, for example, just Class 3 or just Instance 2 (without siblings)?

 

Queries with the “subClassOf” or “type” predicates do not seem to be the correct strategy for my purposes, but I can’t figure out the correct SPARQL syntax to retrieve just the individual entity Class 3, or just Instance 2, for example.

 

I realize that questions about SPARQL are probably better suited to another forum and greatly appreciate your time and assistance.

 

Thank you

 

 

From: protege-user [[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Wednesday, October 08, 2014 9:48 AM
To: [hidden email]
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz




Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 






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

 





_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

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

 


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

samsontu

On Oct 8, 2014, at 11:13 AM, Lyman, Daniel [USA] <[hidden email]> wrote:

With regard to my use case, it is a bit more complicated than I had indicated.
Suppose I wanted to query for Class 3 (without siblings) and also for subclasses of Class 3. “subClassOf” gets me subclasses of Class 3. But, I also need syntax to get Class 3 as well. Hope this makes sense, but perhaps I am approaching the problem wrong.


This doesn’t make sense. When you use SPARQL to query for "Class 3” using the syntax I suggested, you start with an IRI for class 3 and get back an IRI for class 3. You don’t need to query for class 3’s IRI because you already have it. You don’t get back anything different from what you already have (assuming that Class 3 exists in the ontology). 

Things are different when you are programming in Java. You may start with an IRI string, and you want to get a reference to the class as a Java instance of the (Java) OWLClass. In the case of SPARQL, you start with an IRI string and end up with the same IRI string.

With best regards,
Samson




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Joshua TAYLOR
In reply to this post by Lyman, Daniel [USA]
On Wed, Oct 8, 2014 at 2:13 PM, Lyman, Daniel [USA]
<[hidden email]> wrote:
> With regard to my use case, it is a bit more complicated than I had
> indicated.
>
> Suppose I wanted to query for Class 3 (without siblings) and also for
> subclasses of Class 3. “subClassOf” gets me subclasses of Class 3. But, I
> also need syntax to get Class 3 as well. Hope this makes sense, but perhaps
> I am approaching the problem wrong.

Is the problem you're talking about that if you query

?x a :classx

you only get one variable in the results (?x), and you'd rather have

?x a ?y

with two variables, but restricted such that ?y only has a specific
value (:classx)?  You can do that with a filter expression, or (in
SPARQL 1.1) a values block:

select ?x ?y where {
  ?x a ?y
  filter ( ?y = :classx )
}

select ?x ?y where {
  values ?y { :classx }
  ?x a ?y
}

The latter should be preferred if you can use it, since conceptually
it means "just get ?x a :classx", whereas the filter expression in the
former would let an implementation grab all the triples and filter
some out, which could be more work.  They should have the same
results, though.

//JT



--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: [External] Re: SPARQL query - single class or single subclass of many subclasses

Dave McComb
In reply to this post by Lorenz Buehmann
If you want say all the assertions for either a class or instance easiest way is 
Select * where { class ?p ?o } 


Or instance where class Is above 

Sent from my iPhone

On Oct 8, 2014, at 10:51 AM, "Lorenz Buehmann" <[hidden email]> wrote:

Sorry, I don't get the use case. If you know that you want only Class 3, why do want to query for it? How should a query engine know which of the classes you want?
On 08.10.2014 16:48, Lyman, Daniel [USA] wrote:

Hi Lorenz,

Using SPARQL, how do I retrieve only Class 3 (or only Instance 2) for example from the given model?

I know that I can use the “subClassOf” or “type” predicates as follows.

if I SPARQL query the given model using the “subClassOf” predicate with { ?x rdfs:subClassOf :Class 2 .}, I’ll retrieve siblings Class 3, Class 4 and Class 5.

Similarly, if I query the given model using the “type” predicate with { ?x rdf:type :Class 4 .}, I’ll retrieve siblings Instance 1, Instance 2 and Instance 3.

But, for my current purposes, I don’t want to retrieve all the subclasses of Class 2 (ie, siblings 3, 4 and 5) or all of the sibling Instances 1, 2 and 3.

 

Is there a way to retrieve, for example, just Class 3 or just Instance 2 (without siblings)?

 

Queries with the “subClassOf” or “type” predicates do not seem to be the correct strategy for my purposes, but I can’t figure out the correct SPARQL syntax to retrieve just the individual entity Class 3, or just Instance 2, for example.

 

I realize that questions about SPARQL are probably better suited to another forum and greatly appreciate your time and assistance.

 

Thank you

 

 

From: protege-user [[hidden email]] On Behalf Of Lorenz Bühmann
Sent: Wednesday, October 08, 2014 9:48 AM
To: [hidden email]
Subject: Re: [protege-user] [External] Re: SPARQL query - single class or single subclass of many subclasses

 

Hello Daniel,

 the question is, what do you mean by query for 'Class 3'? What is the expected result from your point of view?

Kind regards,
Lorenz



Thank you Csongor,

 

I’m afraid I didn’t quite understand your response.

 

Perhaps I really don’t understand your solution, or my question wasn’t stated clearly.

In case of the later, let me revise the question as follows.

 

Given the following RDF(/XML) model of classes and instances, for example:

Class 1

                Class 2

                                Class 3

                                Class 4

                                                Instance 1

                                                Instance 2

                                                Instance 3

                                Cass 5

 

What is the correct SPARQL syntax to query for only Class 3 or only Instance 2?

 

Thanks again very much.

Dan

 

From: protege-user [[hidden email]] On Behalf Of Csongor Nyulas
Sent: Monday, October 06, 2014 6:40 PM
To: [hidden email]
Subject: [External] Re: [protege-user] SPARQL query - single class or single subclass of many subclasses

 

Everywhere where you want to refer to a specific class/instance, you should use the URI of the class/instance .

Csongor

On 10/06/2014 06:14 PM, Lyman, Daniel [USA] wrote:

As I understand SPARQL from various tutorials, subclasses (or instances) in an RDF/OWL model can be retrieved by a query such as

{ ?x rdfs:subClassOf :y .} (or { ?x rdf:type :y .}),

for example.

 

This query will retrieve all the subclasses (or instances) of class (y) in my model of course.

 

I have not been able to find a method in any tutorial to directly retrieve only the class (y) by a query such as

{ ?x rdfs:Class :y .}

or { ?x owl:Class :y .}, for example.

 

I have tried these queries, which do not appear to work (no match).

 

The only way I am able to retrieve class (y) (as a subclass of (z) for example) seems to be by

{ ?x rdfs:subClassOf :z .}.

 

But this approach retrieves all other subclasses of (z) as well and I want to retrieve only (y).


Is the rdfs:Class or owl:Class query described above incorrect or actually possible to do in SPARQL?

Is another method to directly retrieve a single class (y) (or instance) available (or even possible) to do in SPARQL?

 

Thanks very much for your assistance

Dan Lyman

 

 





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

 




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann, MSc in Computer Science
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center


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

<ATT00001.c>

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