You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "McGibbney, Lewis John" <Le...@gcu.ac.uk> on 2011/05/04 14:45:43 UTC

Executing SPARQL queries on owl:NamedIndividual

Hi list,

Moving on to expose different entities within a given RDF dataset, I am trying to construct a query to retrieve individuals and their associated numeric values. Some sample data is as follows

###  http://www.semanticweb.org/ontologies/2010/11/section6energydomestic2010.owl#exampleGlazingToConservatory

section6energydomestic2010:exampleGlazingToConservatory rdf:type section6energydomestic2010:Glazing ,
                                                                 owl:NamedIndividual ;

                                                        section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K "2.0"^^xsd:double ;

                                                        section6energydomestic2010:hasMaximumIndividualElementUvalueWperm²K "3.3"^^xsd:double .

I am confused as to how to construct my query, so far I have

PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:     <http://www.w3.org/2002/07/owl#>
PREFIX fn:      <http://www.w3.org/2005/xpath-functions#>
PREFIX apf:     <http://jena.hpl.hp.com/ARQ/property#>
PREFIX dc:      <http://purl.org/dc/elements/1.1/>
PREFIX ns:      <http://www.semanticweb.org/ontologies/2010/11/section6energydomestic2010.owl#exampleGlazingToConservatory/>
SELECT ?type ?NamedInidividual ?b ?double
WHERE { ?b rdf:type ?type;
         owl:NamedIndividual ?NamedIndividual;
         xsd:double ?double .
        FILTER (?double < 2.5)}

Although again the syntax is valid, I am getting no results as the query is not correctly constructed.

I would like to get something like

Glazing | exampleGlazingToConservatory | hasMaximumAreaWeighted...blahblah | 2.0

Thanks for any help on this one. Lewis


Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Re: Executing SPARQL queries on owl:NamedIndividual

Posted by Andy Seaborne <an...@epimorphics.com>.

On 06/05/11 17:15, McGibbney, Lewis John wrote:
> Hi Andy,
>
> I tried your suggested syntax but can't seem to form a valid SPARQL query.
>
> It's the ':p' that is causing confusion... I am expecting something different. By 'The property that...' do you mean the predicate?
> Thanks

I meant something from your data - I don't know which property you want 
to use there.

The syntax error is is because prefix ":" is not defined but it was only 
an illustration.

	Andy

> ________________________________________
> From: Andy Seaborne [andy.seaborne@epimorphics.com]
> Sent: 06 May 2011 14:24
> To: jena-users@incubator.apache.org
> Subject: Re: Executing SPARQL queries on owl:NamedIndividual
>
> Did yo mean something like
>
> SELECT ?type ?name ?b ?double
>
> WHERE { ?b rdf:type ?type ;
>           # Get the display name for ?b - your property may vary.
>              rdfs:label ?name ;
>          # The property that connect ?b to the double value.
>              :p   ?double .
>           FILTER (?double<  2.5)}
>
>
>
> On 04/05/11 14:59, McGibbney, Lewis John wrote:
>> Hi Chris,
>>
>>> (typo in second name)
>>
>> fixed now thanks for pointing this out.
>>
>>>> WHERE { ?b rdf:type ?type;
>>>>            owl:NamedIndividual ?NamedIndividual;
>>>>            xsd:double ?double .
>>>>           FILTER (?double<   2.5)}
>>>
>>> There's something wrong with how you're thinking of this, but I'm not
>>> sure how best to explain it. There is no statement with property xsd:double
>>> in your data, so the query cannot succeed. Similarly there are no statements
>>> with property owl:NamedIndividual; ditto.
>>>
>>> What you've written for the triples  is shorthand for
>>>
>>>      ?b rdf:type ?type.
>>>      ?b owl:NamedIndividual ?NamedIndividual.
>>>      ?b xsd:double ?double .
>>>
>>
>> OK I understand your point. When I think more about it, I am trying to think logically about how to construct SPARQL query's but have failed to understand how the triples are structured. I will focus on getting my head around this problem, hopefully this will have the knock-on effect of producing cleaner more logical SPARQL queries.
>>
>>> Your properties -- the middle terms of the triples, eg
>>>
>>>    section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K
>>>
>>> (which is a horribly long name to be using) -- don't match any of those.
>>
>> Yes I know this, I think this is something which I will be dealing with in the future. Currently the RDF resource was produced from domain specific building regulations, hence the obscure property names.
>>
>> Thank you for your solution, this is what I was looking for.
>>
>>> PS ?x ?p ?y queries can be very expensive.
>> I had a feeling that this would be the case, however from viewing various threads is it a fair comment to say that this will only be the case when querying over large datasets or many datasets within a triple store? In comparison my testdata (ath this stage) consists of 329 triples which are being read into Fuseki manually without the requirement for a triple store.
>>
>> Glasgow Caledonian University is a registered Scottish charity, number SC021474
>>
>> Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
>> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html
>>
>> Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
>> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html
>
> Email has been scanned for viruses by Altman Technologies' email management service - www.altman.co.uk/emailsystems
>
> Glasgow Caledonian University is a registered Scottish charity, number SC021474
>
> Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html
>
> Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

