work on NIHVIVO-205 ontology upgrade
This commit is contained in:
parent
e8e3401539
commit
ea5f4327f7
2 changed files with 47 additions and 10 deletions
|
@ -50,11 +50,6 @@ public class OntologyUpdater {
|
||||||
private OntologyChangeLogger logger;
|
private OntologyChangeLogger logger;
|
||||||
private OntologyChangeRecord record;
|
private OntologyChangeRecord record;
|
||||||
|
|
||||||
private OntModel OLD_TBOX_MODEL = null; // TODO change this
|
|
||||||
|
|
||||||
private OntModel oldTBoxAnnotationsModel;
|
|
||||||
private OntModel newTBoxAnnotationsModel;
|
|
||||||
|
|
||||||
public OntologyUpdater(OntologyUpdateSettings settings) {
|
public OntologyUpdater(OntologyUpdateSettings settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.logger = new SimpleOntologyChangeLogger(settings.getLogFile(),
|
this.logger = new SimpleOntologyChangeLogger(settings.getLogFile(),
|
||||||
|
@ -83,7 +78,7 @@ public class OntologyUpdater {
|
||||||
AtomicOntologyChangeLists changes =
|
AtomicOntologyChangeLists changes =
|
||||||
new AtomicOntologyChangeLists(rawChanges,
|
new AtomicOntologyChangeLists(rawChanges,
|
||||||
settings.getOntModelSelector().getTBoxModel(),
|
settings.getOntModelSelector().getTBoxModel(),
|
||||||
OLD_TBOX_MODEL);
|
settings.getOldTBoxModel());
|
||||||
|
|
||||||
//updateTBox(changes);
|
//updateTBox(changes);
|
||||||
//preprocessChanges(changes);
|
//preprocessChanges(changes);
|
||||||
|
@ -182,7 +177,8 @@ public class OntologyUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTBoxAnnotations() throws IOException {
|
private void updateTBoxAnnotations() throws IOException {
|
||||||
(new TBoxUpdater(oldTBoxAnnotationsModel, newTBoxAnnotationsModel,
|
(new TBoxUpdater(settings.getOldTBoxAnnotationsModel(),
|
||||||
|
settings.getNewTBoxAnnotationsModel(),
|
||||||
settings.getOntModelSelector().getTBoxModel(), logger, record))
|
settings.getOntModelSelector().getTBoxModel(), logger, record))
|
||||||
.updateVitroPropertyDefaultValues();
|
.updateVitroPropertyDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
@ -55,10 +57,15 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
"removedData.rdf";
|
"removedData.rdf";
|
||||||
private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
private final String SPARQL_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
||||||
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
||||||
|
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
||||||
|
private final String OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/";
|
||||||
|
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
|
||||||
/*
|
// TODO remove when ready
|
||||||
|
if (true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ServletContext ctx = sce.getServletContext();
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
|
@ -80,6 +87,11 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory");
|
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory");
|
||||||
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
settings.setDefaultNamespace(wadf.getDefaultNamespace());
|
||||||
|
|
||||||
|
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
|
||||||
|
settings.setOldTBoxModel(oldTBoxModel);
|
||||||
|
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR));
|
||||||
|
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
|
doMiscAppMetadataReplacements(ctx.getRealPath(MISC_REPLACEMENTS_FILE), oms);
|
||||||
(new OntologyUpdater(settings)).update();
|
(new OntologyUpdater(settings)).update();
|
||||||
|
@ -93,7 +105,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
throw new RuntimeException(errMsg, ioe);
|
throw new RuntimeException(errMsg, ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +146,35 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OntModel loadModelFromDirectory(String directoryPath) {
|
||||||
|
OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
File directory = new File(directoryPath);
|
||||||
|
if (!directory.isDirectory()) {
|
||||||
|
throw new RuntimeException(directoryPath + " must be a directory " +
|
||||||
|
"containing RDF files.");
|
||||||
|
}
|
||||||
|
File[] rdfFiles = directory.listFiles();
|
||||||
|
for (int i = 0; i < rdfFiles.length; i++) {
|
||||||
|
try {
|
||||||
|
File f = rdfFiles[i];
|
||||||
|
FileInputStream fis = new FileInputStream(f);
|
||||||
|
try {
|
||||||
|
if (f.getName().endsWith(".n3")) {
|
||||||
|
om.read(fis, null, "N3");
|
||||||
|
} else {
|
||||||
|
om.read(fis, null, "RDF/XML");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unable to load RDF from " + f.getName(), e);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
log.error(rdfFiles[i].getName() + " not found. Unable to load" +
|
||||||
|
" RDF from this location.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return om;
|
||||||
|
}
|
||||||
|
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue