VIVO-366 change to annotation-to-PropertyConfig converter to deal with multiple values
This commit is contained in:
parent
e33070b3a8
commit
cd28028fb3
2 changed files with 70 additions and 77 deletions
|
@ -93,18 +93,6 @@ public class KnowledgeBaseUpdater {
|
||||||
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
|
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
|
||||||
|
|
||||||
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,settings.getNewTBoxModel(),settings.getOldTBoxModel());
|
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,settings.getNewTBoxModel(),settings.getOldTBoxModel());
|
||||||
|
|
||||||
// Only modify the TBox and migration metadata the first time
|
|
||||||
if(updateRequired(servletContext)) {
|
|
||||||
//process the TBox before the ABox
|
|
||||||
try {
|
|
||||||
log.debug("\tupdating tbox annotations");
|
|
||||||
updateTBoxAnnotations();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e,e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// update ABox data any time
|
// update ABox data any time
|
||||||
log.info("performing SPARQL CONSTRUCT additions");
|
log.info("performing SPARQL CONSTRUCT additions");
|
||||||
|
@ -124,6 +112,18 @@ public class KnowledgeBaseUpdater {
|
||||||
performSparqlConstructs(settings.getSparqlConstructDeletionsDir() + "/post/",
|
performSparqlConstructs(settings.getSparqlConstructDeletionsDir() + "/post/",
|
||||||
settings.getRDFService(), RETRACT);
|
settings.getRDFService(), RETRACT);
|
||||||
|
|
||||||
|
|
||||||
|
// Only modify the TBox and migration metadata the first time
|
||||||
|
if(updateRequired(servletContext)) {
|
||||||
|
//process the TBox before the ABox
|
||||||
|
try {
|
||||||
|
log.debug("\tupdating tbox annotations");
|
||||||
|
updateTBoxAnnotations();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -450,90 +450,69 @@ public class TBoxUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renameProperty(AtomicOntologyChange changeObj) throws IOException {
|
public void renameProperty(AtomicOntologyChange changeObj) throws IOException {
|
||||||
Dataset dataset = new RDFServiceDataset(settings.getRDFService());
|
|
||||||
Model userAnnotationsModel = dataset.getNamedModel(
|
|
||||||
JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
|
||||||
if(changeObj.getNotes() != null && changeObj.getNotes().startsWith("cc:")) {
|
if(changeObj.getNotes() != null && changeObj.getNotes().startsWith("cc:")) {
|
||||||
mergePropertyAnnotationsToPropertyConfig(changeObj, userAnnotationsModel);
|
mergePropertyAnnotationsToPropertyConfig(changeObj, siteModel);
|
||||||
}
|
}
|
||||||
Resource renamedProperty = userAnnotationsModel.getResource(changeObj.getSourceURI());
|
Resource renamedProperty = siteModel.getResource(changeObj.getSourceURI());
|
||||||
userAnnotationsModel.removeAll(renamedProperty, null, (RDFNode) null);
|
siteModel.removeAll(renamedProperty, null, (RDFNode) null);
|
||||||
userAnnotationsModel.removeAll(null, null, renamedProperty);
|
siteModel.removeAll(null, null, renamedProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergePropertyAnnotationsToPropertyConfig(AtomicOntologyChange changeObj,
|
private void mergePropertyAnnotationsToPropertyConfig(AtomicOntologyChange changeObj,
|
||||||
Model userAnnotationsModel) throws IOException {
|
Model userAnnotationsModel) throws IOException {
|
||||||
String contextURI = VitroVocabulary.PROPERTY_CONFIG_DATA + changeObj.getNotes().substring(3);
|
String contextURI = VitroVocabulary.PROPERTY_CONFIG_DATA + changeObj.getNotes().substring(3);
|
||||||
String oldPropertyURI = changeObj.getSourceURI();
|
String oldPropertyURI = changeObj.getSourceURI();
|
||||||
|
|
||||||
Model oldAnnotationsModel = settings.getOldTBoxAnnotationsModel();
|
Model oldAnnotationsModel = settings.getOldTBoxAnnotationsModel();
|
||||||
|
|
||||||
String propertyAnnotationsQuery =
|
String propertyAnnotationsQuery =
|
||||||
"PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
"PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
||||||
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||||
"CONSTRUCT { \n" +
|
"CONSTRUCT { \n" +
|
||||||
" <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group . \n" +
|
|
||||||
" <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label . \n" +
|
" <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label . \n" +
|
||||||
" <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank . \n" +
|
" <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
|
||||||
" <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm . \n" +
|
|
||||||
" <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
|
|
||||||
" <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
|
|
||||||
"} WHERE { \n" +
|
"} WHERE { \n" +
|
||||||
" { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
|
" { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
|
||||||
" UNION { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
|
" UNION { <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
|
||||||
" UNION { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank } \n" +
|
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
|
||||||
" UNION { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm } \n" +
|
|
||||||
" UNION { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
|
|
||||||
" UNION { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n " +
|
|
||||||
"} \n" ;
|
"} \n" ;
|
||||||
|
|
||||||
Model userChangesModel = construct(
|
Model userChangesModel = construct(
|
||||||
propertyAnnotationsQuery, userAnnotationsModel).difference(
|
propertyAnnotationsQuery, userAnnotationsModel).difference(
|
||||||
construct(propertyAnnotationsQuery, oldAnnotationsModel));
|
construct(propertyAnnotationsQuery, oldAnnotationsModel));
|
||||||
|
|
||||||
String addQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
if(userChangesModel.size() == 0) {
|
||||||
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
return;
|
||||||
"CONSTRUCT { \n" +
|
} else {
|
||||||
" ?configuration config:propertyGroup ?group . \n" +
|
log.info("Updating PropertyConfig.n3 to include locally-changed " +
|
||||||
" ?configuration config:displayName ?label . \n" +
|
"settings from old property " + oldPropertyURI);
|
||||||
" ?configuration vitro:displayRankAnnot ?displayRank . \n" +
|
}
|
||||||
" ?configuration vitro:customEntryFormAnnot ?customForm . \n" +
|
|
||||||
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
|
|
||||||
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
|
|
||||||
"} WHERE { \n" +
|
|
||||||
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank } \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm } \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
|
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n " +
|
|
||||||
"} \n" ;
|
|
||||||
|
|
||||||
String retractQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
String newQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
||||||
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||||
"CONSTRUCT { \n" +
|
"CONSTRUCT { \n" +
|
||||||
" <" + oldPropertyURI + "> config:propertyGroup ?rgroup . \n" +
|
" ?configuration config:propertyGroup ?group . \n" +
|
||||||
" ?configuration config:displayName ?rlabel . \n" +
|
" ?configuration config:displayName ?label . \n" +
|
||||||
" ?configuration vitro:displayRankAnnot ?rdisplayRank . \n" +
|
" ?configuration ?vitroProp ?vitroValue . \n" +
|
||||||
" ?configuration vitro:customEntryFormAnnot ?rcustomForm . \n" +
|
|
||||||
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?rdisplayLevel . \n" +
|
|
||||||
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?rupdateLevel . \n " +
|
|
||||||
"} WHERE { \n" +
|
"} WHERE { \n" +
|
||||||
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
|
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group . \n" +
|
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
|
||||||
" ?configuration config:propertyGroup ?rgroup } \n" +
|
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label . \n" +
|
" OPTIONAL { <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
|
||||||
" ?configuration config:displayName ?rlabel . \n " +
|
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
|
||||||
" FILTER(?rlabel != ?label) } \n " +
|
"} \n" ;
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank . \n" +
|
|
||||||
" ?configuration vitro:displayRantAnnot ?rdisplayRank } \n " +
|
String existingQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm . \n" +
|
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||||
" ?configuration vitro:customEntryFormAnnot ?rcustomForm } \n" +
|
"CONSTRUCT { \n" +
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
|
" ?configuration config:propertyGroup ?group . \n" +
|
||||||
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?rdisplayLevel } \n" +
|
" ?configuration config:displayName ?label . \n" +
|
||||||
" OPTIONAL { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
|
" ?configuration ?vitroProp ?vitroValue . \n" +
|
||||||
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } " +
|
"} WHERE { \n" +
|
||||||
|
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
|
||||||
|
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
|
||||||
|
" OPTIONAL { ?configuration config:displayName ?label } \n" +
|
||||||
|
" OPTIONAL { ?configuration ?vitroProp ?vitroValue \n" +
|
||||||
|
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
|
||||||
"} \n" ;
|
"} \n" ;
|
||||||
|
|
||||||
Model configModel = ModelFactory.createDefaultModel();
|
Model configModel = ModelFactory.createDefaultModel();
|
||||||
|
@ -542,17 +521,31 @@ public class TBoxUpdater {
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
configModel.read(fis, null, "N3");
|
configModel.read(fis, null, "N3");
|
||||||
|
|
||||||
Model union = ModelFactory.createUnion(configModel,
|
Model currentUnion = ModelFactory.createUnion(configModel,
|
||||||
userChangesModel);
|
userAnnotationsModel);
|
||||||
|
|
||||||
Model additions = construct(addQuery, union);
|
Model userAnnotationsAsConfig = construct(newQuery, currentUnion);
|
||||||
Model retractions = construct(retractQuery, union);
|
Model currentDefaultConfig = construct(existingQuery, currentUnion);
|
||||||
|
|
||||||
if (additions.size() > 0 || retractions.size() > 0) {
|
Model additions = userAnnotationsAsConfig.difference(currentDefaultConfig);
|
||||||
configModel.remove(retractions);
|
Model retractions = currentDefaultConfig.difference(userAnnotationsAsConfig);
|
||||||
log.info("Removing " + retractions.size() + " statements from " + contextURI);
|
|
||||||
|
// filter the retractions so we won't remove a value for a given predicate
|
||||||
|
// unless the additions model contains at least one value for the same predicate
|
||||||
|
Model filteredRetractions = ModelFactory.createDefaultModel();
|
||||||
|
StmtIterator retractIt = retractions.listStatements();
|
||||||
|
while(retractIt.hasNext()) {
|
||||||
|
Statement candidate = retractIt.nextStatement();
|
||||||
|
if(additions.contains(null, candidate.getPredicate(), (RDFNode) null)) {
|
||||||
|
filteredRetractions.add(candidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additions.size() > 0 || filteredRetractions.size() > 0) {
|
||||||
|
configModel.remove(filteredRetractions);
|
||||||
|
log.debug("Removing " + filteredRetractions.size() + " statements from " + contextURI);
|
||||||
configModel.add(additions);
|
configModel.add(additions);
|
||||||
log.info("Adding " + additions.size() + " statements from " + contextURI);
|
log.debug("Adding " + additions.size() + " statements from " + contextURI);
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
configModel.write(fos, "N3");
|
configModel.write(fos, "N3");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue