Classes with ? at the end can be created, but not queried

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

Classes with ? at the end can be created, but not queried

maxrosen
This post was updated on .
This successfully creates a new class for a class_name ending with "?":

or_subclass = or2.types.new_class(class_name, (or_superclass,))

But both of these will return the iri for the new class without the "?" in the end:

or_superclass.subclasses()

SELECT ?s WHERE { ?s rdfs:subClassOf <""" + or_superclass_iri + """> . }
Reply | Threaded
Open this post in threaded view
|

Re: Classes with ? at the end can be created, but not queried

Jiba
Administrator
Hello,

I tried to reproduce the problem with the following code, but I was unable to. Could you try it, and see what happens ?

Jiba


from owlready2 import *
import sys, os, time, types, datetime

onto = get_ontology("http://test.org/onto.owl")

with onto:
  C = types.new_class("C?", (Thing,))
  class D(C): pass
print(C)

r = default_world.sparql("""
SELECT ?s WHERE { ?s rdfs:subClassOf <""" + C.iri + """> . }
""")

print(list(r))
print(list(C.subclasses()))
Reply | Threaded
Open this post in threaded view
|

Re: Classes with ? at the end can be created, but not queried

maxrosen
Hm, your example works. And I can't seem to reproduce it either.

Thanks for looking into this. Sorry for wasting your time.
Reply | Threaded
Open this post in threaded view
|

Re: Classes with ? at the end can be created, but not queried

maxrosen
In reply to this post by Jiba
OK, I succeeded in reproducing it. In the ontology below (icd10cm.owl), H54.415? is a child of H54.415, but H54.415 is returned, leading to a cycle. If unrelated parts of the ontology are deleted (result: untitled.owl), H54.415? is correctly returned.

DOES NOT WORK:

import owlready2 as or2

icd10cm_ontology = or2.get_ontology("/Users/xxx/icd10cm.owl").load()

ontology_prefix = "http://purl.bioontology.org/ontology/ICD10CM/"
class_reference = "H54.415"

hi_owlready = or2.default_world[ontology_prefix + class_reference]

children1 = hi_owlready.subclasses()

print(list(children1))

Output:

[icd10cm.H54.415, icd10cm.H54.415A]
* Owlready2 * Warning: ignoring cyclic subclass of/subproperty of, involving:
  http://purl.bioontology.org/ontology/ICD10CM/H54.415

WORKS:

import owlready2 as or2

icd10cm_ontology = or2.get_ontology("/Users/xxx/untitled.owl").load()

ontology_prefix = "http://purl.bioontology.org/ontology/ICD10CM/"
class_reference = "H54.415"

hi_owlready = or2.default_world[ontology_prefix + class_reference]

children1 = hi_owlready.subclasses()

print(list(children1))

Output: [untitled.H54.415A, untitled.H54.415?]

The ontologies are here: https://uni-bonn.sciebo.de/s/uhj0ZoWMYl4oc2a
Reply | Threaded
Open this post in threaded view
|

Re: Classes with ? at the end can be created, but not queried

Jiba
Administrator
I found the problem : Owlready was using urllib.parse.urljoin, but it removes the trailing '?', if any (for an URL, it is supposed to be OK).

I reimplemented urljoin, and it should now be ok in the development version of Owlready on Bitbucket.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Classes with ? at the end can be created, but not queried

maxrosen
Awesome. Thanks for looking into this.