Hi,
I'm exploring owlready and I've found an example to find ancestor in another thread: http://owlready.8326.n8.nabble.com/Problem-with-inferring-classes-caused-by-logical-operators-td1403.html Which works for me. But when I try with the ontology I want to use, I get an error: __venv__\Scripts\python.exe owlready_ancecestor_issue.py * Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation obo.FOODON_03311121 Traceback (most recent call last): File "owlready_ancecestor_issue.py", line 18, in <module> all_ancestors(my_white_rice) File "owlready_ancecestor_issue.py", line 12, in all_ancestors ancestors.update(c.ancestors()) File "__venv__\lib\site-packages\owlready2\entity.py", line 278, in ancestors Class._fill_ancestors(s, include_self, include_constructs) File "__venv__\lib\site-packages\owlready2\entity.py", line 312, in _fill_ancestors parent._fill_ancestors(s, True, False) File "__venv__\lib\site-packages\owlready2\entity.py", line 312, in _fill_ancestors parent._fill_ancestors(s, True, False) File "__venv__\lib\site-packages\owlready2\entity.py", line 312, in _fill_ancestors parent._fill_ancestors(s, True, False) File "__venv__\lib\site-packages\owlready2\entity.py", line 296, in _fill_ancestors for equivalent in Class.equivalent_to.indirect(): File "__venv__\lib\site-packages\owlready2\entity.py", line 41, in indirect if self._indirect is None: self._build_indirect() File "__venv__\lib\site-packages\owlready2\entity.py", line 37, in _build_indirect for o in n.world._get_obj_triples_transitive_sym(self._obj.storid, self._obj._owl_equivalent) File "__venv__\lib\site-packages\owlready2\entity.py", line 38, in <genexpr> if o != self._obj.storid )) File "__venv__\lib\site-packages\owlready2\namespace.py", line 259, in _to_python if o < 0: return self._parse_bnode(o) File "__venv__\lib\site-packages\owlready2\namespace.py", line 1032, in _parse_bnode r = self.world._get_by_storid(bnode, main_onto = self) File "__venv__\lib\site-packages\owlready2\namespace.py", line 537, in _get_by_storid return self._load_by_storid(storid, full_iri, main_type, main_onto, default_to_none) File "__venv__\lib\site-packages\owlready2\namespace.py", line 610, in _load_by_storid entity = ThingClass(name, types, { "namespace" : namespace, "storid" : storid } ) File "__venv__\lib\site-packages\owlready2\entity.py", line 144, in __new__ Class = namespace.world._entities[storid] = _is_a._obj = type.__new__(MetaClass, name, superclasses, obj_dict) TypeError: type.__new__() argument 1 must be str, not int This is the code I'm using: import owlready2 foodon = owlready2.get_ontology("http://purl.obolibrary.org/obo/foodon.owl") foodon.load() obo = foodon.get_namespace("http://purl.obolibrary.org/obo/") def all_ancestors(indiv): ancestors = set() for c in indiv.is_a: if isinstance(c, owlready2.EntityClass): print(c) ancestors.update(c.ancestors()) print(ancestors) with foodon: WhiteRice = obo.FOODON_03311121 my_white_rice = WhiteRice() all_ancestors(my_white_rice) There might be mistakes in the ontology or the (many) imports but the error message is not telling me enough to find it. Right after the crash in debug I find this: <class 'dict'>: {'namespace': get_ontology("http://purl.obolibrary.org/obo/foodon/imports/foodon_product_import.owl#"), 'storid': -30, '_name': -30, 'is_a': [owl.Thing], '_equivalent_to': None} Can someone help me out? Thanks in advance |
Administrator
|
Hi,
Thank you for reporting this problem. It was caused by some complew use of blank node use, mixing several ontologies. I fixed it in the development version of Owlready, coul dyou try again? By the way, you can just use list(obo.FOODON_03311121.ancestors()) if you want the ancestor of a class. Jiba |
Indeed it works with the development version, thanks for the quick fix! On Fri, Nov 8, 2019, at 18:03, Jiba [via Owlready] wrote:
|
Free forum by Nabble | Edit this page |