Skip to content

Commit

Permalink
Merge branch 'main' into feature/5033-Ability-to-configure-recommende…
Browse files Browse the repository at this point in the history
…rs-interactively-on-the-annotation-page

* main:
  #5050 - Tags on the second level of conditional features cannot be selected
  #4977 - Clean up Knowledge Base UI code
  • Loading branch information
reckart committed Sep 13, 2024
2 parents aac1efb + e3dc4f2 commit 720899d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public boolean anyRuleAffectingFeatureMatchesAllConditions(ParsedConstraints aCo

for (var rule : scope.getRules()) {
if (allRuleConditionsMatch(aConstraints, rule, aContext)) {
return anyRestrictionAffectsFeature(aConstraints, rule, aFeature);
if (anyRestrictionAffectsFeature(aConstraints, rule, aFeature)) {
return true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static de.tudarmstadt.ukp.inception.ui.kb.KnowledgeBasePage.PAGE_PARAM_KB_NAME;
import static org.apache.wicket.RuntimeConfigurationType.DEVELOPMENT;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.apache.wicket.AttributeModifier;
Expand Down Expand Up @@ -261,30 +261,39 @@ else if (aKbObject instanceof KBProperty) {
public void actionStatementChanged(AjaxStatementChangedEvent event)
{
// if this event is not about renaming (changing the RDFS label) of a KBObject, return
KBStatement statement = event.getStatement();
var statement = event.getStatement();

if (isLabelStatement(statement)) {
// determine whether the concept name or property name was changed (or neither), then
// update the name in the respective KBHandle

List<Model<? extends KBObject>> models = Arrays.asList(selectedConceptHandle,
selectedPropertyHandle);
models.stream().filter(model -> model.getObject() != null && model.getObject()
.getIdentifier().equals(statement.getInstance().getIdentifier()))
.forEach(model -> {
Optional<KBHandle> kbObject = kbService.readHandle(kbModel.getObject(),
model.getObject().getIdentifier());
if (kbObject.isPresent()) {
model.getObject().setName(kbObject.get().getName());
}
event.getTarget().add(this);
});
if (updateStatmentModel(event, statement, selectedConceptHandle)) {
event.getTarget().add(this);
}
if (updateStatmentModel(event, statement, selectedPropertyHandle)) {
event.getTarget().add(this);
}
}
else {
event.getTarget().add(getPage());
}
}

private boolean updateStatmentModel(AjaxStatementChangedEvent event, KBStatement statement,
Model<? extends KBObject> mod)
{
if (mod.getObject() != null && mod.getObject().getIdentifier()
.equals(statement.getInstance().getIdentifier())) {
var kbObject = kbService.readHandle(kbModel.getObject(),
mod.getObject().getIdentifier());
if (kbObject.isPresent()
&& !Objects.equals(kbObject.get().getName(), mod.getObject().getName())) {
mod.getObject().setName(kbObject.get().getName());
return true;
}
}
return false;
}

/**
* Checks if the given statement is (potentially) assigning the label to the item in subject
* position. This is the case if the property is a label property. Since we do at this point not
Expand All @@ -298,22 +307,6 @@ private boolean isLabelStatement(KBStatement aStatement)
}

return labelProperties.contains(aStatement.getProperty().getIdentifier());

// SimpleValueFactory vf = SimpleValueFactory.getInstance();
//
// String propertyIri = aStatement.getProperty().getIdentifier();
// IRI subjectIri = vf.createIRI(aStatement.getInstance().getIdentifier());
// IRI labelIri = kbModel.getObject().getLabelIri();
//
// try (RepositoryConnection conn = kbService.getConnection(kbModel.getObject())) {
//
// boolean hasMainLabel = RdfUtils
// .readFirst(conn, subjectIri, labelIri, null, kbModel.getObject()).isPresent();
//
// return propertyIri.equals(labelIri.stringValue())
// || (kbService.isLabelProperty(kbModel.getObject(), propertyIri)
// && !hasMainLabel);
// }
}

@OnEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class AjaxStatementChangedEvent
extends AbstractAjaxAwareEvent
{

/**
* Statement editor component of the changed statement.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*/
package de.tudarmstadt.ukp.inception.ui.kb.stmt.editor;

import static org.apache.wicket.event.Broadcast.BREADTH;

import java.util.Iterator;
import java.util.List;
import java.util.Optional;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.event.Broadcast;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand Down Expand Up @@ -145,9 +146,8 @@ private void actionCancelExistingStatement(AjaxRequestTarget aTarget)
private void actionCancelNewStatement(AjaxRequestTarget aTarget)
{
// send a delete event to trigger the deletion in the UI
AjaxStatementChangedEvent deleteEvent = new AjaxStatementChangedEvent(aTarget,
statement.getObject(), this, true);
send(getPage(), Broadcast.BREADTH, deleteEvent);
var deleteEvent = new AjaxStatementChangedEvent(aTarget, statement.getObject(), this, true);
send(getPage(), BREADTH, deleteEvent);
}

private void actionSave(AjaxRequestTarget aTarget, Form<KBStatement> aForm)
Expand All @@ -167,7 +167,7 @@ private void actionSave(AjaxRequestTarget aTarget, Form<KBStatement> aForm)
statement.setObject(modifiedStatement);
// switch back to ViewMode and send notification to listeners
actionCancelExistingStatement(aTarget);
send(getPage(), Broadcast.BREADTH,
send(getPage(), BREADTH,
new AjaxStatementChangedEvent(aTarget, statement.getObject(), oldStatement));
}
catch (RepositoryException e) {
Expand All @@ -184,7 +184,7 @@ private void actionDelete(AjaxRequestTarget aTarget)

AjaxStatementChangedEvent deleteEvent = new AjaxStatementChangedEvent(aTarget,
statement.getObject(), this, true);
send(getPage(), Broadcast.BREADTH, deleteEvent);
send(getPage(), BREADTH, deleteEvent);
}
catch (RepositoryException e) {
error("Unable to delete statement: " + e.getLocalizedMessage());
Expand All @@ -203,8 +203,7 @@ private void actionMakeExplicit(AjaxRequestTarget aTarget)
// KBStatement to false, so that's what's done here
statement.getObject().setInferred(false);
aTarget.add(this);
send(getPage(), Broadcast.BREADTH,
new AjaxStatementChangedEvent(aTarget, statement.getObject()));
send(getPage(), BREADTH, new AjaxStatementChangedEvent(aTarget, statement.getObject()));
}
catch (RepositoryException e) {
error("Unable to make statement explicit " + e.getLocalizedMessage());
Expand Down

0 comments on commit 720899d

Please sign in to comment.