use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class TestClerezzaSpaces method testRemoveCustomOntology.
@Test
public void testRemoveCustomOntology() throws Exception {
OntologySpace space = null;
space = factory.createCustomOntologySpace(scopeId, dropSrc);
OWLOntologyID dropId = OWLUtils.extractOntologyID(dropSrc.getRootOntology());
OWLOntologyID nonexId = OWLUtils.extractOntologyID(nonexSrc.getRootOntology());
space.addOntology(inMemorySrc);
space.addOntology(nonexSrc);
// The other remote ontologies may change base IRI...
// baseIri is maincharacters
assertTrue(space.hasOntology(baseIri));
assertTrue(space.hasOntology(dropId));
assertTrue(space.hasOntology(nonexId));
space.removeOntology(dropId);
assertFalse(space.hasOntology(dropId));
space.removeOntology(nonexId);
assertFalse(space.hasOntology(nonexId));
// OntologyUtils.printOntology(space.getTopOntology(), System.err);
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class TestOntologySpaces method testIdentifiers.
/**
* Checks whether attempting to create ontology spaces with invalid identifiers or namespaces results in
* the appropriate exceptions being thrown.
*
* @throws Exception
* if an unexpected error occurs.
*/
@Test
public void testIdentifiers() throws Exception {
OntologySpace shouldBeNull = null, shouldBeNotNull = null;
// Null identifier (invalid).
try {
shouldBeNull = factory.createOntologySpace(null, SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite null scope identifier.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
// More than one slash in identifier (invalid).
try {
shouldBeNull = factory.createOntologySpace("Sc0/p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite null scope identifier.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
/* Now test namespaces. */
// Null namespace (invalid).
factory.setDefaultNamespace(null);
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite null OntoNet namespace.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
// Namespace with query (invalid).
factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/?query=true"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite query in OntoNet namespace.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
// Namespace with fragment (invalid).
factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#fragment"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE, new BlankOntologySource());
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
// Namespace ending with hash (invalid).
factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology#"));
try {
shouldBeNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
fail("Expected IllegalArgumentException not thrown despite fragment in OntoNet namespace.");
} catch (IllegalArgumentException ex) {
}
assertNull(shouldBeNull);
// Namespace ending with neither (valid, should automatically add slash).
factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
assertTrue(shouldBeNotNull.getDefaultNamespace().toString().endsWith("/"));
shouldBeNotNull = null;
// Namespace ending with slash (valid).
factory.setDefaultNamespace(IRI.create("http://stanbol.apache.org/ontology/"));
shouldBeNotNull = factory.createOntologySpace("Sc0p3", SpaceType.CORE);
assertNotNull(shouldBeNotNull);
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class TestOntologySpaces method testCreateSpace.
@Test
public void testCreateSpace() throws Exception {
OntologySpace space = factory.createCustomOntologySpace("testCreateSpace", dropSrc);
IRI logicalId = dropSrc.getRootOntology().getOntologyID().getOntologyIRI();
assertTrue(space.hasOntology(logicalId));
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class CustomSpaceImpl method equals.
@Override
public boolean equals(Object arg0) {
if (arg0 == null)
return false;
if (!(arg0 instanceof OntologySpace))
return false;
if (this == arg0)
return true;
log.warn("{} only implements weak equality, i.e. managed ontologies are only checked by public key, not by content.", getClass());
OntologySpace sp = (OntologySpace) arg0;
if (!super.equals(arg0))
return false;
if (!this.getConnectivityPolicy().equals(sp.getConnectivityPolicy()))
return false;
return true;
}
use of org.apache.stanbol.ontologymanager.servicesapi.scope.OntologySpace in project stanbol by apache.
the class RefactorEnhancementEngine method initEngine.
/**
* Method for adding ontologies to the scope core ontology.
* <ol>
* <li>Get all the ontologies from the property.</li>
* <li>Create a base scope.</li>
* <li>Retrieve the ontology space from the scope.</li>
* <li>Add the ontologies to the scope via ontology space.</li>
* </ol>
*/
private void initEngine(RefactorEnhancementEngineConf engineConfiguration) {
// IRI dulcifierScopeIRI = org.semanticweb.owlapi.model.IRI.create((String) context.getProperties().get(SCOPE));
String scopeId = engineConfiguration.getScope();
// Create or get the scope with the configured ID
try {
scope = onManager.createOntologyScope(scopeId);
// No need to deactivate a newly created scope.
} catch (DuplicateIDException e) {
scope = onManager.getScope(scopeId);
onManager.setScopeActive(scopeId, false);
}
// All resolvable ontologies stated in the configuration are loaded into the core space.
OntologySpace ontologySpace = scope.getCoreSpace();
ontologySpace.tearDown();
String[] coreScopeOntologySet = engineConfiguration.getScopeCoreOntologies();
List<String> success = new ArrayList<String>(), failed = new ArrayList<String>();
try {
log.info("Will now load requested ontology into the core space of scope '{}'.", scopeId);
OWLOntologyManager sharedManager = OWLManager.createOWLOntologyManager();
org.semanticweb.owlapi.model.IRI physicalIRI = null;
for (int o = 0; o < coreScopeOntologySet.length; o++) {
String url = coreScopeOntologySet[o];
try {
physicalIRI = org.semanticweb.owlapi.model.IRI.create(url);
} catch (Exception e) {
failed.add(url);
}
try {
// TODO replace with a Clerezza equivalent
ontologySpace.addOntology(new RootOntologySource(physicalIRI, sharedManager));
success.add(url);
} catch (OWLOntologyCreationException e) {
log.error("Failed to load ontology from physical location " + physicalIRI + " Continuing with next...", e);
failed.add(url);
}
}
} catch (UnmodifiableOntologyCollectorException ex) {
log.error("Ontology space {} was found locked for modification. Cannot populate.", ontologySpace);
}
for (String s : success) log.info(" >> {} : SUCCESS", s);
for (String s : failed) log.info(" >> {} : FAILED", s);
ontologySpace.setUp();
// if (!onManager.containsScope(scopeId)) onManager.registerScope(scope);
onManager.setScopeActive(scopeId, true);
/*
* The first thing to do is to create a recipe in the rule store that can be used by the engine to
* refactor the enhancement graphs.
*/
String recipeId = engineConfiguration.getRecipeId();
Recipe recipe = null;
try {
recipe = ruleStore.createRecipe(new IRI(recipeId), null);
} catch (AlreadyExistingRecipeException e1) {
log.error("A recipe with ID {} already exists in the store.", recipeId);
}
if (recipe != null) {
log.debug("Initialised blank recipe with ID {}", recipeId);
/*
* The set of rule to put in the recipe can be provided by the user. A default set of rules is
* provided in /META-INF/default/seo_rules.sem. Use the property engine.refactor in the felix
* console to pass to the engine your set of rules.
*/
String recipeLocation = engineConfiguration.getRecipeLocation();
InputStream recipeStream = null;
String recipeString = null;
if (recipeLocation != null && !recipeLocation.isEmpty()) {
Dereferencer dereferencer = new DereferencerImpl();
try {
recipeStream = dereferencer.resolve(recipeLocation);
log.debug("Loaded recipe from external source {}", recipeLocation);
} catch (FileNotFoundException e) {
log.error("Recipe Stream is null.", e);
}
} else {
// TODO remove this part (or manage it better in the @Activate method).
String loc = "/META-INF/default/seo_rules.sem";
recipeStream = getClass().getResourceAsStream(loc);
log.debug("Loaded default recipe in {}.", loc);
}
if (recipeStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(recipeStream));
recipeString = "";
String line = null;
try {
while ((line = reader.readLine()) != null) recipeString += line;
} catch (IOException e) {
log.error("Failed to load Refactor Engine recipe from stream. Aborting read. ", e);
recipeString = null;
}
}
log.debug("Recipe content follows :\n{}", recipeString);
if (recipeString != null) {
ruleStore.addRulesToRecipe(recipe, recipeString, null);
log.debug("Added rules to recipe {}", recipeId);
}
}
}
Aggregations