use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class RegistryManagerImpl method populateOntology.
protected RegistryOntology populateOntology(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI ontId = ind.getIRI();
RegistryItem ront = null;
if (population.containsKey(ontId)) {
// We are not allowing multityping either.
ront = population.get(ontId);
if (!(ront instanceof RegistryOntology))
throw new RegistryContentException("Inconsistent multityping: for item " + ontId + " : {" + RegistryOntology.class + ", " + ront.getClass() + "}");
} else {
ront = riFactory.createRegistryOntology(ind);
try {
population.put(ront.getIRI(), ront);
} catch (Exception e) {
log.error("Invalid identifier for library item " + ront, e);
return null;
}
}
// EXIT nodes.
Set<OWLNamedObject> libs = new HashSet<OWLNamedObject>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (OWLOntology o : registries) {
if (ind instanceof OWLIndividual) {
// Get usages of isOntologyOf as an object property
for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(isOntologyOf, o)) if (value.isNamed())
libs.add(value.asOWLNamedIndividual());
// Get usages of isOntologyOf as an annotation property
for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (isOntologyOfAnn.equals(ann.getProperty())) {
OWLAnnotationValue value = ann.getValue();
if (value instanceof OWLNamedObject)
libs.add((OWLNamedObject) value);
else if (value instanceof IRI)
libs.add(df.getOWLNamedIndividual((IRI) value));
}
}
}
for (OWLNamedObject ilib : libs) {
IRI parentId = ilib.getIRI();
// If some populate*() method has created it, it will be there.
RegistryItem rlib = population.get(parentId);
// Otherwise populating it will also put it in population.
if (rlib == null)
rlib = populateLibrary(ilib, registries);
ront.addParent(rlib);
if (ontologyIndex.get(ontId) == null)
ontologyIndex.put(ontId, new HashSet<IRI>());
ontologyIndex.get(ontId).add(parentId);
}
return (RegistryOntology) ront;
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class TestOntologyRegistry method testRegistryUnion.
/**
* Verifies that, when loading multiple registries that add library information to each other, the overall
* model reflects the union of these registries.
*
* @throws Exception
*/
@Test
public void testRegistryUnion() throws Exception {
// Create the model from two overlapping registries.
Set<OWLOntology> regs = new HashSet<OWLOntology>();
regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST));
regs.add(virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_ADDITIONS));
Set<Registry> rs = regman.createModel(regs);
for (Registry r : rs) {
// The nonexistent library should also be included, if using the more powerful algorithm.
// set to 2 if using the less powerful algorithm.
int count = 3;
if (Locations._REGISTRY_TEST.equals(r.getIRI()))
assertEquals(count, r.getChildren().length);
else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI()))
assertEquals(1, r.getChildren().length);
// Check that we find the expected ontology in the expected library.
for (RegistryItem lib : r.getChildren()) {
if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
boolean found = false;
for (RegistryItem child : lib.getChildren()) {
if (child instanceof RegistryOntology && Locations.ONT_TEST1.equals(child.getIRI())) {
found = true;
break;
}
}
assertTrue(found);
break;
}
}
}
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class TestOntologyRegistry method testLoopInLibrary.
@Test
public void testLoopInLibrary() throws Exception {
// Create the model from the looping registry.
OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_LOOP);
Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
// There has to be a single registry, with the expected number of children (one).
assertEquals(1, rs.size());
Registry r = rs.iterator().next();
assertTrue(r.hasChildren());
int count = 1;
assertEquals(count, r.getChildren().length);
// There are no libreries without ontologies in the test registry.
for (RegistryItem child : r.getChildren()) {
assertTrue(child instanceof Library);
// Check both parent-child relations.
assertTrue(child.hasChildren());
for (RegistryItem grandchild : child.getChildren()) {
assertTrue(grandchild instanceof RegistryOntology);
assertTrue(grandchild.hasParents());
assertTrue(Arrays.asList(grandchild.getParents()).contains(child));
}
}
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class LibraryImpl method getOntology.
@Override
public <O> O getOntology(IRI id, Class<O> returnType) throws RegistryContentException {
/*
* Note that this implementation is not synchronized. Listeners may indefinitely be notified before or
* after the rest of this method is executed. If listeners call loadOntologies(), they could still get
* a RegistryContentException, which however they can catch by calling loadOntologies() and
* getOntologies() in sequence.
*/
fireContentRequested(this);
// If no listener has saved the day by loading the ontologies by now, an exception will be thrown.
if (!loaded)
throw new LibraryContentNotLoadedException(this);
O ontology = null;
RegistryItem child = getChild(id);
if (child instanceof RegistryOntology) {
ontology = getCache().getStoredOntology(child.getIRI(), returnType);
}
return ontology;
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology in project stanbol by apache.
the class LibraryImpl method loadOntologies.
@Override
public synchronized void loadOntologies(OntologyProvider<?> loader) {
if (loader == null)
throw new IllegalArgumentException("A null loader is not allowed.");
for (RegistryItem item : getChildren()) {
if (item instanceof RegistryOntology) {
RegistryOntology o = (RegistryOntology) item;
IRI id = o.getIRI();
try {
// No preferred key, we don't have a prefix here.
OWLOntologyID key = loader.loadInStore(id, null, false);
if (key == null || key.isAnonymous())
log.error("Empty storage key. Ontology {} was apparently not stored.", id);
} catch (IOException ex) {
log.error("I/O error occurred loading {}", id);
}
}
}
loaded = true;
}
Aggregations