KReS/WeatherServiceRefactoring

From STLab

Jump to: navigation, search

First we need to obtain the resource managers

  • this example assumes OSGi with declarative services, and the usage of Felix SCR annotations. Shall we make a POJO example with constructors?
/*
 * FIXME perhaps this won't be needed by the tutorial, 
 * unless we add a non-SCR snippet.
 */
@Reference
KReSONManager onMgr;
 
/*
 * This object will select appropriate reengineers.
 */
@Reference
SemionManager reengineerMgr;
 
/*
 * Ontology refactoring uses a dedicated object. 
 * Note that the rule ontology is pre-configured in the 
 * referred object itself.
 */
@Reference
SemionRefactorer refactorer;
 
Logger logger = LoggerFactory.createLogger(getClass());

To make a content item processable by reengineers, a DataSource object must be created from it.

// Create a DataSource object from the given content type (XML) and input stream.
InputStream content;
// TODO add a snippet on how the content item is retrieved.
 
DataSource ds = null;
try {
	ds = DataSourceFactory.createDataSource(ReengineerType.XML, content);
} catch (NoSuchDataSourceExpection e1) {
	logger.error(
			"Could not create a data source for the supplied content item and type.",
			e1);
	return null;
} catch (InvalidDataSourceForTypeSelectedException e1) {
	logger.error(
			"No reengineers registered for this content type.",
			e1);
	return null;
}

Prepare the IRIs that will identify the reengineered ontology itself and the entities therein.

long now = new Date().getTime();
 
// Newly created entities will have a hash (#) IRI starting with this namespace.
String namespace = "http://www.iks-project.eu/content/weather";
/* 
 * The reengineered ontology can be identified by a different IRI than the default namespace.
 * Here this feature is exploited to have different weather report ontologies identified by 
 * their timestamps, but with a common vocabulary using the same namespace all along.
 */
IRI baseIRI = IRI.create(namespace + "/" + new Date().getTime());

Perform the reengineering. Note that no specific reengineer must be invoked, as it is selected by the reengineerManager.

// Now do the reengineering.
OWLOntology oReeng;
try {
	oReeng = reengineerMgr.performReengineering(namespace, baseIRI, ds);
} catch (ReengineerExeption e1) {
	logger.error(
			"Reengineering failed.",
			e1);
	return null;
}

Pipe the reengineered ontology to the refactorer

  • TODO ad a recipe example
IRI weatherRecipeIri = IRI.create("http://www.iks-project.eu/meta/refactoring_rules.owl#WeatherRecipe");
 
OWLOntology o = null;
try {
	/*
	 * Note that we do not provide a new ontology identifier in this case,
	 * as we will get rid of the reengineered ontology and keep the
	 * refactored one instead.
	 */
	o = refactorer.ontologyRefactoring(o, weatherRecipeIri);
} catch (SemionRefactoringException e1) {
	logger.error(
			"Refactoring failed for ontology " + o.getOntologyID(),
			e1);
	return null;
} catch (NoSuchRecipeException e2) {
	logger.error(
			"The are no rules to refactor this ontology by.",
			e2);
	return null;
}
 
/* 
 * Ontology o now contains all the ABox axioms reaulting from 
 * applying rules in WeatherRecipe to the reengineered ontology.
 */
 return o;
Personal tools