}
@Override
public void setup(UpdateContainer uc) {
logger.info("Start OntologyMetadata.setup");
OntologyManager ontologyManager = workspace.getOntologyManager();
/** Check if any ontology needs to be preloaded **/
String preloadedOntDir = ServletContextParameterMap.getParameterValue(ServletContextParameterMap.ContextParameter.PRELOADED_ONTOLOGY_DIRECTORY);
File ontDir = new File(preloadedOntDir);
logger.info("Load ontologies from " + preloadedOntDir);
if (ontDir.exists()) {
File[] ontologies = ontDir.listFiles();
for (File ontology: ontologies) {
if(ontology.getName().startsWith(".") || ontology.isDirectory()) {
continue; //Ignore . files
}
if (ontology.getName().endsWith(".owl") ||
ontology.getName().endsWith(".rdf") ||
ontology.getName().endsWith(".n3") ||
ontology.getName().endsWith(".ttl") ||
ontology.getName().endsWith(".xml")) {
if(ontology.getName().matches("catalog\\-v[0-9]{3}\\.xml")) {
logger.info("Ignore: " + ontology.getAbsolutePath());
continue; //ignore mac catalog-v001.xml file
}
logger.info("Loading ontology file: " + ontology.getAbsolutePath());
try {
String encoding = EncodingDetector.detect(ontology);
ontologyManager.doImport(ontology, encoding);
} catch (Exception t) {
logger.error ("Error loading ontology: " + ontology.getAbsolutePath(), t);
uc.add(new TrivialErrorUpdate("Error loading ontology: " + ontology.getAbsolutePath()));
}
} else {
logger.error ("the file: " + ontology.getAbsolutePath() + " does not have proper format: xml/rdf/n3/ttl/owl");
uc.add(new TrivialErrorUpdate("Error loading ontology: " + ontology.getAbsolutePath() + ". The file does not have proper format: xml/rdf/n3/ttl/owl"));
}
}
// update the cache at the end when all files are added to the model
ontologyManager.updateCache();
} else {
logger.info("No directory for preloading ontologies exists.");
}
SemanticTypeUtil.setSemanticTypeTrainingStatus(true);
}