infrastructure for handling deletions with sparql constructs
This commit is contained in:
parent
0b128939b6
commit
0bab5a3f6f
3 changed files with 60 additions and 36 deletions
|
@ -9,7 +9,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
|||
public class OntologyUpdateSettings {
|
||||
|
||||
private String dataDir;
|
||||
private String sparqlConstructsDir;
|
||||
private String sparqlConstructAdditionsDir;
|
||||
private String sparqlConstructDeletionsDir;
|
||||
private String askQueryFile;
|
||||
private String successAssertionsFile;
|
||||
private String successRDFFormat = "N3";
|
||||
|
@ -31,11 +32,17 @@ public class OntologyUpdateSettings {
|
|||
public void setDataDir(String dataDir) {
|
||||
this.dataDir = dataDir;
|
||||
}
|
||||
public String getSparqlConstructsDir() {
|
||||
return sparqlConstructsDir;
|
||||
public String getSparqlConstructAdditionsDir() {
|
||||
return sparqlConstructAdditionsDir;
|
||||
}
|
||||
public void setSparqlConstructsDir(String sparqlConstructsDir) {
|
||||
this.sparqlConstructsDir = sparqlConstructsDir;
|
||||
public void setSparqlConstructAdditionsDir(String sparqlConstructAdditionsDir) {
|
||||
this.sparqlConstructAdditionsDir = sparqlConstructAdditionsDir;
|
||||
}
|
||||
public String getSparqlConstructDeletionsDir() {
|
||||
return sparqlConstructDeletionsDir;
|
||||
}
|
||||
public void setSparqlConstructDeletionsDir(String sparqlConstructDeletionsDir) {
|
||||
this.sparqlConstructDeletionsDir = sparqlConstructDeletionsDir;
|
||||
}
|
||||
public String getAskQueryFile() {
|
||||
return askQueryFile;
|
||||
|
|
|
@ -80,7 +80,7 @@ public class OntologyUpdater {
|
|||
|
||||
private void performUpdate() throws IOException {
|
||||
|
||||
performSparqlConstructs(settings.getSparqlConstructsDir(), settings.getOntModelSelector().getABoxModel());
|
||||
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
|
||||
|
||||
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
|
||||
|
||||
|
@ -94,6 +94,44 @@ public class OntologyUpdater {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private void performSparqlConstructAdditions(String sparqlConstructDir, OntModel aboxModel) throws IOException {
|
||||
|
||||
Model anonModel = performSparqlConstructs(sparqlConstructDir, aboxModel);
|
||||
|
||||
if (anonModel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
JenaIngestUtils jiu = new JenaIngestUtils();
|
||||
Model additions = jiu.renameBNodes(anonModel, settings.getDefaultNamespace() + "n",
|
||||
aboxModel);
|
||||
Model actualAdditions = ModelFactory.createDefaultModel();
|
||||
StmtIterator stmtIt = additions.listStatements();
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
if (!aboxModel.contains(stmt)) {
|
||||
actualAdditions.add(stmt);
|
||||
}
|
||||
}
|
||||
aboxModel.add(actualAdditions);
|
||||
if (actualAdditions.size() > 0) {
|
||||
logger.log("Constructed " + actualAdditions.size() + " new " +
|
||||
"statement"
|
||||
+ ((actualAdditions.size() > 1) ? "s" : "") +
|
||||
" using SPARQL CONSTRUCT queries.");
|
||||
}
|
||||
record.recordAdditions(actualAdditions);
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs a set of arbitrary SPARQL CONSTRUCT queries on the
|
||||
* data, for changes that cannot be expressed as simple property
|
||||
|
@ -102,16 +140,18 @@ public class OntologyUpdater {
|
|||
* @param sparqlConstructDir
|
||||
* @param aboxModel
|
||||
*/
|
||||
private void performSparqlConstructs(String sparqlConstructDir,
|
||||
private Model performSparqlConstructs(String sparqlConstructDir,
|
||||
OntModel aboxModel) throws IOException {
|
||||
|
||||
Model anonModel = ModelFactory.createDefaultModel();
|
||||
File sparqlConstructDirectory = new File(sparqlConstructDir);
|
||||
|
||||
if (!sparqlConstructDirectory.isDirectory()) {
|
||||
logger.logError(this.getClass().getName() +
|
||||
"performSparqlConstructs() expected to find a directory " +
|
||||
" at " + sparqlConstructDir + ". Unable to execute " +
|
||||
" SPARQL CONSTRUCTS.");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
File[] sparqlFiles = sparqlConstructDirectory.listFiles();
|
||||
for (int i = 0; i < sparqlFiles.length; i ++) {
|
||||
|
@ -147,32 +187,7 @@ public class OntologyUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
JenaIngestUtils jiu = new JenaIngestUtils();
|
||||
Model additions = jiu.renameBNodes(anonModel, settings.getDefaultNamespace() + "n",
|
||||
aboxModel);
|
||||
Model actualAdditions = ModelFactory.createDefaultModel();
|
||||
StmtIterator stmtIt = additions.listStatements();
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
if (!aboxModel.contains(stmt)) {
|
||||
actualAdditions.add(stmt);
|
||||
}
|
||||
}
|
||||
aboxModel.add(actualAdditions);
|
||||
if (actualAdditions.size() > 0) {
|
||||
logger.log("Constructed " + actualAdditions.size() + " new " +
|
||||
"statement"
|
||||
+ ((actualAdditions.size() > 1) ? "s" : "") +
|
||||
" using SPARQL CONSTRUCT queries.");
|
||||
}
|
||||
record.recordAdditions(actualAdditions);
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
|
||||
return anonModel;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
private final String ERROR_LOG_FILE = DATA_DIR + LOG_DIR + "knowledgeBaseUpdate.error.log";
|
||||
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_CONSTRUCTS_DIR = DATA_DIR + "sparqlConstructs/";
|
||||
private final String SPARQL_CONSTRUCT_ADDITIONS_DIR = DATA_DIR + "sparqlConstructs/additions/";
|
||||
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/";
|
||||
private final String NEW_TBOX_MODEL_DIR = "/WEB-INF/submodels/";
|
||||
|
@ -72,7 +73,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
OntologyUpdateSettings settings = new OntologyUpdateSettings();
|
||||
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
|
||||
settings.setDataDir(ctx.getRealPath(DATA_DIR));
|
||||
settings.setSparqlConstructsDir(ctx.getRealPath(SPARQL_CONSTRUCTS_DIR));
|
||||
settings.setSparqlConstructAdditionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_ADDITIONS_DIR));
|
||||
settings.setSparqlConstructDeletionsDir(ctx.getRealPath(SPARQL_CONSTRUCT_DELETIONS_DIR));
|
||||
settings.setDiffFile(ctx.getRealPath(DIFF_FILE));
|
||||
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
|
||||
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
|
||||
|
|
Loading…
Add table
Reference in a new issue