From f8ab3d10166e62907bf8a97e216a02eaad70d35a Mon Sep 17 00:00:00 2001 From: brianjlowe Date: Wed, 16 Oct 2013 09:05:45 -0400 Subject: [PATCH] improvement to annotation migration --- .../webapp/ontology/update/TBoxUpdater.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java index 9c37e1544..0d217ea7b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ontology/update/TBoxUpdater.java @@ -476,11 +476,24 @@ public class TBoxUpdater { " FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" + "} \n" ; - Model userChangesModel = construct( - propertyAnnotationsQuery, userAnnotationsModel).difference( - construct(propertyAnnotationsQuery, oldAnnotationsModel)); + Model userAnnotations = construct( + propertyAnnotationsQuery, userAnnotationsModel); + Model oldAnnotations = construct(propertyAnnotationsQuery, oldAnnotationsModel); - if(userChangesModel.size() == 0) { + Model diff = userAnnotations.difference(oldAnnotations); + + // migrate all current values for any predicate that has been modified + // from the default + Model valuesToMigrate = ModelFactory.createDefaultModel(); + StmtIterator sit = diff.listStatements(); + while(sit.hasNext()) { + Statement stmt = sit.nextStatement(); + valuesToMigrate.add(userAnnotations.listStatements( + null, stmt.getPredicate(), (RDFNode) null)); + + } + + if(valuesToMigrate.size() == 0) { return; } else { log.info("Updating PropertyConfig.n3 to include locally-changed " + @@ -521,11 +534,10 @@ public class TBoxUpdater { FileInputStream fis = new FileInputStream(file); configModel.read(fis, null, "N3"); - Model currentUnion = ModelFactory.createUnion(configModel, - userAnnotationsModel); + Model userChangesUnion = ModelFactory.createUnion(configModel, valuesToMigrate); - Model userAnnotationsAsConfig = construct(newQuery, currentUnion); - Model currentDefaultConfig = construct(existingQuery, currentUnion); + Model userAnnotationsAsConfig = construct(newQuery, userChangesUnion); + Model currentDefaultConfig = construct(existingQuery, configModel); Model additions = userAnnotationsAsConfig.difference(currentDefaultConfig); Model retractions = currentDefaultConfig.difference(userAnnotationsAsConfig);