Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some ObjectProperties from EMMO-beta-4.0 cause errors in OntoGraph #429

Closed
MBueschelberger opened this issue Jun 27, 2022 · 1 comment
Closed

Comments

@MBueschelberger
Copy link

MBueschelberger commented Jun 27, 2022

Dear EMMO-Python developers,

I came across the issue that my EMMO-python v0.3.1 on Python 3.9 (Windows 10 ) has troubles plotting some ObjectProperties with EMMO-beta-4.0 from public Github.

Here is my example serialization:

@prefix : <http://my_exp.info#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix emmo: <http://emmo.info/emmo#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@base <http://my_exp.info> .

<http://my_exp.info> rdf:type owl:Ontology ;
                                 owl:versionIRI <http://my_exp.info/v0.1> ;
                                 owl:imports <https://emmo-repo.github.io/versions/1.0.0-beta4/emmo-inferred.ttl> .

:EMMO_822408b4_c473_4433_8cd0_21e54e82a812 rdf:type owl:Class ;
                                           rdfs:subClassOf emmo:EMMO_22522299_4091_4d1f_82a2_3890492df6db ,
                                                           [ rdf:type owl:Restriction ;
                                                             owl:onProperty emmo:EMMO_c4bace1d_4db0_4cd3_87e9_18122bae2840 ;
                                                             owl:someValuesFrom emmo:EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
                                                           ] ;
                                           skos:prefLabel "my_exp" .

If one tries to import it into emmo-python with the following script ...

from ontopy import get_ontology
from ontopy.graph import OntoGraph
import os

PATH = os.getcwd()
onto_file = os.path.join(PATH, "example.ttl")
new = get_ontology(onto_file).load()


graph = OntoGraph(new, new.my_exp, parents=1, addnodes=True, relations="all")

... the following traceback is returned:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\ontology_viszalizaion.ipynb Cell 9' in <cell line: 6>()

----> 6 graph = OntoGraph(new, new.my_exp, parents=1, addnodes=True, relations="all")


File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:293, in OntoGraph.__init__(self, ontology, root, leafs, entities, relations, style, edgelabels, addnodes, addconstructs, included_namespaces, included_ontologies, parents, excluded_nodes, graph, imported, **kwargs)
    286     self.add_entities(
    287         relations=relations,
    288         edgelabels=edgelabels,
    289         addnodes=addnodes,
    290         addconstructs=addconstructs,
    291     )
    292 elif root:
--> 293     self.add_branch(
    294         root,
    295         leafs,
    296         relations=relations,
    297         edgelabels=edgelabels,
    298         addnodes=addnodes,
    299         addconstructs=addconstructs,
    300         included_namespaces=included_namespaces,
    301         included_ontologies=included_ontologies,
    302     )
    303     if parents:
    304         self.add_parents(
    305             root,
    306             levels=parents,
   (...)
    310             addconstructs=addconstructs,
    311         )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:390, in OntoGraph.add_branch(self, root, leafs, include_leafs, strict_leafs, exclude, relations, edgelabels, addnodes, addconstructs, included_namespaces, included_ontologies, include_parents, **attrs)
    387 for leaf in leafs:
    388     nodeattrs[get_label(leaf)] = self.style.get("leaf", {})
--> 390 self.add_entities(
    391     entities=classes,
    392     relations=relations,
    393     edgelabels=edgelabels,
    394     addnodes=addnodes,
    395     addconstructs=addconstructs,
    396     nodeattrs=nodeattrs,
    397     **attrs,
    398 )
    400 parents = self.ontology.get_ancestors(
    401     classes, include=include_parents, strict=True
    402 )
    403 if parents:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:341, in OntoGraph.add_entities(self, entities, relations, edgelabels, addnodes, addconstructs, nodeattrs, **attrs)
    339     entities = self.ontology.classes(imported=self.imported)
    340 self.add_nodes(entities, nodeattrs=nodeattrs, **attrs)
--> 341 self.add_edges(
    342     relations=relations,
    343     edgelabels=edgelabels,
    344     addnodes=addnodes,
    345     addconstructs=addconstructs,
    346     **attrs,
    347 )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:608, in OntoGraph.add_edges(self, sources, relations, edgelabels, addnodes, addconstructs, **attrs)
    606     sources = self.nodes
    607 for source in sources.copy():
--> 608     self.add_source_edges(
    609         source,
    610         relations=relations,
    611         edgelabels=edgelabels,
    612         addnodes=addnodes,
    613         addconstructs=addconstructs,
    614         **attrs,
    615     )

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:573, in OntoGraph.add_source_edges(self, source, relations, edgelabels, addnodes, addconstructs, **attrs)
    571             continue
    572         pred = asstring(relation, exclude_object=True)
--> 573         self.add_edge(
    574             label, pred, obj, edgelabel=edgelabels, **attrs
    575         )
    577 # inverse
    578 if isinstance(relation, owlready2.Inverse):

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:504, in OntoGraph.add_edge(self, subject, predicate, obj, edgelabel, **attrs)
    501 elif edgelabel:
    502     label = predicate
--> 504 kwargs = self.get_edge_attrs(predicate, attrs=attrs)
    505 self.dot.edge(subject, obj, label=label, **kwargs)
    506 self.edges.add(key)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ontopy\graph.py:725, in OntoGraph.get_edge_attrs(self, predicate, attrs)
    723         break
    724 else:
--> 725     raise ValueError(
    726         f"Relation {relation} not found in entity.mro()."
    727     )
    728 # object property
    729 if isinstance(
    730     entity,
    731     (owlready2.ObjectPropertyClass, owlready2.ObjectProperty),
    732 ):

ValueError: Relation <class 'object'> not found in entity.mro().

The problem occurs for all ObjectProperties, which are a subproperty of hasHolisticRelation, but e.g. does not occur for other relations such as hasPart, hasParticipant, hasSign etc.

Do you have an idea what might be the cause?

@francescalb
Copy link
Collaborator

Hi, thanx for pointing this out. I have changed so that relations that do not have a default style will use the overall default style (olive, solid line). At the same time a warning is printed.

I suggest that you add edgelabel=True if you want to check more what is what.

I will make a new issue about adding defaults for new relations in EMMO 1.0.0-beta4.

Note that this change is not added to the pypi package just yet, but it will happen soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants