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 <[email protected]>

> 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:[email protected]]
> Sent: Wednesday, May 08, 2013 4:45 AM
> To: [email protected]
> 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
>
>
>
>

Reply via email to