RE: Executing SPARQL queries on owl:NamedIndividual

Posted by "McGibbney, Lewis John" <Le...@gcu.ac.uk>.
Hi Andy,

I tried your suggested syntax but can't seem to form a valid SPARQL query.

It's the ':p' that is causing confusion... I am expecting something different. By 'The property that...' do you mean the predicate?
Thanks
________________________________________
From: Andy Seaborne [andy.seaborne@epimorphics.com]
Sent: 06 May 2011 14:24
To: jena-users@incubator.apache.org
Subject: Re: Executing SPARQL queries on owl:NamedIndividual

Did yo mean something like

SELECT ?type ?name ?b ?double

WHERE { ?b rdf:type ?type ;
         # Get the display name for ?b - your property may vary.
            rdfs:label ?name ;
        # The property that connect ?b to the double value.
            :p   ?double .
         FILTER (?double < 2.5)}



On 04/05/11 14:59, McGibbney, Lewis John wrote:
> Hi Chris,
>
>> (typo in second name)
>
> fixed now thanks for pointing this out.
>
>>> WHERE { ?b rdf:type ?type;
>>>           owl:NamedIndividual ?NamedIndividual;
>>>           xsd:double ?double .
>>>          FILTER (?double<  2.5)}
>>
>> There's something wrong with how you're thinking of this, but I'm not
>> sure how best to explain it. There is no statement with property xsd:double
>> in your data, so the query cannot succeed. Similarly there are no statements
>> with property owl:NamedIndividual; ditto.
>>
>> What you've written for the triples  is shorthand for
>>
>>     ?b rdf:type ?type.
>>     ?b owl:NamedIndividual ?NamedIndividual.
>>     ?b xsd:double ?double .
>>
>
> OK I understand your point. When I think more about it, I am trying to think logically about how to construct SPARQL query's but have failed to understand how the triples are structured. I will focus on getting my head around this problem, hopefully this will have the knock-on effect of producing cleaner more logical SPARQL queries.
>
>> Your properties -- the middle terms of the triples, eg
>>
>>   section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K
>>
>> (which is a horribly long name to be using) -- don't match any of those.
>
> Yes I know this, I think this is something which I will be dealing with in the future. Currently the RDF resource was produced from domain specific building regulations, hence the obscure property names.
>
> Thank you for your solution, this is what I was looking for.
>
>> PS ?x ?p ?y queries can be very expensive.
> I had a feeling that this would be the case, however from viewing various threads is it a fair comment to say that this will only be the case when querying over large datasets or many datasets within a triple store? In comparison my testdata (ath this stage) consists of 329 triples which are being read into Fuseki manually without the requirement for a triple store.
>
> Glasgow Caledonian University is a registered Scottish charity, number SC021474
>
> Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html
>
> Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Email has been scanned for viruses by Altman Technologies' email management service - www.altman.co.uk/emailsystems

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Re: Executing SPARQL queries on owl:NamedIndividual

Posted by Andy Seaborne <an...@epimorphics.com>.
Did yo mean something like

SELECT ?type ?name ?b ?double

WHERE { ?b rdf:type ?type ;
         # Get the display name for ?b - your property may vary.
            rdfs:label ?name ;
	# The property that connect ?b to the double value.
            :p   ?double .	
         FILTER (?double < 2.5)}



On 04/05/11 14:59, McGibbney, Lewis John wrote:
> Hi Chris,
>
>> (typo in second name)
>
> fixed now thanks for pointing this out.
>
>>> WHERE { ?b rdf:type ?type;
>>>           owl:NamedIndividual ?NamedIndividual;
>>>           xsd:double ?double .
>>>          FILTER (?double<  2.5)}
>>
>> There's something wrong with how you're thinking of this, but I'm not
>> sure how best to explain it. There is no statement with property xsd:double
>> in your data, so the query cannot succeed. Similarly there are no statements
>> with property owl:NamedIndividual; ditto.
>>
>> What you've written for the triples  is shorthand for
>>
>>     ?b rdf:type ?type.
>>     ?b owl:NamedIndividual ?NamedIndividual.
>>     ?b xsd:double ?double .
>>
>
> OK I understand your point. When I think more about it, I am trying to think logically about how to construct SPARQL query's but have failed to understand how the triples are structured. I will focus on getting my head around this problem, hopefully this will have the knock-on effect of producing cleaner more logical SPARQL queries.
>
>> Your properties -- the middle terms of the triples, eg
>>
>>   section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K
>>
>> (which is a horribly long name to be using) -- don't match any of those.
>
> Yes I know this, I think this is something which I will be dealing with in the future. Currently the RDF resource was produced from domain specific building regulations, hence the obscure property names.
>
> Thank you for your solution, this is what I was looking for.
>
>> PS ?x ?p ?y queries can be very expensive.
> I had a feeling that this would be the case, however from viewing various threads is it a fair comment to say that this will only be the case when querying over large datasets or many datasets within a triple store? In comparison my testdata (ath this stage) consists of 329 triples which are being read into Fuseki manually without the requirement for a triple store.
>
> Glasgow Caledonian University is a registered Scottish charity, number SC021474
>
> Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html
>
> Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
> http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

