Hi ,
I have been using OWLready to map database to OWL.Its documentation is great and this mailing list is very helpfull. I am getting my data from MySql database.I have already created the ontology schema ie the classes,data properties and object properties. Now I am trying to create instances by accessing the data from database. Here is my code with onto: for i in range(len(list_of_tuples_CustNo)): my_customer = onto.customers('customer_'+str(i)) my_customer.customerNumber = list_of_tuples_CustNo[i][0] Here list_of_tuples_CustNo[i][0] is all the customernumbers i am trying to attach to dataproperty customerNumber. The program runs without any error ie it creates instances "customer_1" ,"customer_2"... from this statement my_customer = onto.customers('customer_'+str(i)) But Data property assertion doesn't happen. customersnumber doesnt get attached to these instances. Any help would really be appreciated. Regards, Jui |
Hi,
Did you check that the data type for my_customer.customerNumber & list_of_tuples_CustNo[i][0] are the same type? Also, have you tried? #1 with onto: for i in range(len(list_of_tuples_CustNo)): my_customer = onto.customers('customer_'+str(i), customerNumber = list_of_tuples_CustNo[i][0]) #2 Do a print out of "list_of_tuples_CustNo[i][0]" just to see that is accessing the specific index #3 Convert the "list_of_tuples_CustNo[i][0]" explicitly to the "customerNumber" data type. You may also want to catch type error if you are converting. |
Administrator
|
Hi,
You should also check that my_customer.customerNumber is really a dataproperty (you may mispelled the dataproperty name, or forget to create it). This can be done with : print(my_customer.customerNumber) BEFORE my_customer.customerNumber = ... . If it is a dataproperty, you should obtain an empty list (no value defined yet). If it is not, you should get an AttributeError. Best regards, Jean-Baptiste Lamy MCF, LIMICS, Université Paris 13 |
Hi,
Thank you everyone for your response.I realized the mistake.So what is happening when I dynamically create my properties,I create the primary keys as Inverse Functional Property like below. with onto: ontology_object_property = types.new_class(tuple[0]+"Pkey",(InverseFunctionalProperty,)) ontology_object_property.range = [datatype] ontology_object_property.domain = [domain] domain.is_a.append(ontology_object_property.min(1,str)) tuple[0] is the name of the property. IT creates customerNumberPkey as a object property and also an data property since in OWL full datatype property is a subclass of object property.Since they are two types pf propertys with the same name it gets confused when I am creating the instance. The solution for this is I guess to use OWL DL where datatype property and Object property are disjoint. How to write in OWL DL with Owlready2 ? or is there any way to make the object property and data property base classes disjoint? Regards, Jui |
Administrator
|
Hi,
In Owlready, ObjectProperties and DataProperties are implicitely disjoint (corresponding to OWL DL). You have nothing to do to assert it. In your example, I think you should use a DataProperty instead of an ObjectProperty, since the values are restricted to string (str). Best regards, Jiba |
Hi Jiba,
Thank you for the response.The str is wrong on my part it has to be an integer since its a customer number. But I want to use an Inverse functional property for customer number since its a Primary key? and since Inverse Functional Property is a subclass of object property it will create a customerNumber object property. I read some research papers which mentioned that for primary keys use inverse functional property. What do you think is the best way to express primary keys in ontology? Also, In my example why does it create a object property as well as a datatype property when i create a Inverse Functional Property since you said they are disjoint implicitely.Also it creates a class with name customerNumber. Regards, Jui |
Administrator
|
Hi,
I think you can use a normal DataProperty (non Inverse functional). Inverse functional properties provide no particular optimization, and no check -- they are only used for reasoning purpose in OWL. > Also, In my example why does it create a object property as well as a > datatype property when i create a > Inverse Functional Property since you said they are disjoint > implicitely.Also it creates a class with name customerNumber. Inheriting from both ObjectProperty and DataProperty is not supported, and thus anything may occur :) Best regards, Jean-Baptiste Lamy MCF, LIMICS, Université Paris 13 > Hi Jiba, > > Thank you for the response.The str is wrong on my part it has to be an > integer since its a customer number. > But I want to use an Inverse functional property for customer number since > its a Primary key? > > and since Inverse Functional Property is a subclass of object property it > will create a customerNumber object property. > > I read some research papers which mentioned that for primary keys use > inverse functional property. > What do you think is the best way to express primary keys in ontology? > > Also, In my example why does it create a object property as well as a > datatype property when i create a > Inverse Functional Property since you said they are disjoint > implicitely.Also it creates a class with name customerNumber. > > > Regards, > Jui > > > > > > _______________________________________________ > If you reply to this email, your message will be added to the discussion below: > http://owlready.8326.n8.nabble.com/How-to-import-instances-and-its-corresponding-property-values-from-database-to-an-ontology-tp387p402.html > To start a new topic under Owlready, email [hidden email] > To unsubscribe from Owlready, visit |
Free forum by Nabble | Edit this page |