You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Michael Trosin <ma...@gmail.com> on 2013/05/07 21:30:39 UTC
Query declared properties returns too much
Hi,
I am quite new to mailing-lists, so sorry if this is not the way, how I
should start a "topic".
I have the attached ontology and I'm trying to list declared properties of
the class "Dataset" via:
OntClass ontclass = mOntModel.getOntClass(namespace + "#Dataset");
ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties();
Doing it this way I get much properties, which actually aren't properties
from dataset (hasDataAnalysis, hasPublishing, ...). Loading it with direct
= true gives me the correct properties. So far so good, the problem is,
that I get now wrong results when using:
OntClass ontclass = mOntModel.getOntClass(namespace + "#LifecycleResource");
ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties(true);
Now the only property is "hasKey" (missing hasName, hasTimestamp, ...).
Is the ontology wrong defined? Or do I miss anything else?
I fixed one class and the other is no broken. I have no idea, what the
issue could be.
For any ideas many thanks in advice.
Best regards,
Michael
Re: Query declared properties returns too much
Posted by Ian Dickinson <ia...@epimorphics.com>.
Hi Michael,
On 07/05/13 20:30, Michael Trosin wrote:
> Hi,
>
> I am quite new to mailing-lists, so sorry if this is not the way, how I
> should start a "topic".
This is fine. Welcome to jena-users!
> I have the attached ontology and I'm trying to list declared properties
> of the class "Dataset" via:
>
> OntClass ontclass = mOntModel.getOntClass(namespace + "#Dataset");
> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties();
>
> Doing it this way I get much properties, which actually aren't
> properties from dataset (hasDataAnalysis, hasPublishing, ...). Loading
> it with direct = true gives me the correct properties. So far so good,
> the problem is, that I get now wrong results when using:
>
> OntClass ontclass = mOntModel.getOntClass(namespace + "#LifecycleResource");
> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties(true);
>
> Now the only property is "hasKey" (missing hasName, hasTimestamp, ...).
> Is the ontology wrong defined? Or do I miss anything else?
It's very difficult to give any advice with this minimal amount of
information. You ask if your ontology is not correct, but you don't tell
us what the ontology contains ..
Please provide a complete, minimal example. What this means: the
smallest amount of code and an extract from your ontology that shows the
problem, in a way that we can run your code to see exactly what is
happening. Please don't just try to post your entire project.
By the way, what listDeclaredProperties() does is documented here:
http://jena.apache.org/documentation/notes/rdf-frames.html
You might find it useful background reading.
> I fixed one class and the other is no broken. I have no idea, what the
> issue could be.
>
> For any ideas many thanks in advice.
>
> Best regards,
> Michael
Ian
Re: Query declared properties returns too much
Posted by David Jordan <da...@bellsouth.net>.
Yes, look at OntModel.getOntProperty(String uri)
On May 7, 2013, at 4:47 PM, Michael Trosin wrote:
> Okay, that works as it gives me many subClassOf-properties, which is like
> it is defined in the ontology. Nevertheless now I am stuck with getting the
> actual OntProperty which should be assigned (or the value of the
> subClassOf-property).
>
> Using
>
>> Property prop = iter.next().getPredicate();
>> System.out.println(oc.getPropertyValue(prop).toString());
>
> for testing purposes give some cryptic values. E.g.
> "-6b6b64bf:13e80b8715e:-7ff4"
>
> Is there a way to load the OntProperty out of the name? I'm not quite sure,
> but I expected to get anything like "&xsd;string" or the real property-name
> like "hasName". Is this wrong?
>
>
> However, thank you very much for the fast answer and your help! :-)
>
> best regards,
> Michael
>
>
>
>
>
> 2013/5/7 David Jordan <Da...@sas.com>
>
>>
>> I ran into this same problem two weeks ago. Joshua Taylor provided me with
>> an answer, which I have included below. I ended up writing code similar to
>> the following, where I passed a Resource object
>> (OntModel.getResource(classURI)) representing the class to the method.
>>
>> private long listProperties(Resource resource){
>> StmtIterator iter = omodel.listStatements(resource, (Property)null,
>> (RDFNode)null);
>> while( iter.hasNext() ){
>> Statement stmt = iter.next();
>> Property property = stmt.getPredicate();
>> String pname = property.getLocalName();
>> }
>> }
>>
>>
>>
>>
>> -----Original Message-----
>> From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
>> Sent: Tuesday, April 23, 2013 3:11 PM
>> To: users@jena.apache.org
>> Subject: Re: OntClass.listDeclaredProperties
>>
>>
>>
>> On Tue, Apr 23, 2013 at 2:45 PM, David Jordan <David.Jordan@sas.com
>> <ma...@sas.com>> wrote:
>>
>>> When I call listDeclaredProperties with a direct parameter value of
>> false, I get a list of properties associated with a class. But when I pass
>> a value of true, I don't get any values, yet there are properties directly
>> associated with the class. I do run this with a reasoner, using
>> OWL_MEM_MICRO_RULE_INF. I am using the latest TDB release. Any idea why
>> they are not being returned?
>>
>>
>>
>> Until now, I hadn't looked closely enough at the doc to know what
>>
>> listDeclaredProperties was supposed to return. It returns an
>>
>> iterator over "properties associated with a frame-like view of this
>> class", but I wasn't sure what "associated with" meant there. Looking at
>> the implementation in OntClassImpl, a property is associated with a class
>> if class is one of the property's domains. Is that the same meaning of
>> "associated with a class" that you're operating under? (I ask this not
>> because your question suggested any misunderstanding, but because I, not
>> having used listDeclaredProperties, assumed it might return properties in
>> restrictions on classes and the like, and that doesn't appear to the be the
>> case.)
>>
>>
>>
>> //JT
>>
>>
>>
>> --
>>
>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>>
>>
>> From: Michael Trosin [mailto:maweypeyyu@gmail.com]
>> Sent: Tuesday, May 07, 2013 3:31 PM
>> To: users@jena.apache.org
>> Subject: Query declared properties returns too much
>>
>> Hi,
>> I am quite new to mailing-lists, so sorry if this is not the way, how I
>> should start a "topic".
>> I have the attached ontology and I'm trying to list declared properties of
>> the class "Dataset" via:
>> OntClass ontclass = mOntModel.getOntClass(namespace + "#Dataset");
>> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties();
>> Doing it this way I get much properties, which actually aren't properties
>> from dataset (hasDataAnalysis, hasPublishing, ...). Loading it with direct
>> = true gives me the correct properties. So far so good, the problem is,
>> that I get now wrong results when using:
>>
>> OntClass ontclass = mOntModel.getOntClass(namespace +
>> "#LifecycleResource");
>> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties(true);
>> Now the only property is "hasKey" (missing hasName, hasTimestamp, ...).
>> Is the ontology wrong defined? Or do I miss anything else?
>> I fixed one class and the other is no broken. I have no idea, what the
>> issue could be.
>> For any ideas many thanks in advice.
>> Best regards,
>> Michael
>>
Re: Query declared properties returns too much
Posted by Ian Dickinson <ia...@epimorphics.com>.
On 07/05/13 21:47, Michael Trosin wrote:
> Okay, that works as it gives me many subClassOf-properties, which is like
> it is defined in the ontology. Nevertheless now I am stuck with getting the
> actual OntProperty which should be assigned (or the value of the
> subClassOf-property).
>
> Using
>
>> Property prop = iter.next().getPredicate();
>> System.out.println(oc.getPropertyValue(prop).toString());
>
> for testing purposes give some cryptic values. E.g.
> "-6b6b64bf:13e80b8715e:-7ff4"
This is the result of calling toString() on an anonymous node (also
known as a bNode). A bNode is a resource with no URI. You can test for
a bNode with the isAnon() method on Resource. The toString() value is
simply an internal identifier used inside Jena, and will change each
time the ontology is loaded.
Note that you are not getting the property here, but the *value* of the
property.
> Is there a way to load the OntProperty out of the name?
I don't understand the question, sorry. You already have the property -
it's your prop variable. If you want that as an OntProperty, you can do:
OntProperty ontProp = prop.as( OntProperty.class );
However, when you call:
oc.getPropertyValue(prop)
whether you do that with prop or ontProp, you're getting the value of
that property of that resource. E.g:
ex:fido foaf:name "Fido Dog" .
prop (or ontProp) is foaf:name, and calling getPropertyValue(prop) on
ex:fido will give you the value "Fido Dog".
> I'm not quite sure,
> but I expected to get anything like "&xsd;string" or the real property-name
> like "hasName". Is this wrong?
Yes, see above.
Ian
Re: Query declared properties returns too much
Posted by Michael Trosin <ma...@gmail.com>.
Okay, that works as it gives me many subClassOf-properties, which is like
it is defined in the ontology. Nevertheless now I am stuck with getting the
actual OntProperty which should be assigned (or the value of the
subClassOf-property).
Using
> Property prop = iter.next().getPredicate();
> System.out.println(oc.getPropertyValue(prop).toString());
for testing purposes give some cryptic values. E.g.
"-6b6b64bf:13e80b8715e:-7ff4"
Is there a way to load the OntProperty out of the name? I'm not quite sure,
but I expected to get anything like "&xsd;string" or the real property-name
like "hasName". Is this wrong?
However, thank you very much for the fast answer and your help! :-)
best regards,
Michael
2013/5/7 David Jordan <Da...@sas.com>
>
> I ran into this same problem two weeks ago. Joshua Taylor provided me with
> an answer, which I have included below. I ended up writing code similar to
> the following, where I passed a Resource object
> (OntModel.getResource(classURI)) representing the class to the method.
>
> private long listProperties(Resource resource){
> StmtIterator iter = omodel.listStatements(resource, (Property)null,
> (RDFNode)null);
> while( iter.hasNext() ){
> Statement stmt = iter.next();
> Property property = stmt.getPredicate();
> String pname = property.getLocalName();
> }
> }
>
>
>
>
> -----Original Message-----
> From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
> Sent: Tuesday, April 23, 2013 3:11 PM
> To: users@jena.apache.org
> Subject: Re: OntClass.listDeclaredProperties
>
>
>
> On Tue, Apr 23, 2013 at 2:45 PM, David Jordan <David.Jordan@sas.com
> <ma...@sas.com>> wrote:
>
> > When I call listDeclaredProperties with a direct parameter value of
> false, I get a list of properties associated with a class. But when I pass
> a value of true, I don't get any values, yet there are properties directly
> associated with the class. I do run this with a reasoner, using
> OWL_MEM_MICRO_RULE_INF. I am using the latest TDB release. Any idea why
> they are not being returned?
>
>
>
> Until now, I hadn't looked closely enough at the doc to know what
>
> listDeclaredProperties was supposed to return. It returns an
>
> iterator over "properties associated with a frame-like view of this
> class", but I wasn't sure what "associated with" meant there. Looking at
> the implementation in OntClassImpl, a property is associated with a class
> if class is one of the property's domains. Is that the same meaning of
> "associated with a class" that you're operating under? (I ask this not
> because your question suggested any misunderstanding, but because I, not
> having used listDeclaredProperties, assumed it might return properties in
> restrictions on classes and the like, and that doesn't appear to the be the
> case.)
>
>
>
> //JT
>
>
>
> --
>
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
>
> From: Michael Trosin [mailto:maweypeyyu@gmail.com]
> Sent: Tuesday, May 07, 2013 3:31 PM
> To: users@jena.apache.org
> Subject: Query declared properties returns too much
>
> Hi,
> I am quite new to mailing-lists, so sorry if this is not the way, how I
> should start a "topic".
> I have the attached ontology and I'm trying to list declared properties of
> the class "Dataset" via:
> OntClass ontclass = mOntModel.getOntClass(namespace + "#Dataset");
> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties();
> Doing it this way I get much properties, which actually aren't properties
> from dataset (hasDataAnalysis, hasPublishing, ...). Loading it with direct
> = true gives me the correct properties. So far so good, the problem is,
> that I get now wrong results when using:
>
> OntClass ontclass = mOntModel.getOntClass(namespace +
> "#LifecycleResource");
> ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties(true);
> Now the only property is "hasKey" (missing hasName, hasTimestamp, ...).
> Is the ontology wrong defined? Or do I miss anything else?
> I fixed one class and the other is no broken. I have no idea, what the
> issue could be.
> For any ideas many thanks in advice.
> Best regards,
> Michael
>
Re: Query declared properties returns too much
Posted by Ian Dickinson <ia...@epimorphics.com>.
On 10/05/13 09:36, Michael Trosin wrote:
> Hi,
>
> thank you very much for the detailed explanation and the link. Now I am a
> little bit confused which way is better: Using listDeclaredProperties or
> using the self-implemented listProperties provided by David Jordan.
Well, as I said in my email to David, the two methods solve completely
different problems. Which one is right for you depends on what you're
trying to achieve, which, as far as I know, you haven't stated.
>
> Well, I made a short example to demonstrate, what the problem is. I have an
> ontology which has three classes (Home, Animal and its subclass Cat). Each
> animal has the DatatypeProperty "hasFur" and a cat "hasHome"
> (objectProperty). A home also has a "hasAddress". The ontology-file I
> created is attached at the end of this mail.
> Now using this peace of code returns no properties:
>
> public static void testProperties(OntModel m) throws Exception
> {
> // load the ontclass
> OntClass oc = m.getOntClass("
> http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Home
> ");
>
> // check
> if(oc == null)
> throw new Exception("ont-class could not be loaded!");
>
> // try to list the properties of this class (should be hasAddress)
> ExtendedIterator<OntProperty> ei = oc.listDeclaredProperties(true);
> System.out.println("Properties:");
>
> while (ei.hasNext())
> {
> OntProperty p = ei.next();
>
> System.out.println(p.getLocalName());
> }
>
> System.out.println("Finished listing...");
> }
>
>
> But, if I call listDeclaredProperties with false, I get all the
> datatype-Properties, what seems strange to me. The link you provided only
> explains the effects of inferred properties on instances, but on classes
> there shouldn't be anything inferred (I mean in this simple ontology). I am
> again wrong? :-)
> Maybe there is a big misunderstanding, what I think how ontologies work.
> Could you explain, why this doesn't give the expected result of hasAddress?
>
> Great thanks in advice for all you help.
Although properties in RDF play a similar role to slots in a frame-based
system, there is not really any notion in RDF of the properties *that
belong to* a class. In an open-world representation like RDF/OWL, you
can attach any property to any resource. That may entail additional
information, including that the model is then inconsistent, but there's
nothing to stop you doing it. Put another way, if you want to ask "which
properties can I use with this class", the correct answer is "any
property from any ontology anywhere".
Lots of people have found this inconvenient. When designing an ontology,
you have a sense of the properties you-the-designer *expect* to be used
with a particular class. A common way of documenting this is to use
rdfs:domain:
:Cat a owl:Class.
:furLength a owl:DatatypeProperty;
rdfs:domain :Cat.
This doesn't, in fact, restrict :furLength to only being used on
resources that are already known to be :Cat instances. It allows you to
infer that any resource with a :furLength must, in fact, be a :Cat.
However, we found that many people were using rdfs:domain *as though* it
imposed just such a restriction, and that can be very useful. A good use
case is a form designer: "I want to create a form to instantiate
instances of :Cat classes, which properties should I provide form fields
for?" Clearly the answer of "every property in the entire ontology" does
not capture the intent that certain properties are expected to appear
with cats.
Jena's listDeclaredProperties method is an attempt to capture this
informal semantics of the association of some properties to certain
classes. It's not officially part of RDF, and there is no formal
specification of what the behaviour should be. However, we use the
rdfs:domain, and the heuristic that a property used with an instance of
a class that entails no additional type information is an property "of"
that class.
In your instance, the datatype properties such as :hasHome or :hasFur
have no stated rdfs:domain, so implicitly the rdfs:domain is
rdfs:Resource (or owl:Thing if you prefer). So by inheritance, every
resource "has" the property :hasFur. That's why :hasFur appears in the
non-direct case of lDP(), and disappears in the direct case.
As for the :Cat class, you're not using rdfs:domain to associate
properties with classes, but qualified cardinality restrictions (:Cat is
a sub-class of the class of resources that have at least one :hasHome
property whose value is a :Home). While that conveys a similar intent to
the global rdfs:domain axiom, and arguably could be covered by the same
argument as above, it's not a case that the code currently covers
(because the edge cases get very complex).
Bottom line: if you need the lDP() kind of association between classes
and properties, either use rdfs:domain axioms, or else you could write a
SPARQL query to extract the associations you want.
Ian
Re: Query declared properties returns too much
Posted by Michael Trosin <ma...@gmail.com>.
Hi,
thank you very much for the detailed explanation and the link. Now I am a
little bit confused which way is better: Using listDeclaredProperties or
using the self-implemented listProperties provided by David Jordan.
Well, I made a short example to demonstrate, what the problem is. I have an
ontology which has three classes (Home, Animal and its subclass Cat). Each
animal has the DatatypeProperty "hasFur" and a cat "hasHome"
(objectProperty). A home also has a "hasAddress". The ontology-file I
created is attached at the end of this mail.
Now using this peace of code returns no properties:
public static void testProperties(OntModel m) throws Exception
{
// load the ontclass
OntClass oc = m.getOntClass("
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Home
");
// check
if(oc == null)
throw new Exception("ont-class could not be loaded!");
// try to list the properties of this class (should be hasAddress)
ExtendedIterator<OntProperty> ei = oc.listDeclaredProperties(true);
System.out.println("Properties:");
while (ei.hasNext())
{
OntProperty p = ei.next();
System.out.println(p.getLocalName());
}
System.out.println("Finished listing...");
}
But, if I call listDeclaredProperties with false, I get all the
datatype-Properties, what seems strange to me. The link you provided only
explains the effects of inferred properties on instances, but on classes
there shouldn't be anything inferred (I mean in this simple ontology). I am
again wrong? :-)
Maybe there is a big misunderstanding, what I think how ontologies work.
Could you explain, why this doesn't give the expected result of hasAddress?
Great thanks in advice for all you help.
Best regards,
Michael
===========================
cats.owl
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#"
xml:base="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3"/>
<owl:ObjectProperty rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasHome
"/>
<owl:DatatypeProperty rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasAddress
"/>
<owl:DatatypeProperty rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasFur
"/>
<owl:Class rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Animal
">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasFur
"/>
<owl:qualifiedCardinality
rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="&xsd;boolean"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Cat">
<rdfs:subClassOf rdf:resource="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Animal
"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasHome
"/>
<owl:onClass rdf:resource="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Home
"/>
<owl:qualifiedCardinality
rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#Home
">
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="
http://www.semanticweb.org/aslan/ontologies/2013/4/untitled-ontology-3#hasAddress
"/>
<owl:qualifiedCardinality
rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
<owl:onDataRange rdf:resource="&xsd;string"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
</rdf:RDF>
2013/5/8 David Jordan <Da...@sas.com>
> Good points. The code I had was sufficient for my immediate purposes, but
> for more general and production cases, I'll use your recommendations.
>
> -----Original Message-----
> From: Ian Dickinson [mailto:ian@epimorphics.com]
> Sent: Wednesday, May 08, 2013 4:45 AM
> To: users@jena.apache.org
> Subject: Re: Query declared properties returns too much
>
> On 07/05/13 21:05, David Jordan wrote:
> >
> > I ran into this same problem two weeks ago. Joshua Taylor provided me
> > with an answer, which I have included below. I ended up writing code
> > similar to the following, where I passed a Resource object
> > (OntModel.getResource(classURI)) representing the class to the method.
> >
> > private long listProperties(Resource resource){
> > StmtIterator iter = omodel.listStatements(resource,
> (Property)null, (RDFNode)null);
> > while( iter.hasNext() ){
> > Statement stmt = iter.next();
> > Property property = stmt.getPredicate();
> > String pname = property.getLocalName();
> > }
> > }
>
> This solves a completely different problem to listDeclaredProperties().
> What this code does is to list the triples in the graph whose subject is
> the class resource itself. This is not the same as finding the properties
> that you would normally expect to be associated with an
> *instance* of the class. An example to clarify:
>
> @prefix ex: <http://example.org/example#>.
>
> ex:Dog
> rdf:type owl:Class ;
> rdfs:comment "The class of all dogs".
>
> ex:pedigree
> rdf:type owl:DatatypeProperty ;
> rdfs:domain ex:Dog ;
> rdfs:range xsd:boolean ;
> rdfs:comment "Denotes whether a particular dog is a pedigree or not" .
>
>
> In this case, the method you provide will return two values, "type"
> (short for rdf:type) and "comment" (short for rdfs:comment), because those
> are the only properties *of the class resource itself*.
> Conversely, listDeclaredProperties() will return ex:pedigree, because
> that's a property that we would expect to find (note: not are guaranteed to
> find, this is a rather informal contract) on instances of ex:Dog. For
> example:
>
> ex:fido
> rdf:type ex:Dog ;
> ex:pedigree "false"^^xsd:boolean ;
> rdfs:comment "Fido is a lovable mongrel!".
>
> By the way, the method you wrote is almost exactly the listProperties()
> method of OntClass (as inherited from Resource), except that your version
> reduces the URI's to local names. Which, incidentally, isn't generally a
> very good idea. Different predicates have different semantics, and the full
> URI is necessary to distinguish predicates that might otherwise have the
> same name. If you need a short name to present a property in a UI, it's
> much better to use the rdfs:label or skos:prefLabel.
>
> Ian
>
>
>
>
RE: Query declared properties returns too much
Posted by David Jordan <Da...@sas.com>.
Good points. The code I had was sufficient for my immediate purposes, but for more general and production cases, I'll use your recommendations.
-----Original Message-----
From: Ian Dickinson [mailto:ian@epimorphics.com]
Sent: Wednesday, May 08, 2013 4:45 AM
To: users@jena.apache.org
Subject: Re: Query declared properties returns too much
On 07/05/13 21:05, David Jordan wrote:
>
> I ran into this same problem two weeks ago. Joshua Taylor provided me
> with an answer, which I have included below. I ended up writing code
> similar to the following, where I passed a Resource object
> (OntModel.getResource(classURI)) representing the class to the method.
>
> private long listProperties(Resource resource){
> StmtIterator iter = omodel.listStatements(resource, (Property)null, (RDFNode)null);
> while( iter.hasNext() ){
> Statement stmt = iter.next();
> Property property = stmt.getPredicate();
> String pname = property.getLocalName();
> }
> }
This solves a completely different problem to listDeclaredProperties().
What this code does is to list the triples in the graph whose subject is the class resource itself. This is not the same as finding the properties that you would normally expect to be associated with an
*instance* of the class. An example to clarify:
@prefix ex: <http://example.org/example#>.
ex:Dog
rdf:type owl:Class ;
rdfs:comment "The class of all dogs".
ex:pedigree
rdf:type owl:DatatypeProperty ;
rdfs:domain ex:Dog ;
rdfs:range xsd:boolean ;
rdfs:comment "Denotes whether a particular dog is a pedigree or not" .
In this case, the method you provide will return two values, "type"
(short for rdf:type) and "comment" (short for rdfs:comment), because those are the only properties *of the class resource itself*.
Conversely, listDeclaredProperties() will return ex:pedigree, because that's a property that we would expect to find (note: not are guaranteed to find, this is a rather informal contract) on instances of ex:Dog. For
example:
ex:fido
rdf:type ex:Dog ;
ex:pedigree "false"^^xsd:boolean ;
rdfs:comment "Fido is a lovable mongrel!".
By the way, the method you wrote is almost exactly the listProperties() method of OntClass (as inherited from Resource), except that your version reduces the URI's to local names. Which, incidentally, isn't generally a very good idea. Different predicates have different semantics, and the full URI is necessary to distinguish predicates that might otherwise have the same name. If you need a short name to present a property in a UI, it's much better to use the rdfs:label or skos:prefLabel.
Ian
Re: Query declared properties returns too much
Posted by Ian Dickinson <ia...@epimorphics.com>.
On 07/05/13 21:05, David Jordan wrote:
>
> I ran into this same problem two weeks ago. Joshua Taylor provided
> me
> with an answer, which I have included below. I ended up writing code
> similar to the following, where I passed a Resource object
> (OntModel.getResource(classURI)) representing the class to the method.
>
> private long listProperties(Resource resource){
> StmtIterator iter = omodel.listStatements(resource, (Property)null, (RDFNode)null);
> while( iter.hasNext() ){
> Statement stmt = iter.next();
> Property property = stmt.getPredicate();
> String pname = property.getLocalName();
> }
> }
This solves a completely different problem to listDeclaredProperties().
What this code does is to list the triples in the graph whose subject is
the class resource itself. This is not the same as finding the
properties that you would normally expect to be associated with an
*instance* of the class. An example to clarify:
@prefix ex: <http://example.org/example#>.
ex:Dog
rdf:type owl:Class ;
rdfs:comment "The class of all dogs".
ex:pedigree
rdf:type owl:DatatypeProperty ;
rdfs:domain ex:Dog ;
rdfs:range xsd:boolean ;
rdfs:comment "Denotes whether a particular dog is a pedigree or not" .
In this case, the method you provide will return two values, "type"
(short for rdf:type) and "comment" (short for rdfs:comment), because
those are the only properties *of the class resource itself*.
Conversely, listDeclaredProperties() will return ex:pedigree, because
that's a property that we would expect to find (note: not are guaranteed
to find, this is a rather informal contract) on instances of ex:Dog. For
example:
ex:fido
rdf:type ex:Dog ;
ex:pedigree "false"^^xsd:boolean ;
rdfs:comment "Fido is a lovable mongrel!".
By the way, the method you wrote is almost exactly the listProperties()
method of OntClass (as inherited from Resource), except that your
version reduces the URI's to local names. Which, incidentally, isn't
generally a very good idea. Different predicates have different
semantics, and the full URI is necessary to distinguish predicates that
might otherwise have the same name. If you need a short name to present
a property in a UI, it's much better to use the rdfs:label or
skos:prefLabel.
Ian
RE: Query declared properties returns too much
Posted by David Jordan <Da...@sas.com>.
I ran into this same problem two weeks ago. Joshua Taylor provided me with an answer, which I have included below. I ended up writing code similar to the following, where I passed a Resource object (OntModel.getResource(classURI)) representing the class to the method.
private long listProperties(Resource resource){
StmtIterator iter = omodel.listStatements(resource, (Property)null, (RDFNode)null);
while( iter.hasNext() ){
Statement stmt = iter.next();
Property property = stmt.getPredicate();
String pname = property.getLocalName();
}
}
-----Original Message-----
From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
Sent: Tuesday, April 23, 2013 3:11 PM
To: users@jena.apache.org
Subject: Re: OntClass.listDeclaredProperties
On Tue, Apr 23, 2013 at 2:45 PM, David Jordan <Da...@sas.com>> wrote:
> When I call listDeclaredProperties with a direct parameter value of false, I get a list of properties associated with a class. But when I pass a value of true, I don't get any values, yet there are properties directly associated with the class. I do run this with a reasoner, using OWL_MEM_MICRO_RULE_INF. I am using the latest TDB release. Any idea why they are not being returned?
Until now, I hadn't looked closely enough at the doc to know what
listDeclaredProperties was supposed to return. It returns an
iterator over "properties associated with a frame-like view of this class", but I wasn't sure what "associated with" meant there. Looking at the implementation in OntClassImpl, a property is associated with a class if class is one of the property's domains. Is that the same meaning of "associated with a class" that you're operating under? (I ask this not because your question suggested any misunderstanding, but because I, not having used listDeclaredProperties, assumed it might return properties in restrictions on classes and the like, and that doesn't appear to the be the case.)
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
From: Michael Trosin [mailto:maweypeyyu@gmail.com]
Sent: Tuesday, May 07, 2013 3:31 PM
To: users@jena.apache.org
Subject: Query declared properties returns too much
Hi,
I am quite new to mailing-lists, so sorry if this is not the way, how I should start a "topic".
I have the attached ontology and I'm trying to list declared properties of the class "Dataset" via:
OntClass ontclass = mOntModel.getOntClass(namespace + "#Dataset");
ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties();
Doing it this way I get much properties, which actually aren't properties from dataset (hasDataAnalysis, hasPublishing, ...). Loading it with direct = true gives me the correct properties. So far so good, the problem is, that I get now wrong results when using:
OntClass ontclass = mOntModel.getOntClass(namespace + "#LifecycleResource");
ExtendedIterator<OntProperty> ei = ontclass.listDeclaredProperties(true);
Now the only property is "hasKey" (missing hasName, hasTimestamp, ...).
Is the ontology wrong defined? Or do I miss anything else?
I fixed one class and the other is no broken. I have no idea, what the issue could be.
For any ideas many thanks in advice.
Best regards,
Michael