Removing 1.4 (and before) specific migration logic (External Concepts, display model, recomputing mostSpecificType on startup)
This commit is contained in:
parent
24f5562626
commit
fe044c759a
6 changed files with 4 additions and 345 deletions
|
@ -564,179 +564,6 @@ public class ABoxUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
protected void migrateExternalConcepts() throws IOException {
|
||||
|
||||
Property hasResearchArea = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#hasResearchArea");
|
||||
Property researchAreaOf = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#researchAreaOf");
|
||||
Property hasSubjectArea = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#hasSubjectArea");
|
||||
Property subjectAreaFor = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#subjectAreaFor");
|
||||
|
||||
Property sourceVocabularyReference = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#sourceVocabularyReference");
|
||||
Property webpage = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#webpage");
|
||||
Property linkURI = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#linkURI");
|
||||
Property linkAnchorText = ResourceFactory.createProperty("http://vivoweb.org/ontology/core#linkAnchorText");
|
||||
|
||||
HashSet<Resource> resourcesToDelete = new HashSet<Resource>();
|
||||
HashSet<Resource> resourcesToDetype = new HashSet<Resource>();
|
||||
|
||||
Model additions = ModelFactory.createDefaultModel();
|
||||
Model retractions = ModelFactory.createDefaultModel();
|
||||
|
||||
int subjectRefCount = 0;
|
||||
int researchRefCount = 0;
|
||||
int webpageCount = 0;
|
||||
int typeCount = 0;
|
||||
int count = 0;
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
StmtIterator iter = aboxModel.listStatements((Resource) null, sourceVocabularyReference, (RDFNode) null);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
Resource subjectAreaResource = stmt.getSubject();
|
||||
|
||||
if (!stmt.getObject().isResource()) continue;
|
||||
|
||||
Resource vocabularySourceReferenceResource = stmt.getObject().asResource();
|
||||
Resource externalConceptResource = null;
|
||||
Resource webpageResource = null;
|
||||
|
||||
if (subjectAreaResource.hasProperty(webpage)) {
|
||||
Statement webpageStmt = subjectAreaResource.getProperty(webpage);
|
||||
RDFNode webpageObject = webpageStmt.getObject();
|
||||
if (!webpageObject.isResource()) continue;
|
||||
webpageResource = webpageObject.asResource();
|
||||
if (!webpageResource.hasProperty(linkURI)) continue;
|
||||
Statement linkURIStmt = webpageResource.asResource().getProperty(linkURI);
|
||||
RDFNode linkURIObject = linkURIStmt.getObject();
|
||||
if (!linkURIObject.isLiteral()) continue;
|
||||
externalConceptResource = ResourceFactory.createResource(linkURIObject.asLiteral().getString());
|
||||
if (externalConceptResource == null) continue;
|
||||
resourcesToDelete.add(webpageResource.asResource());
|
||||
resourcesToDetype.add(vocabularySourceReferenceResource);
|
||||
additions.add(externalConceptResource,RDFS.isDefinedBy,vocabularySourceReferenceResource);
|
||||
additions.add(externalConceptResource, RDF.type, OWL_THING);
|
||||
Statement conceptLabelStmt = subjectAreaResource.getProperty(RDFS.label);
|
||||
if (conceptLabelStmt == null) {
|
||||
conceptLabelStmt = webpageResource.asResource().getProperty(RDFS.label);
|
||||
}
|
||||
if (conceptLabelStmt != null) {
|
||||
additions.add(externalConceptResource, RDFS.label, conceptLabelStmt.getObject().asLiteral());
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
subjectRefCount += migrateConceptReferences(externalConceptResource, subjectAreaResource, hasSubjectArea, subjectAreaFor, additions);
|
||||
researchRefCount += migrateConceptReferences(externalConceptResource, subjectAreaResource, hasResearchArea, researchAreaOf, additions);
|
||||
migrateRelatedConcepts(externalConceptResource, subjectAreaResource, additions);
|
||||
|
||||
resourcesToDelete.add(subjectAreaResource);
|
||||
if (webpageResource != null) {
|
||||
resourcesToDelete.add(webpageResource);
|
||||
webpageCount++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
Iterator<Resource> vsrIter = resourcesToDetype.iterator();
|
||||
while (vsrIter.hasNext()) {
|
||||
Resource resource = vsrIter.next();
|
||||
StmtIterator typeiter = resource.listProperties(RDF.type);
|
||||
while (typeiter.hasNext()) {
|
||||
Statement typeStatement = typeiter.next();
|
||||
if (!typeStatement.getObject().equals(OWL_THING)) {
|
||||
retractions.add(typeStatement);
|
||||
}
|
||||
}
|
||||
additions.add(resource, RDF.type, OWL_THING);
|
||||
typeCount++;
|
||||
}
|
||||
|
||||
aboxModel.add(additions);
|
||||
aboxModel.remove(retractions);
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
record.recordAdditions(additions);
|
||||
record.recordRetractions(retractions);
|
||||
|
||||
Iterator<Resource> iter = resourcesToDelete.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Resource ind = iter.next();
|
||||
deleteIndividual(ind);
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
; logger.log("migrated " + count + " external concept" + ((count == 1) ? "" : "s") + ", which involved deleting " +
|
||||
count + " vivo:SubjectArea individual" + ((count == 1) ? "" : "s") + " and " +
|
||||
webpageCount + " vivo:URLLink individual" + ((webpageCount == 1) ? "" : "s") +
|
||||
", and changing the type for " + typeCount + " vivo:VocabularySourceReference individual" + ((typeCount == 1) ? "" : "s") + " to owl:Thing");
|
||||
}
|
||||
|
||||
if (subjectRefCount > 0) {
|
||||
logger.log("migrated " + subjectRefCount + " " + hasSubjectArea.getLocalName() + " external concept reference" + ((subjectRefCount == 1) ? "" : "s"));
|
||||
}
|
||||
|
||||
if (researchRefCount > 0) {
|
||||
logger.log("migrated " + researchRefCount + " " + hasResearchArea.getLocalName() + " external concept reference" + ((researchRefCount == 1) ? "" : "s"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected int migrateConceptReferences(Resource externalConceptResource, Resource subjectArea, Property hasConcept, Property conceptOf, Model additions) throws IOException {
|
||||
|
||||
int count = 0;
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
StmtIterator iter = aboxModel.listStatements((Resource) null, hasConcept, subjectArea);
|
||||
while (iter.hasNext()) {
|
||||
|
||||
Statement stmt = iter.next();
|
||||
Resource agent = stmt.getSubject();
|
||||
if (!additions.contains(agent, hasConcept, externalConceptResource)) {
|
||||
additions.add(agent, hasConcept, externalConceptResource);
|
||||
count++;
|
||||
}
|
||||
|
||||
if (!additions.contains(externalConceptResource, conceptOf, agent)) {
|
||||
additions.add(externalConceptResource, conceptOf, agent);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
protected void migrateRelatedConcepts(Resource externalConceptResource, Resource subjectAreaResource, Model additions) throws IOException {
|
||||
|
||||
Property related = ResourceFactory.createProperty("http://www.w3.org/2004/02/skos/core#related");
|
||||
|
||||
aboxModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
StmtIterator iter = subjectAreaResource.listProperties(related);
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
if (!stmt.getObject().isResource()) continue;
|
||||
Resource relatedConcept = stmt.getObject().asResource();
|
||||
if (!additions.contains(externalConceptResource, related, relatedConcept)) {
|
||||
additions.add(externalConceptResource, related, relatedConcept);
|
||||
}
|
||||
if (!additions.contains(relatedConcept, related, externalConceptResource)) {
|
||||
additions.add(relatedConcept, related, externalConceptResource);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
||||
public void logChanges(Statement oldStatement, Statement newStatement) throws IOException {
|
||||
logChange(oldStatement,false);
|
||||
logChange(newStatement,true);
|
||||
|
|
|
@ -236,7 +236,6 @@ public class KnowledgeBaseUpdater {
|
|||
OntModel newTBoxModel = settings.getNewTBoxModel();
|
||||
OntModel ABoxModel = settings.getAssertionOntModelSelector().getABoxModel();
|
||||
ABoxUpdater aboxUpdater = new ABoxUpdater(oldTBoxModel, newTBoxModel, ABoxModel,settings.getNewTBoxAnnotationsModel(), logger, record);
|
||||
aboxUpdater.migrateExternalConcepts();
|
||||
aboxUpdater.processPropertyChanges(changes.getAtomicPropertyChanges());
|
||||
aboxUpdater.processClassChanges(changes.getAtomicClassChanges());
|
||||
}
|
||||
|
|
|
@ -912,66 +912,6 @@ public class SimpleReasoner extends StatementListener {
|
|||
log.info("ABox inference model updated");
|
||||
}
|
||||
|
||||
|
||||
public synchronized void computeMostSpecificType() {
|
||||
recomputing = true;
|
||||
try {
|
||||
doComputeMostSpecificType();
|
||||
} finally {
|
||||
recomputing = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Special for version 1.4
|
||||
*/
|
||||
public synchronized void doComputeMostSpecificType() {
|
||||
|
||||
log.info("Computing mostSpecificType annotations.");
|
||||
HashSet<String> unknownTypes = new HashSet<String>();
|
||||
|
||||
try {
|
||||
String queryString = "select distinct ?subject where {?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept>}";
|
||||
ArrayList<String> individuals = this.getIndividualURIs(queryString);
|
||||
|
||||
int numStmts = 0;
|
||||
for (String individualURI : individuals ) {
|
||||
|
||||
Resource individual = ResourceFactory.createResource(individualURI);
|
||||
|
||||
try {
|
||||
setMostSpecificTypes(individual, inferenceModel, unknownTypes);
|
||||
} catch (NullPointerException npe) {
|
||||
log.error("a NullPointerException was received while computing mostSpecificType annotations. Halting inference computation.");
|
||||
return;
|
||||
} catch (JenaException je) {
|
||||
if (je.getMessage().equals("Statement models must no be null")) {
|
||||
log.error("Exception while computing mostSpecificType annotations.: " + je.getMessage() + ". Halting inference computation.");
|
||||
return;
|
||||
}
|
||||
log.error("Exception while computing mostSpecificType annotations.: " + je.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("Exception while computing mostSpecificType annotations", e);
|
||||
}
|
||||
|
||||
numStmts++;
|
||||
if ((numStmts % 10000) == 0) {
|
||||
log.info("Still computing mostSpecificType annotations...");
|
||||
}
|
||||
|
||||
if (stopRequested) {
|
||||
log.info("a stopRequested signal was received during computeMostSpecificType. Halting Processing.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Exception while computing mostSpecificType annotations", e);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Finished computing mostSpecificType annotations");
|
||||
}
|
||||
|
||||
public synchronized boolean isABoxReasoningAsynchronous() {
|
||||
if (batchMode1 || batchMode2) {
|
||||
return true;
|
||||
|
|
|
@ -129,10 +129,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
new Thread(new ABoxRecomputer(simpleReasoner),"ABoxRecomputer").start();
|
||||
}
|
||||
|
||||
} else if ( isMSTComputeRequired(sce.getServletContext()) ) {
|
||||
log.info("mostSpecificType computation required. It will be done in a separate thread.");
|
||||
waitForTBoxReasoning(pelletListener);
|
||||
new Thread(new MostSpecificTypeRecomputer(simpleReasoner),"MostSpecificTypeComputer").start();
|
||||
}
|
||||
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
||||
|
@ -232,19 +228,6 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
|||
}
|
||||
}
|
||||
|
||||
private class MostSpecificTypeRecomputer implements Runnable {
|
||||
|
||||
private SimpleReasoner simpleReasoner;
|
||||
|
||||
public MostSpecificTypeRecomputer(SimpleReasoner simpleReasoner) {
|
||||
this.simpleReasoner = simpleReasoner;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
simpleReasoner.computeMostSpecificType();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the names of the plugin classes classes.
|
||||
*
|
||||
|
|
|
@ -109,10 +109,6 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
try {
|
||||
if (ontologyUpdater.updateRequired()) {
|
||||
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
|
||||
log.info("Migrating data model");
|
||||
doMigrateDisplayModel(ctx);
|
||||
log.info("Display model migrated");
|
||||
ontologyUpdater.update();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
String errMsg = "IOException updating knowledge base " +
|
||||
|
@ -137,53 +133,6 @@ public class UpdateKnowledgeBase implements ServletContextListener {
|
|||
return;
|
||||
}
|
||||
OntModel displayModel = (OntModel) o;
|
||||
migrateDisplayModel(displayModel);
|
||||
}
|
||||
|
||||
public static void migrateDisplayModel(Model displayModel) {
|
||||
|
||||
Resource browseDataGetterClass = ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.BrowseDataGetter");
|
||||
Resource pageDataGetterClass = ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.ClassGroupPageData");
|
||||
Resource internalDataGetterClass = ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.InternalClassesDataGetter");
|
||||
Resource individualsDataGetterClass = ResourceFactory.createResource("java:edu.cornell.mannlib.vitro.webapp.utils.pageDataGetter.IndividualsForClassesDataGetter");
|
||||
|
||||
Resource homeDataGetter = ResourceFactory.createResource(DisplayVocabulary.DISPLAY_NS + "homeDataGetter");
|
||||
Property dataGetterProperty = displayModel.getProperty(DisplayVocabulary.HAS_DATA_GETTER);
|
||||
|
||||
Resource homePage = displayModel.getResource(DisplayVocabulary.HOME_PAGE_URI);
|
||||
Resource classGroupPage = displayModel.getResource(DisplayVocabulary.CLASSGROUP_PAGE_TYPE);
|
||||
Resource internalClassesPage = displayModel.getResource(DisplayVocabulary.CLASSINDIVIDUALS_INTERNAL_TYPE);
|
||||
Resource individualsPage = displayModel.getResource(DisplayVocabulary.CLASSINDIVIDUALS_PAGE_TYPE);
|
||||
|
||||
displayModel.add(homePage, dataGetterProperty, homeDataGetter);
|
||||
displayModel.add(homeDataGetter, RDF.type, browseDataGetterClass);
|
||||
|
||||
Model additions = ModelFactory.createDefaultModel();
|
||||
Model retractions = ModelFactory.createDefaultModel();
|
||||
|
||||
StmtIterator iter = displayModel.listStatements((Resource) null, RDF.type, internalClassesPage);
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
retractions.add(stmt);
|
||||
additions.add(stmt.getSubject(), RDF.type, internalDataGetterClass);
|
||||
}
|
||||
|
||||
iter = displayModel.listStatements((Resource) null, RDF.type, classGroupPage);
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
retractions.add(stmt);
|
||||
additions.add(stmt.getSubject(), RDF.type, pageDataGetterClass);
|
||||
}
|
||||
|
||||
iter = displayModel.listStatements((Resource) null, RDF.type, individualsPage);
|
||||
while (iter.hasNext()) {
|
||||
Statement stmt = iter.next();
|
||||
retractions.add(stmt);
|
||||
additions.add(stmt.getSubject(), RDF.type, individualsDataGetterClass);
|
||||
}
|
||||
|
||||
displayModel.remove(retractions);
|
||||
displayModel.add(additions);
|
||||
}
|
||||
|
||||
private OntModel loadModelFromDirectory(String directoryPath) {
|
||||
|
|
|
@ -13,47 +13,8 @@ import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
|||
|
||||
public class UpdateKnowledgeBaseTest extends AbstractTestClass {
|
||||
|
||||
//@org.junit.Test
|
||||
public void testMigrateDisplayModel12() {
|
||||
|
||||
String version12DisplayModel = "\n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#PrimaryLuceneIndex> " +
|
||||
" a <http://www.w3.org/2002/07/owl#Thing> . \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Organizations> \n" +
|
||||
" a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> , \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Page> ; \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup> \n " +
|
||||
" <http://vivoweb.org/ontology#vitroClassGrouporganizations> ; \n " +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#title> \n" +
|
||||
" \"Organizations\" ; \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#urlMapping> \n " +
|
||||
" \"/organizations\" . ";
|
||||
|
||||
String version13DisplayModel = "\n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#SearchIndex> " +
|
||||
" a <http://www.w3.org/2002/07/owl#Thing> . \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Organizations> \n" +
|
||||
" a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Page> ; \n " +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasDataGetter> \n " +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#OrganizationsDataGetter1> ; " +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#title> \n " +
|
||||
" \"Organizations\" ; \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#urlMapping> \n" +
|
||||
" \"/organizations\" . \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#OrganizationsDataGetter1> \n" +
|
||||
" a <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#ClassGroupPage> ; \n" +
|
||||
" <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#forClassGroup> \n" +
|
||||
" <http://vivoweb.org/ontology#vitroClassGrouporganizations> .";
|
||||
|
||||
Model preMigrate = ModelFactory.createDefaultModel().read(new StringReader(version12DisplayModel), null, "N3");
|
||||
Model postMigrate = ModelFactory.createDefaultModel().read(new StringReader(version13DisplayModel), null, "N3");
|
||||
UpdateKnowledgeBase.migrateDisplayModel(preMigrate);
|
||||
Assert.assertTrue(preMigrate.isIsomorphicWith(postMigrate));
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testMigrateDisplayModel13() {
|
||||
public void testMigrateDisplayModel14() {
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue