development for NIHVIVO-2426, knowledge base migration.

This commit is contained in:
stellamit 2011-06-28 20:37:55 +00:00
parent 9479a220f5
commit cd976b67bc
6 changed files with 28 additions and 59 deletions

View file

@ -57,27 +57,6 @@ xmlns:vitro="&vitro;"
<owl:AnnotationProperty rdf:about="&vitro;isExternalId"/>
<owl:AnnotationProperty rdf:about="&vitro;originalId"/>
<!-- Keyword related -->
<owl:Class rdf:about="&vitro;Keyword"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordStem"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordType"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordSource"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordComments"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordOrigin"/>
<owl:Class rdf:about="&vitro;KeywordRelation"/>
<owl:ObjectProperty rdf:about="&vitro;involvesIndividual"/>
<owl:ObjectProperty rdf:about="&vitro;involvesKeyword"/>
<owl:DatatypeProperty rdf:about="&vitro;keywordMode"/>
<!-- Link related -->
<owl:ObjectProperty rdf:about="&vitro;primaryLink"/>
<owl:ObjectProperty rdf:about="&vitro;additionalLink"/>
<owl:Class rdf:about="&vitro;Link"/>
<owl:DatatypeProperty rdf:about="&vitro;linkAnchor"/>
<owl:DatatypeProperty rdf:about="&vitro;linkURL"/>
<!-- other Individual-related -->
<owl:DatatypeProperty rdf:about="&vitro;curatorNote">

View file

