1

Instead of having to copy the full IRI when defining the ontology in Turtle, is there a way to re-use the @base, : or my-base: instead?

NOTE: @base provides a prefix for relative IRIs using <...>. So in the example below, <Entity> expands to <http://my-url.com/ontologies/0.1/entity#Entity>.

Could I use any of the first three lines instead of the 4th line from below (<http://my-url.com/ontologies/0.1/entity>)?

@base          <http://my-url.com/ontologies/0.1/entity#> .
@prefix :      <http://my-url.com/ontologies/0.1/entity#> .
@prefix ent:   <http://my-url.com/ontologies/0.1/entity#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .

<http://my-url.com/ontologies/0.1/entity>
  a owl:Ontology .
hoijui
  • 3,615
  • 2
  • 33
  • 41

2 Answers2

3

NOTE: @base provides a prefix for relative IRIs using <...>. So in the example below, <Entity> expands to <http://my-url.com/ontologies/0.1/entity#Entity>.

Where did you get this idea from? This is not the case. @base is not prefixing whatever is in between the < and >. @base defines the base IRI over which relative IRIs are resolved. Resolving relative IRIs is more complicated than concatenating two strings.

First, a base IRI is necessarily stripped off of its trailing # and any fragment identifier. So, if you write:

@base <http://my-url.com/ontologies/0.1/entity#> .
<> a owl:Ontology .

you mean:

<http://my-url.com/ontologies/0.1/entity> a owl:Ontology .

you would have to add a # explicitly to have it in the IRI:

@base <http://my-url.com/ontologies/0.1/entity#> .
<#> a owl:Ontology .

means:

<http://my-url.com/ontologies/0.1/entity#> a owl:Ontology .

If you want to add a non empty fragment identifier, you need the # as well:

@base <http://my-url.com/ontologies/0.1/entity#> .
<#Entity> a owl:Ontology .

means:

<http://my-url.com/ontologies/0.1/entity#Entity> a owl:Ontology .

Second, if you use a non empty string between the < and >, and it is not a fragment identifier, then the IRI is constructed by getting rid of the local part of the base, which is whatever appear after the last / of the path of the IRI. E.g.,

@base <http://my-url.com/ontologies/0.1/entity#> .
<Entity> a owl:Ontology .

means:

<http://my-url.com/ontologies/0.1/Entity> a owl:Ontology .

Another example:

@base <http://my-url.com/something/?uri=http://example.com/anything> .
<Entity> a owl:Ontology .

means:

<http://my-url.com/something/Entity> a owl:Ontology .

This is not, properly speaking, a direct answer to your question(s) but should suffice to allow you to take the right decision.

Antoine Zimmermann
  • 5,314
  • 18
  • 36
  • If I replace `@base .` with `@base .` (removing the `#`), would your examples still work the same, or would the `entity` part then be missing in all the relative IRIs? – hoijui Nov 05 '19 at 09:59
  • 1
    The hash in a `@base` declaration really doesn't make any difference, as far as I know. – Antoine Zimmermann Nov 05 '19 at 21:08
0

Thanks to the answer by Antonine Zimmermann, I came up with this solution:

@base          <http://my-url.com/ontologies/0.1/entity> .
@prefix ent:   <#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .

<>
  a owl:Ontology .

ent:MyClass
  a owl:Class .

This way, I can use both @base and the named prefix ent: without having to repeat the base-IRI.

I chose named over empty prefix, because it makes the code more portable and creates nicer output with rdf2dot (and probably other tools).

hoijui
  • 3,615
  • 2
  • 33
  • 41