oeg-upm / Chowlk

Tool to transform an ontology diagram into OWL code.
Apache License 2.0
22 stars 6 forks source link

Implement @base directive #13

Closed GordianDziwis closed 4 months ago

GordianDziwis commented 3 years ago

Enabling the base directive would also clean up the diagrams, because the base prefix can be omitted.

https://github.com/oeg-upm/chowlk_spec/issues/35

mariapoveda commented 2 years ago

Do you mean to keep the prefix empty in the module you are editing?

GordianDziwis commented 2 years ago

Here is the difference between an empty and a base prefix explained: https://stackoverflow.com/questions/34146707/turtle-difference-between-base-and-empty-prefix Having a base prefix gives a mechanism to use relative paths in the data, and then use an external base URI (instead of whatever is declared in the file) to resolve them. This can be useful for things like hosting the same data in multiple locations.

mariapoveda commented 1 year ago

then, if the user includes "base" in the prefixes, every element with "ID" will be created in the base prefix, and if there is an empty prefix the elements with ":ID" will be created in the empty one. Is that ok?

GordianDziwis commented 1 year ago

I think you also have to create the resources as a URI or prefixed name depending on if it relates to the empty namespace or base directive. For example, this graph: image should translate to:

@base <http://base.namespace.com/> 
@prefix : <http://empty.namespace.com/> 

<baseNSIndividiual> rdf:type owl:Individual .
:emptyNSIndividual rdf:type owl:Individual .

As you can see <baseNSIndividiual> is an IRI and :emptyNSIndividual is a prefixed name.

GordianDziwis commented 1 year ago

Nice that you added this feature, unfortunately it does not work yet.

image

@prefix : <https://foo.bar#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

: a owl:Ontology ;
    dc:description "Ontology code created by Chowlk" .

:NoPrefix a owl:Class ;
    rdfs:label "No Prefix>" .

Not a @base prefix is created, but an empty prefix. Also the label does not get parsed correctly.

GordianDziwis commented 1 year ago

Also in your Notation the output is wrong:

prefix : <https://w3id.org/def/saref4bldg#> .
...
@base <https://w3id.org/def/saref4bldg#> .
<https://w3id.org/def/saref4bldg#Class1> a owl:Class . # should be <Class1> a owl:Class
:Class2 a owl:Class .
mariapoveda commented 1 year ago

Hello @BonaBeavis we are reviewing your PR and also wondering whether the owl:Ontology should be created for diagrams with no metadata block. It seems it doesn't make sense to generate that tag if the user is only defining data triples. What do you think?

Regarding the @base it is not possible to keep it in the output as rdflib removes it.

Sergio-Carulli commented 1 year ago

Hello @BonaBeavis. When chowlk converts the diagram to a turtle file it uses rdflib to parse the ontology. However, rdflib resolves a relative IRI between <> directly to the current base IRI. For example, if the input is the following:

image The output of rdflib is the following:

image

Anyway, we believe that the problem lies in the fact that Chowlk currently takes the first prefix defined as the IRI of the ontology if a "base" has not been defined. Otherwise, the IRI defined within "base" is taken as the IRI of the ontology. In addition, if the user does not define the empty prefix ":", the empty prefix is automatically generated with the same IRI as the ontology IRI. That is why you get the outputs you mentioned above.

Now we are thinking that the ontology IRI should not be generated directly because it can generate unwanted results (like the one you posted).

GordianDziwis commented 1 year ago

I started a fix:

https://github.com/oeg-upm/Chowlk/pull/54

Sergio-Carulli commented 7 months ago

Hello @BonaBeavis,

Now chowlk resolves the relative IRIs to write the absolute IRIs in the ontology code. Thus there are two cases:

Case 1: image

Case 2: image

However chowlk will not write an explicit @base. Chowlk generates an intermediate file with a first version of the ontology code (in which an @base is declared), and then this code is parsed by rdflib to generate the chowlk output (in which rdflib directly resolves the relative IRIs).