infrastructure for NIHVIVO-205 ontology upgrade
This commit is contained in:
parent
6eccc7e2c9
commit
da8a7f3649
7 changed files with 202 additions and 2 deletions
|
@ -0,0 +1,31 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
|
||||||
|
public class ABoxUpdater {
|
||||||
|
|
||||||
|
private OntModel tboxModel;
|
||||||
|
private OntModel aboxModel;
|
||||||
|
private OntologyChangeLogger logger;
|
||||||
|
private OntologyChangeRecord record;
|
||||||
|
|
||||||
|
public ABoxUpdater(OntModel tboxModel, OntModel aboxModel,
|
||||||
|
OntologyChangeLogger logger, OntologyChangeRecord record) {
|
||||||
|
this.tboxModel = tboxModel;
|
||||||
|
this.aboxModel = aboxModel;
|
||||||
|
this.logger = logger;
|
||||||
|
this.record = record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processClassChanges(List<AtomicOntologyChange> changes) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processPropertyChanges(List<AtomicOntologyChange> changes) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface OntologyChangeLogger {
|
||||||
|
|
||||||
|
public void log(String logMessage) throws IOException;
|
||||||
|
|
||||||
|
public void logError(String errorMessage) throws IOException;
|
||||||
|
|
||||||
|
public void closeLogs() throws IOException;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
public interface OntologyChangeRecord {
|
||||||
|
|
||||||
|
public void recordAdditions(Model incrementalAdditions);
|
||||||
|
|
||||||
|
public void recordRetractions(Model incrementalRetractions);
|
||||||
|
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
import org.apache.commons.logging.Log;
|
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.query.Query;
|
import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
@ -54,7 +55,11 @@ public class OntologyUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performUpdate() throws IOException {
|
private void performUpdate() throws IOException {
|
||||||
List<AtomicOntologyChange> changes = getAtomicOntologyChanges();
|
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
|
||||||
|
|
||||||
|
AtomicOntologyChangeLists changes =
|
||||||
|
new AtomicOntologyChangeLists(rawChanges,
|
||||||
|
settings.getOntModelSelector().getTBoxModel());
|
||||||
|
|
||||||
//updateTBox(changes);
|
//updateTBox(changes);
|
||||||
//preprocessChanges(changes);
|
//preprocessChanges(changes);
|
||||||
|
@ -71,7 +76,9 @@ public class OntologyUpdater {
|
||||||
return (new OntologyChangeParser()).parseFile(settings.getDiffFile());
|
return (new OntologyChangeParser()).parseFile(settings.getDiffFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateABox(List<AtomicOntologyChange> changes) {
|
|
||||||
|
|
||||||
|
private void updateABox(AtomicOntologyChangeLists changes) {
|
||||||
// perform operations based on change objects
|
// perform operations based on change objects
|
||||||
// run additional SPARQL CONSTRUCTS
|
// run additional SPARQL CONSTRUCTS
|
||||||
}
|
}
|
||||||
|
@ -140,6 +147,34 @@ public class OntologyUpdater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that allows to access two different ontology change lists,
|
||||||
|
* one for class changes and the other for property changes. The
|
||||||
|
* constructor will split a list containing both types of changes.
|
||||||
|
* @author bjl23
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private class AtomicOntologyChangeLists {
|
||||||
|
|
||||||
|
private List<AtomicOntologyChange> atomicClassChanges;
|
||||||
|
|
||||||
|
private List<AtomicOntologyChange> atomicPropertyChanges;
|
||||||
|
|
||||||
|
public AtomicOntologyChangeLists(
|
||||||
|
List<AtomicOntologyChange> changeList, OntModel tboxModel) {
|
||||||
|
// TODO: split the main list of change objects into two lists
|
||||||
|
// depending on whether they refer to classes or properties
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AtomicOntologyChange> getAtomicClassChanges() {
|
||||||
|
return atomicClassChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AtomicOntologyChange> getAtomicPropertyChanges() {
|
||||||
|
return atomicPropertyChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
public class SimpleOntologyChangeLogger implements OntologyChangeLogger {
|
||||||
|
|
||||||
|
private Writer logWriter;
|
||||||
|
private Writer errorWriter;
|
||||||
|
|
||||||
|
public SimpleOntologyChangeLogger( String logPath,
|
||||||
|
String errorPath ) {
|
||||||
|
File logFile = new File(logPath);
|
||||||
|
File errorFile = new File(errorPath);
|
||||||
|
try {
|
||||||
|
logWriter = new BufferedWriter(new FileWriter(logFile));
|
||||||
|
errorWriter = new BufferedWriter(new FileWriter(errorFile));
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new RuntimeException ("Unable to open ontology change log " +
|
||||||
|
"files for writing", ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void log(String logMessage) throws IOException {
|
||||||
|
logWriter.write(logMessage + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logError(String errorMessage) throws IOException {
|
||||||
|
errorWriter.write(errorMessage + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeLogs() throws IOException {
|
||||||
|
logWriter.flush();
|
||||||
|
logWriter.close();
|
||||||
|
errorWriter.flush();
|
||||||
|
errorWriter.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
public class SimpleOntologyChangeRecord implements OntologyChangeRecord {
|
||||||
|
|
||||||
|
private final static Log log =
|
||||||
|
LogFactory.getLog(SimpleOntologyChangeRecord.class);
|
||||||
|
|
||||||
|
private final static String RDF_SYNTAX = "RDF/XML-ABBREV";
|
||||||
|
|
||||||
|
private Model additionsModel;
|
||||||
|
private Model retractionsModel;
|
||||||
|
private File additionsFile;
|
||||||
|
private File retractionsFile;
|
||||||
|
|
||||||
|
public SimpleOntologyChangeRecord(
|
||||||
|
Model additionsModel, Model retractionsModel,
|
||||||
|
String additionsFile, String retractionsFile) {
|
||||||
|
this.additionsModel = additionsModel;
|
||||||
|
this.retractionsModel = retractionsModel;
|
||||||
|
this.additionsFile = new File(additionsFile);
|
||||||
|
if (!this.additionsFile.exists()) {
|
||||||
|
throw new RuntimeException(this.getClass().getName() +
|
||||||
|
" unable to create required file at " + additionsFile);
|
||||||
|
}
|
||||||
|
this.retractionsFile = new File(retractionsFile);
|
||||||
|
if (!this.retractionsFile.exists()) {
|
||||||
|
throw new RuntimeException(this.getClass().getName() +
|
||||||
|
" unable to create required file at " + retractionsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordAdditions(Model incrementalAdditions) {
|
||||||
|
additionsModel.add(incrementalAdditions);
|
||||||
|
write(additionsModel, additionsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordRetractions(Model incrementalRetractions) {
|
||||||
|
retractionsModel.add(incrementalRetractions);
|
||||||
|
write(retractionsModel, retractionsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write(Model model, File file) {
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
model.write(fos, RDF_SYNTAX);
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
log.error(this.getClass().getName() +
|
||||||
|
" unable to write to RDF file", fnfe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||||
|
|
||||||
|
public class TBoxUpdater {
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue