incremental development of knowledge base migration for release 1.2

This commit is contained in:
sjm222 2010-12-27 14:37:56 +00:00
parent 85db1c3ba0
commit 5618118d85
4 changed files with 67 additions and 10 deletions

View file

@ -37,13 +37,17 @@ public class DateTimeMigration {
private static final String dateTimeURI = "http://vivoweb.org/ontology/core#dateTime";
private static final String dateTimePrecisionURI = "http://vivoweb.org/ontology/core#dateTimePrecision";
private static final String hasTimeIntervalURI = "http://vivoweb.org/ontology/core#hasTimeInterval";
private static final String dateTimeIntervalURI = "http://vivoweb.org/ontology/core#dateTimeInterval";
private static final String yPrecisionURI = "http://vivoweb.org/ontology/core#yearPrecision";
private static final String ymPrecisionURI = "http://vivoweb.org/ontology/core#yearMonthPrecision";
private static final String ymdPrecisionURI = "http://vivoweb.org/ontology/core#yearMonthDayPrecision";
private static final String ymdtPrecisionURI = "http://vivoweb.org/ontology/core#yearMonthDayTimePrecision";
private DatatypeProperty dateTimeProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createDatatypeProperty(dateTimeURI);
private ObjectProperty hasTimeIntervalProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createObjectProperty(hasTimeIntervalURI);
private ObjectProperty dateTimeIntervalProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createObjectProperty(dateTimeIntervalURI);
private ObjectProperty dateTimePrecisionProp = (ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM)).createObjectProperty(dateTimePrecisionURI);
@ -65,11 +69,57 @@ public class DateTimeMigration {
/**
*
* Update a knowledge base to align with changes in the Date/Time class
* Update the abox to align with changes in the Date/Time class
* and property definitions in the transition from version 1.1 to 1.2.
*
*/
public void updateABox() throws IOException {
updateAcademicIntervals();
updateLiterals();
}
/**
*
*
*/
public void updateAcademicIntervals() throws IOException {
aboxModel.enterCriticalSection(Lock.WRITE);
try {
Model additions = ModelFactory.createDefaultModel();
Model retractions = ModelFactory.createDefaultModel();
StmtIterator iter = aboxModel.listStatements((Resource) null, hasTimeIntervalProp, (RDFNode) null);
while (iter.hasNext()) {
Statement stmt = iter.next();
Statement stmt2 = aboxModel.getProperty(stmt.getObject().asResource(), dateTimeIntervalProp);
if (stmt2 != null) {
retractions.add(stmt2);
additions.add(stmt.getSubject(), dateTimeIntervalProp, stmt2.getObject());
}
}
aboxModel.remove(retractions);
record.recordRetractions(retractions);
aboxModel.add(additions);
record.recordAdditions(additions);
} finally {
aboxModel.leaveCriticalSection();
}
}
/**
*
*
*/
public void updateLiterals() throws IOException {
// note: not handling timezones - they are not expected to be in the 1.1.1 data
DateFormat yearFormat = new SimpleDateFormat("yyyy");

View file

@ -10,6 +10,7 @@ public class OntologyUpdateSettings {
private String dataDir;
private String sparqlConstructAdditionsDir;
private String sparqlConstructAdditionsPass2Dir;
private String sparqlConstructDeletionsDir;
private String askQueryFile;
private String successAssertionsFile;
@ -35,6 +36,12 @@ public class OntologyUpdateSettings {
public String getSparqlConstructAdditionsDir() {
return sparqlConstructAdditionsDir;
}
public void setSparqlConstructAdditionsPass2Dir(String sparqlConstructAdditionsDir) {
this.sparqlConstructAdditionsPass2Dir = sparqlConstructAdditionsDir;
}
public String getSparqlConstructAdditionsPass2Dir() {
return sparqlConstructAdditionsPass2Dir;
}
public void setSparqlConstructAdditionsDir(String sparqlConstructAdditionsDir) {
this.sparqlConstructAdditionsDir = sparqlConstructAdditionsDir;
}

View file

@ -81,23 +81,21 @@ public class OntologyUpdater {
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
performSparqlConstructRetractions(settings.getSparqlConstructDeletionsDir(), settings.getOntModelSelector().getABoxModel());
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsPass2Dir(), settings.getOntModelSelector().getABoxModel());
DateTimeMigration dtMigration = new DateTimeMigration(settings.getOntModelSelector().getABoxModel(), logger, record);
dtMigration.updateABox();
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,
settings.getNewTBoxModel(),
settings.getOldTBoxModel());
//process the TBox before the ABox
//TODO: uncomment updateTBoxAnnotations();
updateABox(changes);
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,settings.getNewTBoxModel(),settings.getOldTBoxModel());
//process the TBox before the ABox
//TODO: uncomment updateTBoxAnnotations(); 12/27/2010 - commented out just for testing abox updater
updateABox(changes);
}
private void performSparqlConstructAdditions(String sparqlConstructDir, OntModel aboxModel) throws IOException {
Model anonModel = performSparqlConstructs(sparqlConstructDir, aboxModel);

View file

@ -53,6 +53,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
private final String REMOVED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "removedData.n3";
private final String ADDED_DATA_FILE = DATA_DIR + CHANGED_DATA_DIR + "addedData.n3";
private final String SPARQL_CONSTRUCT_ADDITIONS_DIR = DATA_DIR + "sparqlConstructs/additions/";
private final String SPARQL_CONSTRUCT_ADDITIONS_PASS2_DIR = DATA_DIR + "sparqlConstructs/additions-pass2/";
private final String SPARQL_CONSTRUCT_DELETIONS_DIR = DATA_DIR + "sparqlConstructs/deletions/";
private final String MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
@ -74,6 +75,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
settings.setDataDir(ctx.getRealPath(DATA_DIR));
settings.setSparqlConstructAdditionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_DIR));
settings.setSparqlConstructAdditionsPass2Dir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_PASS2_DIR));
settings.setSparqlConstructDeletionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_DELETIONS_DIR));
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));