Reading from an ontology

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading from an ontology

zkay
Hello, I am using owlready to only read an ontology and store classes' names, object properties, data properties, and individuals.

I've been looking at the documentation and there are simple things I cannot find.

First of all do you have an API documentation for owlready?
Here ware what I am trying to do but with no success.
- How do we retrieve the object properties and data properties for an individual?

What I have so far is this:
onto = get_ontology("file://ariac-rdf-xml.owl").load()
class_list = list(onto.classes())

for c in class_list:
    print("C: {0}".format(c))
    individual_list = onto.search(type=c)  # Get all the individual from each class
    for i in individual_list:
        # todo: get all the object properties along with range for each individual
        # part_1 has_pose pose_1: I would like to grab has_pose and pose_1
        # todo: get all the data properties for each individual along with the value:
        # pose_1 has_x 2: I would like to grab has_x and 2

It would be very helpful if you could help me. To summarize:
- How to retrieve object properties and data properties for an individual.
- Also, from an individual, how to get its class?

Thank you very much.
Reply | Threaded
Open this post in threaded view
|

Re: Reading from an ontology

fengbozheng
I think you can download the documentation from https://readthedocs.org/projects/owlready2/downloads/, if you prefer a pdf. It includes how to retrieve properties, e.g, using get_class_properties().
Reply | Threaded
Open this post in threaded view
|

Re: Reading from an ontology

Jiba
Administrator
In reply to this post by zkay
Hi,

- How to retrieve object properties and data properties for an individual.

Use: individual.get_properties()  to obtain the set of properties for which the individual has at least one value.


- Also, from an individual, how to get its class?

Use: individual.is_a  (or individual.__class__ , but does not work well for individuals belonging to several classes).

Jiba