need help with owlready and python specifically with adding dynamic data properties

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

need help with owlready and python specifically with adding dynamic data properties

Madiha
I need help with owlready and data properties as i am new to owlready ontologies and python and have to meet deadline for my reserach. I have a list of nouns like city name bamberg which i want to enter in ontology class entity and assign it to data property how can i do it using owl ready?

Secondly i would like to have all the relations displayed like bamberg is a city so can i do that using owlready and python
Your help will be highly appreciated
Reply | Threaded
Open this post in threaded view
|

Re: need help with owlready and python specifically with adding dynamic data properties

Jiba
Administrator
Hello,

> I need help with owlready and data properties as i am new to owlready
> ontologies and python and have to meet deadline for my reserach. I have a
> list of nouns like city name bamberg which i want to enter in ontology class
> entity and assign it to data property how can i do it using owl ready?

I think you need to create the City class (if not yet existing), and then to create City individuals:

        onto.City(name = "Bamberg")http://owlready2.readthedocs.io/en/latest/class.html

See the documentation of Owlready2 here :

        http://owlready2.readthedocs.io/en/latest/class.html

> Secondly i would like to have all the relations displayed like bamberg is a
> city so can i do that using owlready and python
> Your help will be highly appreciated

You can list city individuals with: onto.City.instances()

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: need help with owlready and python specifically with adding dynamic data properties

Madiha
Thankyou for your reply ... one more question can instead of bamberg can it be a variable ? that changes values all the times
Reply | Threaded
Open this post in threaded view
|

Re: need help with owlready and python specifically with adding dynamic data properties

Jiba
Administrator
Hello,

Yes, it can be a variable :

                onto.City(name = city_name_variable)

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

> Thankyou for your reply ... one more question can instead of bamberg can it
> be a variable ? that changes values all the times
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://owlready.8326.n8.nabble.com/need-help-with-owlready-and-python-specifically-with-adding-dynamic-data-properties-tp211p213.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: need help with owlready and python specifically with adding dynamic data properties

Joe S.
In reply to this post by Jiba
Hello. How may I create subclasses using a variable? For example:
class name is favorites

fruits = [apple, orange, grapes]

for x in fruits:
   add x as subclass of the class favorites

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

Re: need help with owlready and python specifically with adding dynamic data properties

Joe S.
Figured out how to add subclasses using a variable.

fruits = ["orange", "apple", "peach"]

for x in fruits:
        types.new_class(x, (onto["Food"],))

This adds "orange" , etc., as subclasses to the superclass "Food".

Credit: https://stackoverflow.com/questions/53397615/owlready2-dynamic-class-generation