Re: Ontology URI vs document URI

2022-04-03 Thread Martynas Jusevičius
On Fri, Apr 1, 2022 at 1:13 PM Andy Seaborne  wrote:
>
>
>
> On 26/03/2022 15:46, Martynas Jusevičius wrote:
> > Hi,
> >
> > Using the ontology API, if one owl:imports an ontology URI such as
> >  into ontology model, the imported model
> > gets cached under the "http://www.w3.org/ns/org#; key.
> >
> > However, given
> >
> >   a owl:Ontology
> >
> > one can argue that this URI is of the ontology resource, but what gets
> > loaded and cached is more than that -- it is the ontology *document*.
> > This relates to the old debate whether ontology instances should
> > contain the trailing # in their URIs, i.e. whether ontology and its
> > document is the same resource or distinct resources.
> >
> > The problem is that despite the ontology being cached, code that
> > attempts to dereference its document URI will not be able to make use
> > of it as "http://www.w3.org/ns/org; will not match the
> > "http://www.w3.org/ns/org#; cache key.
>
> This seems inconsistent of imports.
>
> You started with
>  > one owl:imports an ontology URI such as
>  > 
>
> so I don't understand where http://www.w3.org/ns/org comes in.

It comes from the Linked Data browser. The HTTP client dereferences
 because that is the document URI.

If the Org ontology is being dereferenced, but it's already been
imported using owl:imports, the browser should be able to take
advantage of the cached model (i.e. document). But it's not directly
connected to the OWL code and is not aware that this document contains
an ontology resource, it can only access the model cache.

At worse,
> things are cached twice, under two different names. There needs to be
> consistency in nmaing - same if http://www.w3.org/ns/org# and
> http://example/myCopy/org

There is no consistency in the general case, as I've tried to explain,
because some ontology URIs equal their document URIs (like SPIN) and
some don't (have a trailing #, like the Org ontology).

So far I've worked by adding a second cache key with the document URI:

OntModel ontModel =
ModelFactory.createOntologyModel(ontModelSpec, baseModel);
ontModel.getDocumentManager().addModel(uri, ontModel,
true); // add as OntModel so that imports do not need to be reloaded
during retrieval
// make sure to cache imported models not only by
ontology URI but also by document URI

ontModel.listImportedOntologyURIs(true).forEach((String importURI) ->
{
try
{
URI ontologyURI = URI.create(importURI);
// remove fragment and normalize
URI docURI = new URI(ontologyURI.getScheme(),
ontologyURI.getSchemeSpecificPart(), null).normalize();
String mappedURI =
ontModelSpec.getDocumentManager().getFileManager().mapURI(docURI.toString());
 // only cache import document URI if it's not
already cached or mapped
if
(!ontModelSpec.getDocumentManager().getFileManager().hasCachedModel(docURI.toString())
&& mappedURI.equals(docURI.toString()))
{
Model importModel =
ontModel.getDocumentManager().getModel(importURI);
if (importModel == null) throw new
IllegalArgumentException("Import model is not cached");

ontModel.getDocumentManager().addModel(docURI.toString(), importModel,
true);
}
}
catch (URISyntaxException ex)
{
throw new RuntimeException(ex);
}
});

>
> Your description says that http://www.w3.org/ns/org# is the import name.
>
> There is the LocationMapper that may help your application.

LocationMapper is unrelated IMO. I could solve this issue if there was
a way to specify or rewrite the import model cache key in the ODM (I
would use a convention where it equals the document URI without
fragment).

>
>  Andy
>
> >
> > My questions are:
> > 1. How can I work around this? Using some kind of post-loadImports()
> > hook to make cache entries for both URIs?
> > 2. Shouldn't the OWL import code be aware of this and cache the
> > document URI while using it as a base for all relative URIs (of
> > ontology terms)?
>
> The base has the same effect. Fragments are stripped on relative URI
> resolution.
>
> >
> > Martynas
> > atomgraph.com


Re: Ontology URI vs document URI

2022-04-01 Thread Andy Seaborne




On 26/03/2022 15:46, Martynas Jusevičius wrote:

Hi,

Using the ontology API, if one owl:imports an ontology URI such as
 into ontology model, the imported model
gets cached under the "http://www.w3.org/ns/org#; key.

However, given

  a owl:Ontology

one can argue that this URI is of the ontology resource, but what gets
loaded and cached is more than that -- it is the ontology *document*.
This relates to the old debate whether ontology instances should
contain the trailing # in their URIs, i.e. whether ontology and its
document is the same resource or distinct resources.

The problem is that despite the ontology being cached, code that
attempts to dereference its document URI will not be able to make use
of it as "http://www.w3.org/ns/org; will not match the
"http://www.w3.org/ns/org#; cache key.


This seems inconsistent of imports.

You started with
> one owl:imports an ontology URI such as
> 

