simphony-osp icon indicating copy to clipboard operation
simphony-osp copied to clipboard

return classes with proper ontological hierarchy

Open adhamhashibon opened this issue 1 year ago • 2 comments

the superclasses attribute returns the classes in random (alphabetical?) order, but should be in proper hierarchical order as it will convey more added value in applications.

e.g., superclasses of a citizen is now:

frozenset({<OntologyClass: City [https://www.simphony-osp.eu/city#City>,](https://www.simphony-osp.eu/city#City%3E,)
           <OntologyClass: Geographical Place [https://www.simphony-osp.eu/city#GeographicalPlace>,](https://www.simphony-osp.eu/city#GeographicalPlace%3E,)
           <OntologyClass: Populated Place [https://www.simphony-osp.eu/city#PopulatedPlace>,](https://www.simphony-osp.eu/city#PopulatedPlace%3E,)
           <OntologyClass: [http://www.w3.org/2002/07/owl#Thing>})](http://www.w3.org/2002/07/owl#Thing%3E}))

probably we need to add a way to traverse iteratively from one level to the other, as in the original pretty_print function.

adhamhashibon avatar Jun 28 '23 11:06 adhamhashibon

@yoavnash @kysrpex could you please review this and let me know whether it came up before?

just to add:

- Ontology individual:
  identifier: e4afaa4e-4600-4236-9627-61dd1275eb0b
  type: City (city)
  superclasses: City (city), Geographical Place (city), Populated Place (city), None (owl)
  values: coordinates: [0 0]

pretty print also gets it wrong, it should be as below:

image

adhamhashibon avatar Jun 28 '23 11:06 adhamhashibon

This seems due to the use of frozenset which does not attempt to preserve the order (and in fact seems to order the elements alphanumerically...). Will try to use instead list(dict.fromkeys([...]))!.

as in:

for i in (list(dict.fromkeys([1, 3, 2, 2, 3, 4, 4, 5, 5]))):
    print(i)
1
3
2
4
5

adhamhashibon avatar Jun 28 '23 13:06 adhamhashibon