This post was updated on .
Hello.
I am working in an ontology whose classes are defined in a different namespace. My task is the following: - I have a value restriction 'ValueRestriction1', whose class inside the .value attribute is in a namespace which is different from the ontology; - I need to create a new class 'FreshClassX' in this namespace; - I need to create a new GeneralClassAxiom such that 'ValueRestriction1' is featured on the left side and 'FreshClassX' on the right side. Ideally, I would need to create these FreshClassX classes dynamically.For now I am just trying to understand the simplest way of doing it. I understand that the syntax with onto: NewClass = types.new_class("NewClassName", (SuperClass,)) serves this purpose, but I don't see how to pass the correct namespace to it. Anyhow, I am still stuck in the simple case. Whenever I do it, I get an error: 'OwlReadySharedBlankNodeError: A Construct cannot be shared by two ontologies, because it correspond to a RDF blank node. Please create a dupplicate.' This is how I am loading the ontology and defining namespaces: This is the function. The error comes when I try to append the FreshClass to the GCA: A few helpful prints regarding the different concepts and their namespaces/ontologies: The full error message: Edit: I've screwed around a bit more with the code and added the following print statements to the _set_ontology method: They give me the following output: ++++++++ INFO ABOUT CONSTRUCT +++++++++ Print(self) = factkb.hasSpecificationLevel.some(factkb.atLeastWellSpecified) <class 'owlready2.class_construct.Restriction'> This is the constructs value namespace: get_ontology("http://www.cs.man.ac.uk/~horrocks/OWL/Ontologies/galen.owl#").get_namespace("http://example.org/factkb#") This is the constructs ontology: get_ontology("http://www.cs.man.ac.uk/~horrocks/OWL/Ontologies/galen.owl#").get_namespace("http://example.org/factkb#") This is the constructs self.ontology: get_ontology("http://www.cs.man.ac.uk/~horrocks/OWL/Ontologies/galen.owl#") It seems to me that there is a mismatch occurring between the restriction and the classes. The restriction.ontology returns the ontology's iri while the classes in the restriction.value are defined in the namespace. But I must say I'm quite confused on how to redefine these things such that they will work. |
Administrator
|
Hello,
I think you are facing a limit of OWL and RDF. OWL distinguishes two types of entities: named entities, that have an IRI, and anonymous entities, that do not have an IRI and that are identified with a blank node. IRI are unique, and thus can be referred from other ontologies. On the contrary, blank nodes cannot be referred from other ontologies. In your example, FreshClassX is a named entity, but the restriction and the GCA are anonymous. Consequently, the restriction and the GCA must be defined in the same ontology. Regarding the dynamic creation of FreshClassX, you can create it in a namespace with the "with...:" syntax: with namespace: NewClass = types.new_class("NewClassName", (SuperClass,)) The namespace can be an ontology, or a namespace that refer to an ontology (e.g. factkb). Jiba |
This post was updated on .
Hey, thank you for your answer!
I am still confused. I tried working with an ontology that makes no use of namespaces, and everything is defined in the ontology itself. If I understood you correctly, there should be no issue as FreshClass and the GCA are being created in the same ontology. The print of the function being called (here, tbox_axiom means a GCA type statement): The prints showing that everything is being defined in the same ontology 'onto' (notice there is no factkb namespace anymore, or any such thing). I also tried to define a similar function, manipulating classes and GCAs, without defining any new ontologies, namespaces or class names. When I create the GCA by explicitly typing out the classes and the construct, it works. When I do it when the construct is stored in a variable, it doesn't. I even included checks to ensure that the variable is storing exactly what I write explicitly: Is there something I am missing here? |
Administrator
|
Hi,
It is not clear to me what is the value of the "concept_class" variable. You create it from the "classes" variable, but I cannot find the definition of "classes". You should explore the content of the value of the "concept_class" variable, e.g. by printing: concept_class.ontology. Jiba |
Free forum by Nabble | Edit this page |