|
Hello,
From an unknown ontology or any ontology, I try to read and make a hierarchy with for each class, find and structure its subclasses.
Being a beginner on ontology notions, I have read up on how to apply the different methods but I only managed to get the desired results on 2 branches as follows:
[{'Class': 'test1', 'Subclass': [{'Class': 'result_test1'}, {'Class': 'result2_test1'}, {'Class': 'result3_test1'}, ]}, {'Class': 'test2', 'Subclass': [{'Class': 'result_result_test2', 'Subclass': [result2_result_test2, result_test2,result3_result_test2]}]}
I would like to be able to get the classes and subclasses for N-dimensional array in the same way, I thought about creating a recursive function but I get stuck on the results.
I made the following code without recursion:
listEmpty = []
listThing = list(Thing.subclasses())
for i in list(listThing ):
listTemp = []
varList = list(i.subclasses())
if varList:
listTemp2 = []
for o in list(varList):
varList2 = list(o.subclasses())
if varList2:
listTemp2.append({"Class": o.name, "Subclass": varList2})
else:
listTemp2.append({"Class": o.name})
listTemp.append({"Class": i.name, "Subclass": listTemp2})
else:
listTemp.append({"Class": i.name})
listEmpty.append((listTemp[0]))
If you have any ideas on how I could find the solution and solve this problem in this way or by another method I am open.
Thank you very much in advance
|