`DocumentGraphRepository` is very simple: 
https://github.com/apache/jena/blob/main/jena-ontapi/src/main/java/org/apache/jena/ontapi/impl/repositories/DocumentGraphRepository.java
It is just like extended Map.
So, yes, you can associate the same graph with different keys using method 
`put`. But the method `addMapping` works differently - it will cause the graph 
to be lazily reloaded from the same document, i.e. two or more keys will be 
associated with different graph containing the same content.
(maybe it is not correct behavior?).

updated example:
```
        DocumentGraphRepository repository = 
GraphRepository.createGraphDocumentRepositoryMem();
        repository.addMapping(
                "http://www.co-ode.org/ontologies/pizza/pizza.owl";,
                documentPath);
        OntModel a = OntModelFactory.getModelOrNull(
                "http://www.co-ode.org/ontologies/pizza/pizza.owl";,
                OntSpecification.OWL2_DL_MEM_BUILTIN_RDFS_INF,
                repository);
        repository.put("b", a.getGraph());
        OntModel b = OntModelFactory.createModel(repository.get("b"));
        b.write(System.out, "ttl");
```

but in combination with `OntModel`, `DocumentGraphRepository` starts to work a 
little differently - the source (base) graph is replaced by `UnionGraph`, which 
manages imports closure, so, for example, adding import via 
`OntModel#addImport(OntModel)` or `OntID#addImport(String)` will cause adding 
corresponding graph into the repository.

On 2024/08/08 13:24:45 Steve Vestal wrote:
> I think the OWL2 spec clarifies that imports should name the ontology or 
> version IRI, but in practice there are a lot of models that import by 
> URL.  If an ontology document in a repo goes through a series of updates 
> and commits, some of which are tagged as having an updated version IRI, 
> the ontology developer might just give the users URLs for specific 
> commits to import the version they desire.
> 
> But does a DocumentGraphRepository care whether the addMapping string is 
> an ontology IRI or not?  Isn't it just a URI that gets mapped to a URL 
> (the documentPath)?  Couldn't I just do three different addMappings for 
> the same documentPath, and it doesn't matter whether the different users 
> import via URL, ontology IRI, or version IRI?
> 
> On 8/8/2024 2:07 AM, Sergei Zuev wrote:
> > In the new API, the ontology identifier is either the version IRI or the 
> > ontology IRI. The document IRI is not an identifier.
> > Perhaps this is a flaw - document support was added at the last moment, and 
> > for managing imports closure no document-manager is needed.
> >
> > Typical work with documents can be like this:
> > ```
> >          DocumentGraphRepository repository = 
> > GraphRepository.createGraphDocumentRepositoryMem();
> >          repository.addMapping(
> >                  "http://www.co-ode.org/ontologies/pizza/pizza.owl";,
> >                  documentPath);
> >          OntModel m = OntModelFactory.getModelOrNull(
> >                  "http://www.co-ode.org/ontologies/pizza/pizza.owl";,
> >                  OntSpecification.OWL2_DL_MEM_BUILTIN_RDFS_INF,
> >                  repository);
> >          m.write(System.out, "ttl");
> > ```
> >
> > Here, `http://www.co-ode.org/ontologies/pizza/pizza.owl` is an ontology 
> > IRI. `DocumentGraphRepository` manages mappings between documents and 
> > ontologies.
> >
> > If you think that some functionality is missing, please open a github issue.
> >
> > By the way, the external library owlcs/ontapi, which works on top of 
> > apache-ontapi, has its own full-fledged ontology manager, which works 
> > according to the specification, i.e. the ontology identifier can also be a 
> > document IRI.
> >
> > On 2024/08/07 11:15:58 Steve Vestal wrote:
> >> I have some questions about doing an OWL import closure.  My
> >> understanding is that an Import for an owl:Ontology can use any of a
> >> URL, an ontology IRI, or a version IRI to access an OWL document.
> >> Different documents that have the same ontology IRI may be accessed
> >> using different URLs, either identical copies or with different version
> >> IRIs.
> >>
> >> The link given on the page
> >> https://jena.apache.org/documentation/ontology/#graphrepository
> >> (https://jena.apache.org/documentation/javadoc/jena/org.apache.jena.ontapi/org/apache/jena/ontapi/GraphRepository.html)
> >> gets a "URL was not found" error.  A search didn't turn it up. What
> >> package contains this class?
> >>
> >> That page says "By default, when an ontology model reads an ontology
> >> document, it will/not/locate and load the document’s imports."  A search
> >> of this page did not find OntDocumentManager, which I have been using.
> >> FileManager seems to be deprecated in favor of RDFDataMgr.  Will
> >> OntDocumentManager be deprecated or modified?
> >>
> >> What is the recommended way to accumulate a set of URLs, ontology IRIs,
> >> and version IRIs, and use that set to do an import closure?
> >>
> 

Reply via email to