@ -21,6 +21,7 @@ import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
@ -401,6 +402,7 @@ public class SimpleReasoner extends StatementListener {
* that B is of that type.
*
*/
public void removedABoxTypeAssertion(Statement stmt, Model inferenceModel) {
//log.debug("stmt = " + stmt.toString());

View file

@ -26,7 +26,8 @@ import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.util.StoreUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
// This ContextListener must run after the JenaDataSourceSetup ContextListener
@ -47,10 +48,10 @@ public class FileGraphSetup implements ServletContextListener {
boolean aboxChanged = false; // indicates whether any ABox file graph model has changed
boolean tboxChanged = false; // indicates whether any TBox file graph model has changed
OntModelSelectorImpl baseOms = null;
OntModelSelector baseOms = null;
try {
baseOms = (OntModelSelectorImpl) sce.getServletContext().getAttribute("baseOntModelSelector");
baseOms = ModelContext.getBaseOntModelSelector(sce.getServletContext());
Store kbStore = (Store) sce.getServletContext().getAttribute("kbStore");
// ABox files
@ -83,7 +84,6 @@ public class FileGraphSetup implements ServletContextListener {
}
if (aboxChanged || tboxChanged) {
if ( !JenaDataSourceSetup.updateRequired(sce.getServletContext(), baseOms.getTBoxModel())) {
log.info("a full recompute of the Abox will be performed because" +
" the filegraph abox(s) and/or tbox(s) have changed, or are being read for the first time." );

View file

@ -73,8 +73,6 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
setUpJenaDataSource(ctx);
log.info((System.currentTimeMillis() - startTime) / 1000 +
" seconds to set up SDB store");
} catch (MigrationRequiredError mre) {
throw new MigrationRequiredError(mre.getMessage());
} catch (SQLException sqle) {
// SQL exceptions are fatal and should halt startup
AbortStartup.abortStartup(ctx);
@ -94,18 +92,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
}
private void setUpJenaDataSource(ServletContext ctx) throws SQLException {
/*
if ( updateRequired(ctx, memModel)) {
log.error(getMigrationErrString());
System.out.println(getMigrationErrString());
// The rest of the application should not
// start if this condition is encountered
AbortStartup.abortStartup(ctx);
throw new MigrationRequiredError(getMigrationErrString());
}
*/
OntModelSelectorImpl baseOms = new OntModelSelectorImpl();
OntModelSelectorImpl inferenceOms = new OntModelSelectorImpl();
OntModelSelectorImpl unionOms = new OntModelSelectorImpl();
@ -646,12 +633,5 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
return required;
}
private class MigrationRequiredError extends Error {
public MigrationRequiredError(String string) {
super(string);
}
}
}

View file

@ -15,6 +15,7 @@ import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
@ -41,9 +42,10 @@ public class SimpleReasonerSetup implements ServletContextListener {
try {
// set up Pellet reasoning for the TBox
OntModelSelector assertionsOms = (OntModelSelector) sce.getServletContext().getAttribute("baseOntModelSelector");
OntModelSelector inferencesOms = (OntModelSelector) sce.getServletContext().getAttribute("inferenceOntModelSelector");
OntModelSelector unionOms = (OntModelSelector) sce.getServletContext().getAttribute("unionOntModelSelector");
OntModelSelector assertionsOms = ModelContext.getBaseOntModelSelector(sce.getServletContext());
OntModelSelector inferencesOms = ModelContext.getInferenceOntModelSelector(sce.getServletContext());
OntModelSelector unionOms = ModelContext.getUnionOntModelSelector(sce.getServletContext());
WebappDaoFactoryJena wadf = (WebappDaoFactoryJena) sce.getServletContext().getAttribute("webappDaoFactory");

View file

@ -6,6 +6,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@ -26,9 +28,8 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
import edu.cornell.mannlib.vitro.webapp.ontology.update.UpdateSettings;
import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup;
@ -52,8 +53,6 @@ public class UpdateKnowledgeBase implements ServletContextListener {
private static final String SUCCESS_ASSERTIONS_FILE = DATA_DIR + "success.n3";
private static final String SUCCESS_RDF_FORMAT = "N3";
private static final String DIFF_FILE = DATA_DIR + "diff.tab.txt";
private static final String LOG_FILE = DATA_DIR + LOG_DIR + "knowledgeBaseUpdate.log";
private static final String ERROR_LOG_FILE = DATA_DIR + LOG_DIR + "knowledgeBaseUpdate.error.log";
private static final String REMOVED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "removedData.n3";
private static final String ADDED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "addedData.n3";
private static final String SPARQL_CONSTRUCT_ADDITIONS_DIR = DATA_DIR + "sparqlConstructs/additions/";
@ -73,9 +72,11 @@ public class UpdateKnowledgeBase implements ServletContextListener {
try {
ServletContext ctx = sce.getServletContext();
OntModelSelector assertionsOms = ModelContext.getBaseOntModelSelector(ctx);
OntModelSelector oms = new SimpleOntModelSelector((OntModel) sce.getServletContext().getAttribute(JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME));
String logFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate", "log");
String errorLogFileName = DATA_DIR + LOG_DIR + timestampedFileName("knowledgeBaseUpdate.error", "log");
UpdateSettings settings = new UpdateSettings();
settings.setAskQueryFile(getAskQueryPath(ctx));
settings.setAskEverQueryFile(getAskEverQueryPath(ctx));
@ -86,14 +87,14 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
settings.setLogFile(ctx.getRealPath(LOG_FILE));
settings.setErrorLogFile(ctx.getRealPath(ERROR_LOG_FILE));
settings.setLogFile(ctx.getRealPath(logFileName));
settings.setErrorLogFile(ctx.getRealPath(errorLogFileName));
settings.setAddedDataFile(ctx.getRealPath(ADDED_DATA_FILE));
settings.setRemovedDataFile(ctx.getRealPath(REMOVED_DATA_FILE));
WebappDaoFactory wadf = (WebappDaoFactory) ctx.getAttribute("webappDaoFactory");
settings.setDefaultNamespace(wadf.getDefaultNamespace());
settings.setOntModelSelector(oms);
settings.setOntModelSelector(assertionsOms);
try {
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR));
settings.setOldTBoxModel(oldTBoxModel);
@ -181,7 +182,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
}
}
} catch (FileNotFoundException fnfe) {
log.info("No miscellaneous application metadata replacements were performed.");
log.warn("Couldn't find miscellaneous application metadata replacement file: " + filename);
} catch (Exception e) {
log.error("Error performing miscellaneous application metadata " +
@ -255,6 +256,11 @@ public class UpdateKnowledgeBase implements ServletContextListener {
}
private static String timestampedFileName(String prefix, String suffix) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-sss");
return prefix + "." + sdf.format(new Date()) + suffix;
}
private class ModelDirectoryNotFoundException extends RuntimeException {
public ModelDirectoryNotFoundException(String msg) {
super(msg);