RE: Executing SPARQL queries on owl:NamedIndividual

Posted by "McGibbney, Lewis John" <Le...@gcu.ac.uk>.
Hi Chris,

>(typo in second name)

fixed now thanks for pointing this out.

>> WHERE { ?b rdf:type ?type;
>>          owl:NamedIndividual ?NamedIndividual;
>>          xsd:double ?double .
>>         FILTER (?double < 2.5)}
>
>There's something wrong with how you're thinking of this, but I'm not
>sure how best to explain it. There is no statement with property xsd:double
>in your data, so the query cannot succeed. Similarly there are no statements
>with property owl:NamedIndividual; ditto.
>
>What you've written for the triples  is shorthand for
>
>    ?b rdf:type ?type.
>    ?b owl:NamedIndividual ?NamedIndividual.
>    ?b xsd:double ?double .
>

OK I understand your point. When I think more about it, I am trying to think logically about how to construct SPARQL query's but have failed to understand how the triples are structured. I will focus on getting my head around this problem, hopefully this will have the knock-on effect of producing cleaner more logical SPARQL queries.

>Your properties -- the middle terms of the triples, eg
>
>  section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K
>
>(which is a horribly long name to be using) -- don't match any of those.

Yes I know this, I think this is something which I will be dealing with in the future. Currently the RDF resource was produced from domain specific building regulations, hence the obscure property names.

Thank you for your solution, this is what I was looking for.

>PS ?x ?p ?y queries can be very expensive.
I had a feeling that this would be the case, however from viewing various threads is it a fair comment to say that this will only be the case when querying over large datasets or many datasets within a triple store? In comparison my testdata (ath this stage) consists of 329 triples which are being read into Fuseki manually without the requirement for a triple store.

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html

Re: Executing SPARQL queries on owl:NamedIndividual

Posted by Chris Dollin <ch...@epimorphics.com>.
Lewis wrote:

> ###  http://www.semanticweb.org/ontologies/2010/11/section6energydomestic2010.owl#exampleGlazingToConservatory
> 
> section6energydomestic2010:exampleGlazingToConservatory rdf:type section6energydomestic2010:Glazing ,
>                                                                  owl:NamedIndividual ;
> 
>                                                         section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K "2.0"^^xsd:double ;
> 
>                                                         section6energydomestic2010:hasMaximumIndividualElementUvalueWperm²K "3.3"^^xsd:double .
> 
> I am confused as to how to construct my query, so far I have
> 
> PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>
> PREFIX rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
> PREFIX owl:     <http://www.w3.org/2002/07/owl#>
> PREFIX fn:      <http://www.w3.org/2005/xpath-functions#>
> PREFIX apf:     <http://jena.hpl.hp.com/ARQ/property#>
> PREFIX dc:      <http://purl.org/dc/elements/1.1/>
> PREFIX ns:      <http://www.semanticweb.org/ontologies/2010/11/section6energydomestic2010.owl#exampleGlazingToConservatory/>
> SELECT ?type ?NamedInidividual ?b ?double

(typo in second name)

> WHERE { ?b rdf:type ?type;
>          owl:NamedIndividual ?NamedIndividual;
>          xsd:double ?double .
>         FILTER (?double < 2.5)}

There's something wrong with how you're thinking of this, but I'm not
sure how best to explain it. There is no statement with property xsd:double
in your data, so the query cannot succeed. Similarly there are no statements
with property owl:NamedIndividual; ditto.

What you've written for the triples  is shorthand for

    ?b rdf:type ?type.
    ?b owl:NamedIndividual ?NamedIndividual.
    ?b xsd:double ?double .

Your properties -- the middle terms of the triples, eg

  section6energydomestic2010:hasMaximumAreaWeightedAverageUvalueForAllElementsOfTheSameTypeWperm²K

(which is a horribly long name to be using) -- don't match any of those.

I would write one version of what you might want as

SELECT ?NamedIndividual ?p ?v WHERE
{
    ?NamedIndividual rdf:type owl:NamedIndividual.
    ?NamedIndividual ?p ?v.
    FILTER (?v < 2.5)
}

which will get you

Individual URI | property URI | numeric value

Chris

PS ?x ?p ?y queries can be very expensive.

-- 
"I don't want to know what the Structuralists think! I want     /Archer's Goon/
 to know what YOU think!"

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)