use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem 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.RegistryItem in project stanbol by apache.
the class TestOntologyRegistry method testPopulateRegistry.
/**
* Verifies that a call to {@link RegistryManager#createModel(Set)} with a registry location creates the
* object model accordingly.
*
* @throws Exception
*/
@Test
public void testPopulateRegistry() throws Exception {
// Create the model from a single registry.
OWLOntology oReg = virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
// There has to be a single registry, with the expected number of children.
assertEquals(1, rs.size());
Registry r = rs.iterator().next();
assertTrue(r.hasChildren());
// 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;
assertEquals(count, r.getChildren().length);
// There are no libraries without ontologies in the test registry.
for (RegistryItem ri : r.getChildren()) assertTrue(ri.hasChildren());
}
use of org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem 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.RegistryItem 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.RegistryItem 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