You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Fabio Aiub Sperotto <fa...@gmail.com> on 2013/01/18 17:26:00 UTC
Problem to get domain concepts of object property
Hi,
I have a doubt.
*I have this fragment:*
<owl:ObjectProperty rdf:ID="Cultiva">
<rdfs:domain>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#conceptA"/>
<owl:Class rdf:about="#conceptB"/>
<owl:Class rdf:about="#conceptC"/>
</owl:unionOf>
</owl:Class>
</rdfs:domain>
</owl:ObjectProperty>
*And I'm using this SPARQL:*
SELECT * { ontoPrefix:Cultiva rdfs:domain ?domain }
*The result are:*
_______________________________
| domain |
|______________________________|
| conceptA or conceptB or conceptC |
------------------------------------------------------
All in a single line in my ontology editor.
*In jena*, with ResultSet, I receive this:
( ?domain = _:b0 )
Is there a way to get the concepts in a table (one row for each concept)
with SPARQL? Or list in Jena?
I searched the archives of the mailing list but did not find any solution
to help me. Anyone knows of something?
--
Fabio Aiub Sperotto
Mestrando em Modelagem Computacional
about.me/fabiosperotto
www.twitter.com/fabio_gk
Re: Problem to get domain concepts of object property
Posted by Paul Gearon <ge...@ieee.org>.
On Fri, Jan 18, 2013 at 11:26 AM, Fabio Aiub Sperotto
<fa...@gmail.com>wrote:
> Hi,
>
> I have a doubt.
>
> *I have this fragment:*
>
> <owl:ObjectProperty rdf:ID="Cultiva">
> <rdfs:domain>
> <owl:Class>
> <owl:unionOf rdf:parseType="Collection">
> <owl:Class rdf:about="#conceptA"/>
> <owl:Class rdf:about="#conceptB"/>
> <owl:Class rdf:about="#conceptC"/>
> </owl:unionOf>
> </owl:Class>
> </rdfs:domain>
> </owl:ObjectProperty>
>
> *And I'm using this SPARQL:*
>
> SELECT * { ontoPrefix:Cultiva rdfs:domain ?domain }
>
> *The result are:*
> _______________________________
> | domain |
> |______________________________|
> | conceptA or conceptB or conceptC |
> ------------------------------------------------------
>
> All in a single line in my ontology editor.
>
Ontology aware systems are able to work with these structures for you,
which is why you get a union as a result ("or" expresses a union).
> *In jena*, with ResultSet, I receive this:
>
> ( ?domain = _:b0 )
>
>
> Is there a way to get the concepts in a table (one row for each concept)
> with SPARQL? Or list in Jena?
>
In raw SPARQL (which Jena is giving you above), you need to ask for the
entire structure, which is a list. The structural definition is in:
http://www.w3.org/TR/2012/REC-owl2-mapping-to-rdf-20121211/
A union is represented with:
_:x *owl:unionOf* T(SEQ DR1 ... DRn) .
Your query is retrieving the blank node, but you'll need the list. Try this:
SELECT ?domain ?class {
ontoPrefix:Cultiva rdfs:domain ?domain .
?domain owl:unionOf ?list .
?list rdf:rest*/rdf:first ?class }
(I haven't run this myself, but I think it's right....)
Paul
Re: Problem to get domain concepts of object property
Posted by Fabio Aiub Sperotto <fa...@gmail.com>.
Pretty cool! You are amazing:
*From the tip of Paul Gearon*, including documentation of W3C, I understood
better aspects of the ontology. Yes Paul, your SPARQL query is fully
functional.
*From the tip of Dave Reynolds*, I understand better some features of Jena
and could develop a better solution for these cases (owl:unionOf). Like
this:
Property prop = ontologyModel.getObjectProperty(ontoPrefix + "Cultiva");
Iterator ConcetpDomains = ((OntProperty)
prop).getDomain().asClass().asUnionClass().listOperands();
while (ConcetpDomains.hasNext()) {
System.out.println(ConcetpDomains.next());
}
Thanks guys!
2013/1/19 Dave Reynolds <da...@gmail.com>
> On 18/01/13 16:26, Fabio Aiub Sperotto wrote:
>
>> Hi,
>>
>> I have a doubt.
>>
>> *I have this fragment:*
>>
>> <owl:ObjectProperty rdf:ID="Cultiva">
>> <rdfs:domain>
>> <owl:Class>
>> <owl:unionOf rdf:parseType="Collection">
>> <owl:Class rdf:about="#conceptA"/>
>> <owl:Class rdf:about="#conceptB"/>
>> <owl:Class rdf:about="#conceptC"/>
>> </owl:unionOf>
>> </owl:Class>
>> </rdfs:domain>
>> </owl:ObjectProperty>
>>
>> *And I'm using this SPARQL:*
>>
>>
>> SELECT * { ontoPrefix:Cultiva rdfs:domain ?domain }
>>
>> *The result are:*
>>
>> ______________________________**_
>> | domain |
>> |_____________________________**_|
>> | conceptA or conceptB or conceptC |
>> ------------------------------**------------------------
>>
>> All in a single line in my ontology editor.
>>
>> *In jena*, with ResultSet, I receive this:
>>
>>
>> ( ?domain = _:b0 )
>>
>>
>> Is there a way to get the concepts in a table (one row for each concept)
>> with SPARQL? Or list in Jena?
>>
>
> Paul has shown you how to do this in SPARQL.
>
> Jena also provides a convenience API for working with ontologies:
> http://jena.apache.org/**documentation/ontology/<http://jena.apache.org/documentation/ontology/>
>
> In particular if you have your property as an OntProperty then you can use
> sequences like
>
> prop.getDomain().asClass().**asUnionClass().listOperands()
>
> to get the domain as a UnionClass and iterate over the members of the
> union.
>
> Dave
>
--
Fabio Aiub Sperotto
Mestrando em Modelagem Computacional
about.me/fabiosperotto
www.twitter.com/fabio_gk
Re: Problem to get domain concepts of object property
Posted by Dave Reynolds <da...@gmail.com>.
On 18/01/13 16:26, Fabio Aiub Sperotto wrote:
> Hi,
>
> I have a doubt.
>
> *I have this fragment:*
>
> <owl:ObjectProperty rdf:ID="Cultiva">
> <rdfs:domain>
> <owl:Class>
> <owl:unionOf rdf:parseType="Collection">
> <owl:Class rdf:about="#conceptA"/>
> <owl:Class rdf:about="#conceptB"/>
> <owl:Class rdf:about="#conceptC"/>
> </owl:unionOf>
> </owl:Class>
> </rdfs:domain>
> </owl:ObjectProperty>
>
> *And I'm using this SPARQL:*
>
> SELECT * { ontoPrefix:Cultiva rdfs:domain ?domain }
>
> *The result are:*
> _______________________________
> | domain |
> |______________________________|
> | conceptA or conceptB or conceptC |
> ------------------------------------------------------
>
> All in a single line in my ontology editor.
>
> *In jena*, with ResultSet, I receive this:
>
> ( ?domain = _:b0 )
>
>
> Is there a way to get the concepts in a table (one row for each concept)
> with SPARQL? Or list in Jena?
Paul has shown you how to do this in SPARQL.
Jena also provides a convenience API for working with ontologies:
http://jena.apache.org/documentation/ontology/
In particular if you have your property as an OntProperty then you can
use sequences like
prop.getDomain().asClass().asUnionClass().listOperands()
to get the domain as a UnionClass and iterate over the members of the union.
Dave