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 {
|
public class OntologyUpdateSettings {
|
||||||
|
|
||||||
private String dataDir;
|
private String dataDir;
|
||||||
private String sparqlConstructsDir;
|
private String sparqlConstructAdditionsDir;
|
||||||
|
private String sparqlConstructDeletionsDir;
|
||||||
private String askQueryFile;
|
private String askQueryFile;
|
||||||
private String successAssertionsFile;
|
private String successAssertionsFile;
|
||||||
private String successRDFFormat = "N3";
|
private String successRDFFormat = "N3";
|
||||||
|
@ -31,11 +32,17 @@ public class OntologyUpdateSettings {
|
||||||
public void setDataDir(String dataDir) {
|
public void setDataDir(String dataDir) {
|
||||||
this.dataDir = dataDir;
|
this.dataDir = dataDir;
|
||||||
}
|
}
|
||||||
public String getSparqlConstructsDir() {
|
public String getSparqlConstructAdditionsDir() {
|
||||||
return sparqlConstructsDir;
|
return sparqlConstructAdditionsDir;
|
||||||
}
|
}
|
||||||
public void setSparqlConstructsDir(String sparqlConstructsDir) {
|
public void setSparqlConstructAdditionsDir(String sparqlConstructAdditionsDir) {
|
||||||
this.sparqlConstructsDir = sparqlConstructsDir;
|
this.sparqlConstructAdditionsDir = sparqlConstructAdditionsDir;
|
||||||
|
}
|
||||||
|
public String getSparqlConstructDeletionsDir() {
|
||||||
|
return sparqlConstructDeletionsDir;
|
||||||
|
}
|
||||||
|
public void setSparqlConstructDeletionsDir(String sparqlConstructDeletionsDir) {
|
||||||
|
this.sparqlConstructDeletionsDir = sparqlConstructDeletionsDir;
|
||||||
}
|
}
|
||||||
public String getAskQueryFile() {
|
public String getAskQueryFile() {
|
||||||
return askQueryFile;
|
return askQueryFile;
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class OntologyUpdater {
|
||||||
|
|
||||||
private void performUpdate() throws IOException {
|
private void performUpdate() throws IOException {
|
||||||
|
|
||||||
performSparqlConstructs(settings.getSparqlConstructsDir(), settings.getOntModelSelector().getABoxModel());
|
performSparqlConstructAdditions(settings.getSparqlConstructAdditionsDir(), settings.getOntModelSelector().getABoxModel());
|
||||||
|
|
||||||
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
|
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
|
* Performs a set of arbitrary SPARQL CONSTRUCT queries on the
|
||||||
* data, for changes that cannot be expressed as simple property
|
* data, for changes that cannot be expressed as simple property
|
||||||
|
@ -102,16 +140,18 @@ public class OntologyUpdater {
|
||||||
* @param sparqlConstructDir
|
* @param sparqlConstructDir
|
||||||
* @param aboxModel
|
* @param aboxModel
|
||||||
*/
|
*/
|
||||||
private void performSparqlConstructs(String sparqlConstructDir,
|
private Model performSparqlConstructs(String sparqlConstructDir,
|
||||||
OntModel aboxModel) throws IOException {
|
OntModel aboxModel) throws IOException {
|
||||||
|
|
||||||
Model anonModel = ModelFactory.createDefaultModel();
|
Model anonModel = ModelFactory.createDefaultModel();
|
||||||
File sparqlConstructDirectory = new File(sparqlConstructDir);
|
File sparqlConstructDirectory = new File(sparqlConstructDir);
|
||||||
|
|
||||||
if (!sparqlConstructDirectory.isDirectory()) {
|
if (!sparqlConstructDirectory.isDirectory()) {
|
||||||
logger.logError(this.getClass().getName() +
|
logger.logError(this.getClass().getName() +
|
||||||
"performSparqlConstructs() expected to find a directory " +
|
"performSparqlConstructs() expected to find a directory " +
|
||||||
" at " + sparqlConstructDir + ". Unable to execute " +
|
" at " + sparqlConstructDir + ". Unable to execute " +
|
||||||
" SPARQL CONSTRUCTS.");
|
" SPARQL CONSTRUCTS.");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
File[] sparqlFiles = sparqlConstructDirectory.listFiles();
|
File[] sparqlFiles = sparqlConstructDirectory.listFiles();
|
||||||
for (int i = 0; i < sparqlFiles.length; i ++) {
|
for (int i = 0; i < sparqlFiles.length; i ++) {
|
||||||
|
@ -147,32 +187,7 @@ public class OntologyUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
return anonModel;
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 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 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 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 MISC_REPLACEMENTS_FILE = DATA_DIR + "miscReplacements.rdf";
|
||||||
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
private final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/";
|
||||||
private final String NEW_TBOX_MODEL_DIR = "/WEB-INF/submodels/";
|
private final String NEW_TBOX_MODEL_DIR = "/WEB-INF/submodels/";
|
||||||
|
@ -72,7 +73,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
||||||
OntologyUpdateSettings settings = new OntologyUpdateSettings();
|
OntologyUpdateSettings settings = new OntologyUpdateSettings();
|
||||||
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
|
settings.setAskQueryFile(ctx.getRealPath(ASK_QUERY_FILE));
|
||||||
settings.setDataDir(ctx.getRealPath(DATA_DIR));
|
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.setDiffFile(ctx.getRealPath(DIFF_FILE));
|
||||||
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
|
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE));
|
||||||
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
|
settings.setSuccessRDFFormat(SUCCESS_RDF_FORMAT);
|
||||||
|
|
Loading…
Add table
Reference in a new issue