so I don't understand where http://www.w3.org/ns/org comes in. At worse, 
things are cached twice, under two different names. There needs to be 
consistency in nmaing - same if http://www.w3.org/ns/org# and 
http://example/myCopy/org


Your description says that http://www.w3.org/ns/org# is the import name.

There is the LocationMapper that may help your application.

Andy



My questions are:
1. How can I work around this? Using some kind of post-loadImports()
hook to make cache entries for both URIs?
2. Shouldn't the OWL import code be aware of this and cache the
document URI while using it as a base for all relative URIs (of
ontology terms)?


The base has the same effect. Fragments are stripped on relative URI 
resolution.




Martynas
atomgraph.com


Re: Ontology URI vs document URI

2022-03-26 Thread Martynas Jusevičius
It doesn't look like the ReadHook is applied on the cache key, unfortunately.

The problematic OntDocumentManager code is here:
https://github.com/apache/jena/blob/main/jena-core/src/main/java/org/apache/jena/ontology/OntDocumentManager.java#L983

On Sat, Mar 26, 2022 at 5:09 PM Martynas Jusevičius
 wrote:
>
> Could OntDocumentManager.ReadHook be used for this?
> https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/ontology/OntDocumentManager.ReadHook.html
>
> On Sat, Mar 26, 2022 at 4:46 PM Martynas Jusevičius
>  wrote:
> >
> > Hi,
> >
> > Using the ontology API, if one owl:imports an ontology URI such as
> >  into ontology model, the imported model
> > gets cached under the "http://www.w3.org/ns/org#; key.
> >
> > However, given
> >
> >  a owl:Ontology
> >
> > one can argue that this URI is of the ontology resource, but what gets
> > loaded and cached is more than that -- it is the ontology *document*.
> > This relates to the old debate whether ontology instances should
> > contain the trailing # in their URIs, i.e. whether ontology and its
> > document is the same resource or distinct resources.
> >
> > The problem is that despite the ontology being cached, code that
> > attempts to dereference its document URI will not be able to make use
> > of it as "http://www.w3.org/ns/org; will not match the
> > "http://www.w3.org/ns/org#; cache key.
> >
> > My questions are:
> > 1. How can I work around this? Using some kind of post-loadImports()
> > hook to make cache entries for both URIs?
> > 2. Shouldn't the OWL import code be aware of this and cache the
> > document URI while using it as a base for all relative URIs (of
> > ontology terms)?
> >
> > Martynas
> > atomgraph.com


Re: Ontology URI vs document URI

2022-03-26 Thread Martynas Jusevičius
Could OntDocumentManager.ReadHook be used for this?
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/ontology/OntDocumentManager.ReadHook.html

On Sat, Mar 26, 2022 at 4:46 PM Martynas Jusevičius
 wrote:
>
> Hi,
>
> Using the ontology API, if one owl:imports an ontology URI such as
>  into ontology model, the imported model
> gets cached under the "http://www.w3.org/ns/org#; key.
>
> However, given
>
>  a owl:Ontology
>
> one can argue that this URI is of the ontology resource, but what gets
> loaded and cached is more than that -- it is the ontology *document*.
> This relates to the old debate whether ontology instances should
> contain the trailing # in their URIs, i.e. whether ontology and its
> document is the same resource or distinct resources.
>
> The problem is that despite the ontology being cached, code that
> attempts to dereference its document URI will not be able to make use
> of it as "http://www.w3.org/ns/org; will not match the
> "http://www.w3.org/ns/org#; cache key.
>
> My questions are:
> 1. How can I work around this? Using some kind of post-loadImports()
> hook to make cache entries for both URIs?
> 2. Shouldn't the OWL import code be aware of this and cache the
> document URI while using it as a base for all relative URIs (of
> ontology terms)?
>
> Martynas
> atomgraph.com


Ontology URI vs document URI

2022-03-26 Thread Martynas Jusevičius
Hi,

Using the ontology API, if one owl:imports an ontology URI such as
 into ontology model, the imported model
gets cached under the "http://www.w3.org/ns/org#; key.

However, given

 a owl:Ontology

one can argue that this URI is of the ontology resource, but what gets
loaded and cached is more than that -- it is the ontology *document*.
This relates to the old debate whether ontology instances should
contain the trailing # in their URIs, i.e. whether ontology and its
document is the same resource or distinct resources.

The problem is that despite the ontology being cached, code that
attempts to dereference its document URI will not be able to make use
of it as "http://www.w3.org/ns/org; will not match the
"http://www.w3.org/ns/org#; cache key.

My questions are:
1. How can I work around this? Using some kind of post-loadImports()
hook to make cache entries for both URIs?
2. Shouldn't the OWL import code be aware of this and cache the
document URI while using it as a base for all relative URIs (of
ontology terms)?

Martynas
atomgraph.com