Introspection with owlready2

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

Introspection with owlready2

Pierre
Hi,

I'm trying to use introspection on owlready-generated objects. When I use "dir" on an object, I don't see the attributes I'm defining in my ontology (as the "has_topping" used in the documentation example). What am I doing wrong? FYI, I'm using "has some Role" in Protégé SubClassOf to define the attribute "has", and was hoping to recover "has" in one way or another.

Thanks in advance.

Bye,

Pierre
Reply | Threaded
Open this post in threaded view
|

Re: Introspection with owlready2

Jiba
Administrator
Hi,

I verified, but there is no "dir()" support in Owlready2. Currently, you may want to use individual.get_properties() for listing asserted properties on an individual.

However, adding dir() support would be a nice addition, and I'm thinking about it.


> FYI, I'm using "has some Role" in Protégé SubClassOf to define the
> attribute "has", and was hoping to recover "has" in one way or another.

Do you mean you are working on a Class and not an Instance/Individual? Owlready2 export some restrictions on Classes (those with "some") as Class properties, but here too, there is no dir() support. On Classes, I think you'll have to scan all restrictions in Class.is_a and Class.equivalent_to, and search for "some" restriction.

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13

> Hi,
>
> I'm trying to use introspection on owlready-generated objects. When I use
> "dir" on an object, I don't see the attributes I'm defining in my ontology
> (as the "has_topping" used in the documentation example). What am I doing
> wrong? FYI, I'm using "has some Role" in Protégé SubClassOf to define the
> attribute "has", and was hoping to recover "has" in one way or another.
>
> Thanks in advance.
>
> Bye,
>
> Pierre
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://owlready.8326.n8.nabble.com/Introspection-with-owlready2-tp168.html
> To start a new topic under Owlready, email [hidden email]
> To unsubscribe from Owlready, visit
Reply | Threaded
Open this post in threaded view
|

Re: Introspection with owlready2

Pierre
Bonjour Jean-Baptiste,

This was very helpful, and this seems to be doing the trick for the time being :) Thanks a lot for your quite fast answer.

I was also wondering whether there is a way of performing a deep object creation (i.e., if a Class A has attributes that are object themselves, say b of Class B, I would like A.deep_new() to create an instance in which deep_new has also being called on the b attribute). Or should I use introspection to write one for owlready2?

Thanks in advance.

Bye,

Pierre

Reply | Threaded
Open this post in threaded view
|

Re: Introspection with owlready2

Jiba
Administrator
Hello,

I think what you need is individual (or class) "cloning" ability. OwlReady2 do not have specific methods for that (or maybe not yet).

By the way, I've added support for dir() on individuals in the development version of OwlReady2. However, I think it's better to use get_properties(), because dir() returns not only properties but also method names and local attributes.

Best regards,
Jean-Baptiste Lamy
Reply | Threaded
Open this post in threaded view
|

Re: Introspection with owlready2

Pierre
Hello Jean-Baptiste,

I don't want to perform cloning, which assumes that an object already exists. I had in mind a recursive, deep object creation procedure that would initialise basic fields with default values (say 0 for ints, "" for strings,...) and object fields with recursively built objects. But, I need in fact more flexibility, more like what some attribute grammars allow. This is not for now, anyway :)

Indeed, get_properties is fine. Thanks for your fast answer :)

Bye,

Pierre