Loading... |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hello,
I'm creating an ontology from a CSV file and I wonder if there is a way to create a property class dynamically as we do for concepts using the for example the following call : ontology_concept = types.new_class(concept_name, (Thing, ontology_super_concept,)) Maybe something like : ontology_data_property = types.new_class(name=property_name, (DataProperty)) Best regards, Driss |
Loading... |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hello again,
After removing the 'name=' parameter in : ontology_data_property = types.new_class(name=property_name, (DataProperty)) (doesn't work) ontology_data_property = types.new_class(property_name, (DataProperty)) (works !) It works to create the owl property. I'm still wondering the way to define the domain, range and so on. Best, Driss |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Administrator
|
Hello,
Yes, your method should works! You can define the range and domain as follows: ontology_data_property.range = [range...] ontology_data_property.domain = [domain...] Best regards, Jiba |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hello Jiba,
I needed to create data properties dynamically for my project. So, following this thread, I tried to implement it in the way Driss has done it. I have a list of strings where each string is a data property name. s = ["has_PropertA", "has_PropertyB", "has_PropertyC"] Now, I wish to create these data properties dynamically. for i in range(len(s)): with onto: ontology_data_property = types.new_class(s[i], (DataProperty)) But this throws an error - AttributeError: 'int' object has no attribute 'DataProperty' I thought changing 'ontology' in the last line to the name of ontology might help. i.e., for i in range(len(s)): with onto: onto_data_property = types.new_class(s[i], (DataProperty)) But this also gives the same error as above case. Kindly put forward your views on this error and suggest a way out of this problem so as to fulfill my intended objective. I would be glad! |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Administrator
|
Hello,
You need a "," after DataProperty. (DataProperty,) is the tuple of base classes, and, in Python, you need a comma after the first element to create a on-element tuple. for i in range(len(s)): with onto: onto_data_property = types.new_class(s[i], (DataProperty,)) Best regards, |
Loading... |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hi,
I am also trying to create data property dynamically.Here is my code. with onto: ontology_data_property = types.new_class('custNo', (DataProperty,)) ontology_data_property.range = [int] ontology_data_property.domain = ['customers'] when i run this I get error in the domain line. AttributeError: 'str' object has no attribute 'storid' without mentioning the domain it works well. Regards, Jui |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Hello jui_guram and Jiba,
Thank you for helping me out. That inclusion of a comma was what all needed. It works perfectly fine now! for i in range(len(s)): with onto: onto_data_property = types.new_class(s[i], (DataProperty,)) onto_data_property.range = [float] onto_data_property.domain = [Customer] @jui_guram: You need to remove the quotes from the class name i.e., instead of ['customers'] as domain, put [customers] as domain. When you put it as 'customers', it is taken up as a new string which is just a constant fixed string and hence, it is not recognized as an ontology class. And since, you must put an ontology class as the domain, you should put it as [customers]. Then it gets recognized as an ontology class. |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by jui guram
Hi,
To entry anything dynamically - with onto: ontology_data_property = types.new_class('custNo', (DataProperty,)) ontology_data_property.range = [int] ontology_data_property.domain = onto['customers'] Regards, Millennium |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
How to give value to existing data properties loaded from owl file that has all properties defined?
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
We can do that dynamically bu the python way - setattr()
So we would have an individual say i of a class say c Lets say the data property is d So the general way is i.d = ['str'] But by using the setattr() we can write it dynamically as- setattr(i, d, ['str']) Hope this solves your problem! Millennium |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Thank you! The other part of the question, can I connect one individual to multiple individuals via multiple object properties at the same time dynamically?
For example, the following will associate newJob individual, named "job1", to a new company newCompanyName via object property hasCompany: newJob= NewJob(name = "job1", hasCompany=newCompanyName) Can I add more object properties at the same time like hasAddress, hasNumber, etc.? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Yes you can ofcourse. But not in this format. Because this in itself is not that dynamic. Again use the same setattr() and it can be done. On Sun, 20 Sep, 2020, 9:29 pm Avraheem [via Owlready], <[hidden email]> wrote: Thank you! The other part of the question, can I connect one individual to multiple individuals via multiple object properties at the same time dynamically? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Thank you and same thing for adding object property or this method only works with data properties?
|
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
Yes same approach. Ofcourse. On Tue, 22 Sep, 2020, 1:53 am Avraheem [via Owlready], <[hidden email]> wrote: Thank you and same thing for adding object property or this method only works with data properties? |
Free forum by Nabble | Edit this page |