Dear all
I am trying to make a function that iterates through the elements of a table and adds them to an ontology saved locally. I know this code can and will be improved, but at the moment the following issue is my most pressing problem. My issue is that at every iteration (i.e. update of the table), the functions makes the urn of the elements appearing in protégé longer (repeats the name of the ontology as additional subfolder) and I do not understand why. So if the first urn is "urn:/Ontology.owl/Ontology.owl/Ontology.owl" (why 3 times?), when I add a "second level" or execute the function a second time (whcih should not change the ontology), the urn becomes "urn:/Ontology.owl/Ontology.owl/Ontology.owl/Ontology.owl/Ontology.owl/Ontology.owl" with the repeated elelments copied. Thank you very much for the help! Here my code: def addElementsfromXLS(ontology, xlsfile, column1, column2="", column3=""): onto_path.append(ontologyLocation) #since the owl file is saved locally, the path is "C:\\Users\\... ontoname = ontology+".owl" onto = get_ontology(ontoname).load() excel= pd.read_excel(xlsfile) with onto: column1Head = "Titel" #can get dynamically, but currently the head is non descriptive NewClass = types.new_class(column1Head, bases = (Thing,), ) for i in range(1,len(excel)): if excel.loc[i, column1] not in ["0", " "]: textCell = excel.loc[i, column1] NewClass = types.new_class(textCell, bases = (onto[column1Head], )) else: pass # If no third column is given, it is assumed that column1 is parent of column2 if column3 == "": if column2 != "": column2Head = "Title2" NewClass = types.new_class(column2Head, bases = (Thing,), ) for i in range(1,len(excel)): textCell = excel.loc[i, column2] if excel.loc[i, column1] not in ["0", " "]: parent = excel.loc[i, column1] NewClass = types.new_class(textCell, bases = (onto[column2Head], onto[parent]),) else: NewClass = types.new_class(textCell, bases = (onto[column2Head],)) else: pass else: for i in range(1,len(excel)):#### TO BE COMPLETED, not relevant for the moment as I am still working on only two columns pass onto.save() |
Administrator
|
Hello,
The problem is probably located in variable ontoname, which depends on parameter ontology. You should verify that this parameter does not include 3 times "/Ontology.owl". By the way, your IRI should starts with "http://" or "https://", I'm not aware of IRI starting with "urn://". Jiba |
Free forum by Nabble | Edit this page |