-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip added edit parents functionality. not tested yet.
- Loading branch information
Showing
4 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/edu/stanford/protege/webprotege/bulkop/ChangeEntityParentsActionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package edu.stanford.protege.webprotege.bulkop; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import edu.stanford.protege.webprotege.access.AccessManager; | ||
import edu.stanford.protege.webprotege.change.ChangeApplicationResult; | ||
import edu.stanford.protege.webprotege.change.ChangeListGenerator; | ||
import edu.stanford.protege.webprotege.change.HasApplyChanges; | ||
import edu.stanford.protege.webprotege.dispatch.AbstractProjectChangeHandler; | ||
import edu.stanford.protege.webprotege.ipc.ExecutionContext; | ||
import org.semanticweb.owlapi.model.OWLClass; | ||
import org.semanticweb.owlapi.model.OWLEntity; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
|
||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 25 Sep 2018 | ||
*/ | ||
public class ChangeEntityParentsActionHandler extends AbstractProjectChangeHandler<Boolean, ChangeEntityParentsAction, ChangeEntityParentsResult> { | ||
|
||
@Nonnull | ||
private final EditParentsChangeListGeneratorFactory factory; | ||
|
||
@Inject | ||
public ChangeEntityParentsActionHandler(@Nonnull AccessManager accessManager, | ||
@Nonnull HasApplyChanges applyChanges, | ||
@Nonnull EditParentsChangeListGeneratorFactory factory) { | ||
super(accessManager, applyChanges); | ||
this.factory = factory; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Class<ChangeEntityParentsAction> getActionClass() { | ||
return ChangeEntityParentsAction.class; | ||
} | ||
|
||
@Override | ||
protected ChangeListGenerator<Boolean> getChangeListGenerator(ChangeEntityParentsAction action, ExecutionContext executionContext) { | ||
if(action.entity().isOWLClass()) { | ||
ImmutableSet<OWLClass> parents = action.parents().stream().map(OWLEntity::asOWLClass).collect(toImmutableSet()); | ||
return factory.create(action.changeRequestId(), parents, action.entity().asOWLClass(), action.commitMessage()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected ChangeEntityParentsResult createActionResult(ChangeApplicationResult<Boolean> changeApplicationResult, | ||
ChangeEntityParentsAction action, | ||
ExecutionContext executionContext) { | ||
return new ChangeEntityParentsResult(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/edu/stanford/protege/webprotege/bulkop/ChangeEntityParentsCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.stanford.protege.webprotege.bulkop; | ||
|
||
import edu.stanford.protege.webprotege.api.ActionExecutor; | ||
import edu.stanford.protege.webprotege.ipc.CommandHandler; | ||
import edu.stanford.protege.webprotege.ipc.ExecutionContext; | ||
import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; | ||
import reactor.core.publisher.Mono; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2021-08-21 | ||
*/ | ||
@WebProtegeHandler | ||
public class ChangeEntityParentsCommandHandler implements CommandHandler<ChangeEntityParentsAction, ChangeEntityParentsResult> { | ||
|
||
private final ActionExecutor executor; | ||
|
||
public ChangeEntityParentsCommandHandler(ActionExecutor executor) { | ||
this.executor = executor; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getChannelName() { | ||
return ChangeEntityParentsAction.CHANNEL; | ||
} | ||
|
||
@Override | ||
public Class<ChangeEntityParentsAction> getRequestClass() { | ||
return ChangeEntityParentsAction.class; | ||
} | ||
|
||
@Override | ||
public Mono<ChangeEntityParentsResult> handleRequest(ChangeEntityParentsAction request, | ||
ExecutionContext executionContext) { | ||
return executor.executeRequest(request, executionContext); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/main/java/edu/stanford/protege/webprotege/bulkop/EditParentsChangeListGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package edu.stanford.protege.webprotege.bulkop; | ||
|
||
|
||
import com.google.common.collect.ImmutableSet; | ||
import edu.stanford.protege.webprotege.change.AddAxiomChange; | ||
import edu.stanford.protege.webprotege.change.ChangeApplicationResult; | ||
import edu.stanford.protege.webprotege.change.ChangeGenerationContext; | ||
import edu.stanford.protege.webprotege.change.ChangeListGenerator; | ||
import edu.stanford.protege.webprotege.change.OntologyChangeList; | ||
import edu.stanford.protege.webprotege.change.RemoveAxiomChange; | ||
import edu.stanford.protege.webprotege.common.ChangeRequestId; | ||
import edu.stanford.protege.webprotege.index.ProjectOntologiesIndex; | ||
import edu.stanford.protege.webprotege.index.SubClassOfAxiomsBySubClassIndex; | ||
import edu.stanford.protege.webprotege.owlapi.RenameMap; | ||
import org.semanticweb.owlapi.model.OWLClass; | ||
import org.semanticweb.owlapi.model.OWLDataFactory; | ||
import org.semanticweb.owlapi.model.OWLOntologyID; | ||
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 25 Sep 2018 | ||
*/ | ||
public class EditParentsChangeListGenerator implements ChangeListGenerator<Boolean> { | ||
|
||
@Nonnull | ||
private final ChangeRequestId changeRequestId; | ||
|
||
@Nonnull | ||
private final ImmutableSet<OWLClass> parents; | ||
|
||
@Nonnull | ||
private final OWLClass entity; | ||
|
||
@Nonnull | ||
private final ProjectOntologiesIndex projectOntologies; | ||
|
||
@Nonnull | ||
private final SubClassOfAxiomsBySubClassIndex subClassAxiomIndex; | ||
|
||
@Nonnull | ||
private final OWLDataFactory dataFactory; | ||
|
||
@Nonnull | ||
private final String commitMessage; | ||
|
||
@Inject | ||
public EditParentsChangeListGenerator(@Nonnull ChangeRequestId changeRequestId, | ||
@Nonnull ImmutableSet<OWLClass> parents, | ||
@Nonnull OWLClass entity, | ||
@Nonnull String commitMessage, | ||
@Nonnull ProjectOntologiesIndex projectOntologies, | ||
@Nonnull SubClassOfAxiomsBySubClassIndex subClassAxiomIndex, | ||
@Nonnull OWLDataFactory dataFactory) { | ||
this.changeRequestId = changeRequestId; | ||
this.parents = checkNotNull(parents); | ||
this.entity = checkNotNull(entity); | ||
this.projectOntologies = checkNotNull(projectOntologies); | ||
this.subClassAxiomIndex = checkNotNull(subClassAxiomIndex); | ||
this.dataFactory = checkNotNull(dataFactory); | ||
this.commitMessage = checkNotNull(commitMessage); | ||
} | ||
|
||
@Override | ||
public ChangeRequestId getChangeRequestId() { | ||
return changeRequestId; | ||
} | ||
|
||
@Override | ||
public OntologyChangeList<Boolean> generateChanges(ChangeGenerationContext context) { | ||
var changeList = new OntologyChangeList.Builder<Boolean>(); | ||
var ontologyId = projectOntologies.getOntologyIds().filter(owlOntologyID -> owlOntologyID.getOntologyIRI().get()==entity.getIRI()).findAny(); | ||
|
||
ontologyId.ifPresent(ontId -> { | ||
parents.forEach(parentClass -> { | ||
subClassAxiomIndex | ||
.getSubClassOfAxiomsForSubClass(entity, ontId) | ||
.filter(ax -> ax.getSuperClass().isNamed()) | ||
.filter(ax -> !ax.getSuperClass().equals(parentClass)) | ||
.forEach(ax -> processAxiom(ax, parentClass, ontId, changeList)); | ||
}); | ||
}); | ||
|
||
|
||
return changeList.build(true); | ||
} | ||
|
||
private void processAxiom(OWLSubClassOfAxiom ax, | ||
OWLClass parent, | ||
OWLOntologyID ontId, | ||
OntologyChangeList.Builder<Boolean> changeList) { | ||
var removeAxiom = RemoveAxiomChange.of(ontId, ax); | ||
changeList.add(removeAxiom); | ||
var replacementAx = dataFactory.getOWLSubClassOfAxiom(entity, parent, ax.getAnnotations()); | ||
var addAxiom = AddAxiomChange.of(ontId, replacementAx); | ||
changeList.add(addAxiom); | ||
} | ||
|
||
@Override | ||
public Boolean getRenamedResult(Boolean result, | ||
RenameMap renameMap) { | ||
return result; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getMessage(ChangeApplicationResult<Boolean> result) { | ||
return commitMessage; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...in/java/edu/stanford/protege/webprotege/bulkop/EditParentsChangeListGeneratorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package edu.stanford.protege.webprotege.bulkop; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import edu.stanford.protege.webprotege.common.ChangeRequestId; | ||
import edu.stanford.protege.webprotege.index.ProjectOntologiesIndex; | ||
import edu.stanford.protege.webprotege.index.SubClassOfAxiomsBySubClassIndex; | ||
import org.semanticweb.owlapi.model.OWLClass; | ||
import org.semanticweb.owlapi.model.OWLDataFactory; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2021-07-13 | ||
*/ | ||
public class EditParentsChangeListGeneratorFactory { | ||
|
||
private final ProjectOntologiesIndex projectOntologiesIndex; | ||
|
||
private final SubClassOfAxiomsBySubClassIndex subClassOfAxiomsBySubClassIndex; | ||
|
||
private final OWLDataFactory dataFactory; | ||
|
||
public EditParentsChangeListGeneratorFactory(ProjectOntologiesIndex projectOntologiesIndex, | ||
SubClassOfAxiomsBySubClassIndex subClassOfAxiomsBySubClassIndex, | ||
OWLDataFactory dataFactory) { | ||
this.projectOntologiesIndex = projectOntologiesIndex; | ||
this.subClassOfAxiomsBySubClassIndex = subClassOfAxiomsBySubClassIndex; | ||
this.dataFactory = dataFactory; | ||
} | ||
|
||
public EditParentsChangeListGenerator create(ChangeRequestId changeRequestId, | ||
ImmutableSet<OWLClass> parents, | ||
OWLClass entity, | ||
String commitMessage) { | ||
return new EditParentsChangeListGenerator(changeRequestId, parents, | ||
entity, | ||
commitMessage, | ||
projectOntologiesIndex, | ||
subClassOfAxiomsBySubClassIndex, | ||
dataFactory); | ||
} | ||
} |