urn gets longer at every iteration

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

urn gets longer at every iteration

m_quad
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()
Reply | Threaded
Open this post in threaded view
|

Re: urn gets longer at every iteration

Jiba
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
Reply | Threaded
Open this post in threaded view
|

Re: urn gets longer at every iteration

Jos Lehmann 2
Hi there

regarding the last remark in reply of Oct 15, 2020; 5:27pm i.e. http(s):// Vs urn:

Recently I have worked with .ttl semantic models that use urn: rather than http(s)://

As far as I could tell, owlready could not handle urn:

Specifically, if one has to work with a model that uses an IRI as specified in (1) below, is there a way of working in owlready with (1), or is the only solution in order to work with owlready to:
- find and replace all occurences of (1) with an http(s):// -based IRI
- find and replace back to (1) when done working with owlready?

(1) urn:M:A.B.C.D#Entity


KR, Jos