Search Mailing List Archives
[protege-discussion] a simple questions about owl programming
Timothy Redmond
tredmond at stanford.edu
Thu Nov 18 08:22:40 PST 2010
The code you had essentially works except that the line
> OWLObjectProperty individual = (OWLObjectProperty) jt.next();
is unlikely to succeed. You would expect the next value to be an
OWLIndividual (or a literal) not an object property.
> /WARNING: Invalid frame type:
> DefaultOWLIndividual(http://www.semanticweb.org/ontologies/2010/0/family.owl#Jim
> of [DefaultOWLNamedClass(http://www.w3.org/2002/07/owl#Thing),
> DefaultOWLNamedClass(http://www.semanticweb.org/ontologies/2010/0/family.owl#male_family_member),
> DefaultRDFSNamedClass(http://www.w3.org/2002/07/owl#NamedIndividual)
> <http://www.w3.org/2002/07/owl#NamedIndividual%29>]) --
> AbstractRedirectingDispatch.getDirectOwnSlotValues()
> Exception in thread "main" java.lang.IllegalArgumentException: null slot/
The first warning is weird but the exception means what it says. Your
owlModel does not have a hasSon object property in it so objectProp is null.
> and I have take a look at owlapi, it's really more direct to handle.
> but after I checked these code sample on the website, I found that
> these codes only do some actions about class. but my target is individual.
The "Classes and instances" example from [1] has individuals. To write
your code in the owl api you simply put:
OWLNamedIndividual jim = factory.getOWLNamedIndividual(":jim", prefixManager);
OWLObjectProperty hasSon = factory.getOWLObjectProperty(":hasSon", prefixManager);
for (OWLIndividual son : jim.getObjectPropertyValues(hasSon, ontology)) {
System.out.println(" - " + son);
}
-Timothy
[1] http://owlapi.sourceforge.net/documentation.html
On 11/18/2010 06:55 AM, tingyu li wrote:
> thanks for you guys response. and I have take a look at owlapi, it's
> really more direct to handle. but after I checked these code sample on
> the website, I found that these codes only do some actions about
> class. but my target is individual. how to get specific individual's
> object property assertions is my purpose.
> And at the same time, I find a simple way that maybe can get this, the
> code is :
>
> OWLIndividual ind = owlModel.getOWLIndividual("Jim");
> OWLObjectProperty objectProp =
> owlModel.getOWLObjectProperty("hasSon");
> Collection values = ind.getPropertyValues(objectProp);
> for (Iterator jt = values.iterator(); jt.hasNext();) {
> OWLObjectProperty individual = (OWLObjectProperty)
> jt.next();
> System.out.println(" - " + individual.getBrowserText());
> }
>
> but error message returned said:
> /WARNING: Invalid frame type:
> DefaultOWLIndividual(http://www.semanticweb.org/ontologies/2010/0/family.owl#Jim
> of [DefaultOWLNamedClass(http://www.w3.org/2002/07/owl#Thing),
> DefaultOWLNamedClass(http://www.semanticweb.org/ontologies/2010/0/family.owl#male_family_member),
> DefaultRDFSNamedClass(http://www.w3.org/2002/07/owl#NamedIndividual)
> <http://www.w3.org/2002/07/owl#NamedIndividual%29>]) --
> AbstractRedirectingDispatch.getDirectOwnSlotValues()
> Exception in thread "main" java.lang.IllegalArgumentException: null slot/
> it seems that this code just can handle the old version proj, so is
> there any replacement of 4.0 for the same target?
>
> In the other hand, as thomas mentioned,
>
> All of the assertion information would be retrieved in the form of
> different kinds of axioms that you would get for a particular
> individual (like Jim) by calling the method with signature:
>
> OWLOntology.getAxioms(
>
> OWLIndividual)
>
> and then filtering the results in to different classes of
> axiom such as
>
> OWLPropertyAssertionAxiom which supports getProperty() and
> getObject() to tell you which property and value it has.
>
> The usages would seem to be returned by
>
> OWLOntology.getReferencingAxioms(OWLEntity)
>
> I will appreciate if you can give me code samples about how to drive them.
>
> thx a lot!
>
> 2010/11/18 Thomas Russ <tar at isi.edu <mailto:tar at isi.edu>>
>
>
> On Nov 17, 2010, at 7:20 AM, tingyu li wrote:
>
> hi Thomas, thanks for your response. but I still very confused
> by these methods...and I have read all the samples posted on
> the website, but I don't find any solutions for my problems, a
> very similar question is about query all resources that have a
> certain property value. the code on website is like this:
> RDFProperty subClassOfProperty =
> owlModel.getRDFProperty(RDFSNames.Slot.SUB_CLASS_OF);
>
> OWLNamedClass owlThingClass = owlModel.getOWLThingClass();
> Collection results =
> owlModel.getRDFResourcesWithPropertyValue(subClassOfProperty,
> owlThingClass);
> System.out.println("Subclasses of owl:Thing:");
>
> for (Iterator it = results.iterator(); it.hasNext();) {
> RDFResource resource = (RDFResource) it.next();
> System.out.println(" - " + resource.getBrowserText());
> }
> but, actually, there are no slot on the new version owl files.
> and I think RDFProperty is not very fit for my file. by the
> way, I use protege 4.0 to develop a owl file and save it as
> format: RDF/XML. the file is like this:
>
>
> You have to look at the class hierarchy in the Java code.
> OWLObjectProperty and OWLIndividual are all subclasses of
> RDFPropery and RDFResource, so those methods will be applicable.
>
> But if you are going to be using Protege 4, then you should be
> using the OWLAPI to work with the ontology rather than the
> Protege-OWL API. That is the underlying code that the Protege 4
> code uses. OWLAPIv3 is used in Protege 4.1
>
> So the place to start for OWLAPI programming are the following
> documents:
>
> http://owlapi.sourceforge.net/documentation.html
>
> All of the assertion information would be retrieved in the form of
> different kinds of axioms that you would get for a particular
> individual (like Jim) by calling the method with signature:
>
> OWLOntology.getAxioms(OWLIndividual)
>
> and then filtering the results in to different classes of axiom
> such as
>
> OWLPropertyAssertionAxiom which supports getProperty() and
> getObject() to tell you which property and value it has.
>
> The usages would seem to be returned by
>
> OWLOntology.getReferencingAxioms(OWLEntity)
>
>
>
>
> <owl:ObjectProperty
> rdf:about="http://www.semanticweb.org/ontologies/2010/0/family.owl#isUncleOf">
> <rdfs:range
> rdf:resource="http://www.semanticweb.org/ontologies/2010/0/family.owl#family_member"/>
> <rdfs:domain
> rdf:resource="http://www.semanticweb.org/ontologies/2010/0/family.owl#male_family_member"/>
> </owl:ObjectProperty>
> I want get the similar result as the probem I described above.
> in other words, if I click Jim as the picture, I can get the
> result as the rigt part of the picture displayed, Usage and
> Property assertions:Jim
>
> thanks.
>
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> <mailto:protege-discussion at lists.stanford.edu>
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03
>
>
>
>
> --
> Li
>
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101118/218c31be/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Son.owl
Type: application/rdf+xml
Size: 1354 bytes
Desc: not available
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101118/218c31be/attachment.owl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Son.pprj
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101118/218c31be/attachment.pprj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PropertyValue.java
Type: text/x-java
Size: 1258 bytes
Desc: not available
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101118/218c31be/attachment.java>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PropertyValue.java
Type: text/x-java
Size: 1477 bytes
Desc: not available
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20101118/218c31be/attachment-0001.java>
More information about the protege-discussion
mailing list