diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestion.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestion.java index e13dfb989c7..42cfc1c5946 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestion.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestion.java @@ -106,7 +106,7 @@ public AnnotationSuggestion(int aId, int aGeneration, int aAge, long aRecommende scoreExplanation = aScoreExplanation; recommenderId = aRecommenderId; documentName = aDocumentName; - autoAcceptMode = aAutoAcceptMode; + autoAcceptMode = aAutoAcceptMode != null ? aAutoAcceptMode : AutoAcceptMode.NEVER; hidingFlags = aHidingFlags; } diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/Predictions.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/Predictions.java index 14f0c17e38a..11488d772de 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/Predictions.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/Predictions.java @@ -335,6 +335,11 @@ public List getPredictionsByRecommenderAndDocument( } } + public List getPredictionsByDocument(SourceDocument aDocument) + { + return getPredictionsByDocument(aDocument.getName()); + } + public List getPredictionsByDocument(String aDocumentName) { synchronized (predictionsLock) { diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/RelationSuggestion.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/RelationSuggestion.java index ca1a7d22730..46c1d0bffda 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/RelationSuggestion.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/RelationSuggestion.java @@ -21,6 +21,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + public class RelationSuggestion extends AnnotationSuggestion implements Serializable @@ -206,6 +208,13 @@ public Builder withFeature(String aFeature) return this; } + public Builder withDocument(SourceDocument aDocument) + { + this.documentName = aDocument.getName(); + return this; + } + + @Deprecated public Builder withDocumentName(String aDocumentName) { this.documentName = aDocumentName; diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestion.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestion.java index d6041865c59..3d5ba6aae1e 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestion.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestion.java @@ -21,6 +21,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + public class SpanSuggestion extends AnnotationSuggestion implements Serializable @@ -41,22 +43,6 @@ private SpanSuggestion(Builder builder) coveredText = builder.coveredText; } - /** - * @deprecated Use builder instead. - */ - @Deprecated - public SpanSuggestion(int aId, long aRecommenderId, String aRecommenderName, long aLayerId, - String aFeature, String aDocumentName, int aBegin, int aEnd, String aCoveredText, - String aLabel, String aUiLabel, double aScore, String aScoreExplanation, - AutoAcceptMode aAutoAcceptMode) - { - super(aId, 0, 0, aRecommenderId, aRecommenderName, aLayerId, aFeature, aDocumentName, - aLabel, aUiLabel, aScore, aScoreExplanation, aAutoAcceptMode, 0); - - position = new Offset(aBegin, aEnd); - coveredText = aCoveredText; - } - // Getter and setter public String getCoveredText() @@ -164,7 +150,7 @@ public static final class Builder private String scoreExplanation; private Offset position; private String coveredText; - private AutoAcceptMode autoAcceptMode; + private AutoAcceptMode autoAcceptMode = AutoAcceptMode.NEVER; private int hidingFlags; private Builder() @@ -198,31 +184,42 @@ public Builder withRecommender(Recommender aRecommender) return this; } - public Builder withRecommenderId(long aRecommenderId) + @Deprecated + Builder withRecommenderId(long aRecommenderId) { this.recommenderId = aRecommenderId; return this; } - public Builder withRecommenderName(String aRecommenderName) + @Deprecated + Builder withRecommenderName(String aRecommenderName) { this.recommenderName = aRecommenderName; return this; } - public Builder withLayerId(long aLayerId) + @Deprecated + Builder withLayerId(long aLayerId) { this.layerId = aLayerId; return this; } - public Builder withFeature(String aFeature) + @Deprecated + Builder withFeature(String aFeature) { this.feature = aFeature; return this; } - public Builder withDocumentName(String aDocumentName) + public Builder withDocument(SourceDocument aDocument) + { + this.documentName = aDocument.getName(); + return this; + } + + @Deprecated + Builder withDocumentName(String aDocumentName) { this.documentName = aDocumentName; return this; @@ -252,6 +249,12 @@ public Builder withScoreExplanation(String aScoreExplanation) return this; } + public Builder withPosition(int aBegin, int aEnd) + { + this.position = new Offset(aBegin, aEnd); + return this; + } + public Builder withPosition(Offset aPosition) { this.position = aPosition; diff --git a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestionTest.java b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestionTest.java index 296d2ee85d9..db4fb5cf2de 100644 --- a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestionTest.java +++ b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/AnnotationSuggestionTest.java @@ -17,31 +17,44 @@ */ package de.tudarmstadt.ukp.inception.recommendation.api.model; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AutoAcceptMode.NEVER; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; -import java.util.List; - import org.junit.jupiter.api.Test; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + public class AnnotationSuggestionTest { @Test public void thatEqualsAndHashCodeAndCompareToWorkCorrectly() { - SpanSuggestion rec1Sug1 = new SpanSuggestion(1, 1, "rec1", 1, "value", "doc1", 0, 1, "a", - "A", "#A", 0.1, "E1", NEVER); - SpanSuggestion rec1Sug2 = new SpanSuggestion(2, 1, "rec1", 1, "value", "doc1", 0, 1, "b", - "B", "#B", 0.2, "E2", NEVER); - SpanSuggestion rec2Sug1 = new SpanSuggestion(3, 2, "rec2", 1, "value", "doc1", 0, 1, "c", - "C", "#C", 0.1, "E1", NEVER); - SpanSuggestion rec2Sug2 = new SpanSuggestion(4, 2, "rec2", 1, "value", "doc1", 0, 1, "d", - "D", "#D", 0.3, "E3", NEVER); - - List all = asList(rec1Sug1, rec1Sug2, rec2Sug1, rec2Sug2); - for (SpanSuggestion x : all) { - for (SpanSuggestion y : all) { + var doc = SourceDocument.builder().withName("doc1").build(); + var layer = AnnotationLayer.builder().withId(1l).build(); + var feature = AnnotationFeature.builder().withLayer(layer).withName("value").build(); + var rec1 = Recommender.builder().withId(1l).withLayer(layer).withFeature(feature).build(); + var rec2 = Recommender.builder().withId(2l).withLayer(layer).withFeature(feature).build(); + + var builder = SpanSuggestion.builder().withLayerId(1).withFeature("value").withDocument(doc) + .withPosition(0, 1); + + builder.withRecommender(rec1); + var rec1Sug1 = builder.withId(1).withCoveredText("a").withLabel("A").withUiLabel("#A") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec1Sug2 = builder.withId(2).withCoveredText("b").withLabel("B").withUiLabel("#B") + .withScore(0.2).withScoreExplanation("E2").build(); + + builder.withRecommender(rec2); + var rec2Sug1 = builder.withId(3).withCoveredText("c").withLabel("C").withUiLabel("#C") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec2Sug2 = builder.withId(4).withCoveredText("d").withLabel("D").withUiLabel("#D") + .withScore(0.3).withScoreExplanation("E3").build(); + + var all = asList(rec1Sug1, rec1Sug2, rec2Sug1, rec2Sug2); + for (var x : all) { + for (var y : all) { if (x == y) { assertThat(x).isEqualTo(y); assertThat(y).isEqualTo(x); diff --git a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionGroupTest.java b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionGroupTest.java index 4dec3c7510b..67ed18f16b8 100644 --- a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionGroupTest.java +++ b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionGroupTest.java @@ -17,53 +17,82 @@ */ package de.tudarmstadt.ukp.inception.recommendation.api.model; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AutoAcceptMode.NEVER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + public class PredictionGroupTest { + private SourceDocument doc; + private AnnotationLayer layer; + private AnnotationFeature feature; + private Recommender rec1; + private Recommender rec2; + + @BeforeEach + void setup() + { + doc = SourceDocument.builder().withId(123l).withName("doc1").build(); + layer = AnnotationLayer.builder().withId(1337l).withName("layer").build(); + feature = AnnotationFeature.builder().withId(1338l).withName("value").withLayer(layer) + .build(); + rec1 = Recommender.builder().withId(1l).withName("rec1").withLayer(layer) + .withFeature(feature).build(); + rec2 = Recommender.builder().withId(2l).withName("rec2").withLayer(layer) + .withFeature(feature).build(); + } + @Test public void thatAddingElementsToGroupWorks() { - var rec1Sug1 = new SpanSuggestion(1, 1, "rec1", 1, "value", "doc1", 0, 1, "a", "A", "#A", - 0.1, "E1", NEVER); - var rec1Sug2 = new SpanSuggestion(2, 1, "rec1", 1, "value", "doc1", 0, 1, "b", "B", "#B", - 0.2, "E2", NEVER); - var rec2Sug1 = new SpanSuggestion(3, 2, "rec2", 1, "value", "doc1", 0, 1, "c", "C", "#C", - 0.1, "E1", NEVER); - var rec2Sug2 = new SpanSuggestion(4, 2, "rec2", 1, "value", "doc1", 0, 1, "d", "D", "#D", - 0.3, "E3", NEVER); + var builder = SpanSuggestion.builder().withDocument(doc).withPosition(0, 1); + + builder.withRecommender(rec1); + var rec1Sug1 = builder.withId(1).withCoveredText("a").withLabel("A").withUiLabel("#A") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec1Sug2 = builder.withId(2).withCoveredText("b").withLabel("B").withUiLabel("#B") + .withScore(0.2).withScoreExplanation("E2").build(); + + builder.withRecommender(rec2); + var rec2Sug1 = builder.withId(3).withCoveredText("c").withLabel("C").withUiLabel("#C") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec2Sug2 = builder.withId(4).withCoveredText("d").withLabel("D").withUiLabel("#D") + .withScore(0.3).withScoreExplanation("E3").build(); // Ensure that group grows and that all elements are added properly var sut = new SuggestionGroup<>(); sut.add(rec1Sug1); - assertThat(sut).hasSize(1); - assertThat(sut).contains(rec1Sug1); + assertThat(sut).hasSize(1).contains(rec1Sug1); sut.add(rec1Sug2); - assertThat(sut).hasSize(2); - assertThat(sut).contains(rec1Sug2); + assertThat(sut).hasSize(2).contains(rec1Sug2); sut.add(rec2Sug1); - assertThat(sut).hasSize(3); - assertThat(sut).contains(rec2Sug1); + assertThat(sut).hasSize(3).contains(rec2Sug1); sut.add(rec2Sug2); - assertThat(sut).hasSize(4); - assertThat(sut).contains(rec2Sug2); + assertThat(sut).hasSize(4).contains(rec2Sug2); } @Test public void thatSortingWorks() { - var rec1Sug1 = new SpanSuggestion(1, 1, "rec1", 1, "value", "doc1", 0, 1, "a", "A", "#A", - 0.1, "E1", NEVER); - var rec1Sug2 = new SpanSuggestion(2, 1, "rec1", 1, "value", "doc1", 0, 1, "b", "B", "#B", - 0.2, "E2", NEVER); - var rec2Sug1 = new SpanSuggestion(3, 2, "rec2", 1, "value", "doc1", 0, 1, "c", "C", "#C", - 0.1, "E1", NEVER); - var rec2Sug2 = new SpanSuggestion(4, 2, "rec2", 1, "value", "doc1", 0, 1, "d", "D", "#D", - 0.3, "E3", NEVER); + var builder = SpanSuggestion.builder().withDocument(doc).withPosition(0, 1); + + builder.withRecommender(rec1); + var rec1Sug1 = builder.withId(1).withCoveredText("a").withLabel("A").withUiLabel("#A") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec1Sug2 = builder.withId(2).withCoveredText("b").withLabel("B").withUiLabel("#B") + .withScore(0.2).withScoreExplanation("E2").build(); + + builder.withRecommender(rec2); + var rec2Sug1 = builder.withId(3).withCoveredText("c").withLabel("C").withUiLabel("#C") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec2Sug2 = builder.withId(4).withCoveredText("d").withLabel("D").withUiLabel("#D") + .withScore(0.3).withScoreExplanation("E3").build(); var sut = new SuggestionGroup<>(rec1Sug1, rec1Sug2, rec2Sug1, rec2Sug2); @@ -83,14 +112,19 @@ public void thatSortingWorks() @Test public void thatTopDeltasAreCorrect() { - var rec1Sug1 = new SpanSuggestion(1, 1, "rec1", 1, "value", "doc1", 0, 1, "a", "A", "#A", - 0.1, "E1", NEVER); - var rec1Sug2 = new SpanSuggestion(2, 1, "rec1", 1, "value", "doc1", 0, 1, "b", "B", "#B", - 0.2, "E2", NEVER); - var rec2Sug1 = new SpanSuggestion(3, 2, "rec2", 1, "value", "doc1", 0, 1, "c", "C", "#C", - 0.1, "E1", NEVER); - var rec2Sug2 = new SpanSuggestion(4, 2, "rec2", 1, "value", "doc1", 0, 1, "d", "D", "#D", - 0.3, "E3", NEVER); + var builder = SpanSuggestion.builder().withDocument(doc).withPosition(0, 1); + + builder.withRecommender(rec1); + var rec1Sug1 = builder.withId(1).withCoveredText("a").withLabel("A").withUiLabel("#A") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec1Sug2 = builder.withId(2).withCoveredText("b").withLabel("B").withUiLabel("#B") + .withScore(0.2).withScoreExplanation("E2").build(); + + builder.withRecommender(rec2); + var rec2Sug1 = builder.withId(3).withCoveredText("c").withLabel("C").withUiLabel("#C") + .withScore(0.1).withScoreExplanation("E1").build(); + var rec2Sug2 = builder.withId(4).withCoveredText("d").withLabel("D").withUiLabel("#D") + .withScore(0.3).withScoreExplanation("E3").build(); var sut = new SuggestionGroup<>(rec1Sug1, rec1Sug2, rec2Sug1, rec2Sug2); diff --git a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionsTest.java b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionsTest.java index c34b608b3aa..9dfa4621b10 100644 --- a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionsTest.java +++ b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/PredictionsTest.java @@ -37,8 +37,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; import de.tudarmstadt.ukp.clarin.webanno.model.Project; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; import de.tudarmstadt.ukp.clarin.webanno.security.model.User; import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence; import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; @@ -112,12 +114,12 @@ void timeGetGroupedPredictions() throws Exception @Test void thatIdsAreAssigned() throws Exception { - var doc = "doc"; + var doc = SourceDocument.builder().withName("doc").build(); sut = new Predictions(user, user.getUsername(), project); sut.putPredictions(asList( // SpanSuggestion.builder() // .withId(AnnotationSuggestion.NEW_ID) // - .withDocumentName(doc) // + .withDocument(doc) // .build())); assertThat(sut.getPredictionsByDocument(doc)) // @@ -129,7 +131,7 @@ void thatIdsAreAssigned() throws Exception sut.putPredictions(asList( // SpanSuggestion.builder() // .withId(AnnotationSuggestion.NEW_ID) // - .withDocumentName(doc) // + .withDocument(doc) // .build())); sut.putPredictions(inheritedPredictions); @@ -148,25 +150,24 @@ private List generatePredictions(int aDocs, int aRecommend var tokens = cas.select(Token.class).asList(); var result = new ArrayList(); - for (int docId = 0; docId < aDocs; docId++) { - var docName = "doc" + docId; - for (var recId = 0; recId < aRecommenders; recId++) { - var recName = "rec" + recId; - var featName = "feat" + recId; + for (var docId = 0l; docId < aDocs; docId++) { + var doc = SourceDocument.builder().withId(docId).withName("doc" + docId).build(); + for (var recId = 0l; recId < aRecommenders; recId++) { + var feature = AnnotationFeature.builder().withId(recId).withName("feat" + recId) + .build(); + var rec = Recommender.builder().withId(recId).withName("rec" + recId) + .withLayer(layer).withFeature(feature).build(); for (int annId = 0; annId < aSuggestions; annId++) { var label = labels.get(rng.nextInt(labels.size())); var token = tokens.get(rng.nextInt(tokens.size())); var ann = SpanSuggestion.builder() // .withId(annId) // - .withDocumentName(docName) // - .withRecommenderName(recName) // - .withRecommenderId(recId) // - .withLayerId(layer.getId()) // + .withDocument(doc) // + .withRecommender(rec) // .withScore(rng.nextDouble()) // .withScoreExplanation(null) // .withLabel(label) // .withUiLabel(label) // - .withFeature(featName) // .withPosition(new Offset(token.getBegin(), token.getEnd())) // .withCoveredText(token.getCoveredText()) // .build(); diff --git a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestionTest.java b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestionTest.java index e21c1cb7ff5..bc8eeb1386b 100644 --- a/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestionTest.java +++ b/inception/inception-recommendation-api/src/test/java/de/tudarmstadt/ukp/inception/recommendation/api/model/SpanSuggestionTest.java @@ -21,25 +21,33 @@ import org.junit.jupiter.api.Test; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; +import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + class SpanSuggestionTest { @Test void thatCloningRetainsAllInformation() { + var layer = AnnotationLayer.builder().withId(5l).withName("layer").build(); + var feature = AnnotationFeature.builder().withId(6l).withName("feature").withLayer(layer) + .build(); + var rec = Recommender.builder().withId(4l).withName("rec").withLayer(layer) + .withFeature(feature).build(); + var doc = SourceDocument.builder().withId(8l).withName("doc").build(); + var s = SpanSuggestion.builder() // .withId(1) // .withGeneration(2) // .withAge(3) // - .withRecommenderId(4) // - .withRecommenderName("rec") // - .withLayerId(5) // - .withFeature("feature") // - .withDocumentName("document") // + .withRecommender(rec) // + .withDocument(doc) // .withLabel("label") // .withUiLabel("uiLabel") // .withScore(6.0) // .withScoreExplanation("scoreExplanation") // - .withPosition(new Offset(1, 2)) // + .withPosition(1, 2) // .withCoveredText("coveredText") // .withAutoAcceptMode(AutoAcceptMode.ON_FIRST_ACCESS) // .withHidingFlags(7) // diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java index f2c36486dd5..10869bfeb86 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java @@ -485,7 +485,7 @@ public static void extractSuggestion(ExtractionContext ctx, TOP predictedFS) .withId(RelationSuggestion.NEW_ID) // .withGeneration(ctx.getGeneration()) // .withRecommender(ctx.getRecommender()) // - .withDocumentName(ctx.getDocument().getName()) // + .withDocument(ctx.getDocument()) // .withPosition(offsets) // .withCoveredText(coveredText) // .withLabel(label) // diff --git a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/Fixtures.java b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/Fixtures.java index 56201f6b50a..5719102c648 100644 --- a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/Fixtures.java +++ b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/Fixtures.java @@ -17,17 +17,15 @@ */ package de.tudarmstadt.ukp.inception.recommendation.service; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AutoAcceptMode.NEVER; -import static java.util.stream.Collectors.toList; - import java.util.ArrayList; import java.util.Collection; import java.util.List; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; -import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion; +import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; +import de.tudarmstadt.ukp.inception.recommendation.api.model.RelationPosition; import de.tudarmstadt.ukp.inception.recommendation.api.model.RelationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionDocumentGroup; @@ -38,7 +36,6 @@ public class Fixtures // AnnotationSuggestion private final static long RECOMMENDER_ID = 1; private final static String RECOMMENDER_NAME = "TestEntityRecommender"; - private final static String UI_LABEL = "TestUiLabel"; private final static double CONFIDENCE = 0.2; private final static String CONFIDENCE_EXPLANATION = "Predictor A: 0.05 | Predictor B: 0.15"; private final static String COVERED_TEXT = "TestText"; @@ -49,7 +46,7 @@ public static List getInvisibleSuggestions( return aSuggestions.stream() // .flatMap(SuggestionGroup::stream) // .filter(s -> !s.isVisible()) // - .collect(toList()); + .toList(); } public static List getVisibleSuggestions( @@ -58,17 +55,21 @@ public static List getVisibleSuggestions( return aSuggestions.stream() // .flatMap(SuggestionGroup::stream) // .filter(s -> s.isVisible()) // - .collect(toList()); + .toList(); } public static SuggestionDocumentGroup makeSpanSuggestionGroup( SourceDocument doc, AnnotationFeature aFeat, int[][] vals) { + var rec = Recommender.builder().withId(RECOMMENDER_ID).withName(RECOMMENDER_NAME) + .withLayer(aFeat.getLayer()).withFeature(aFeat).build(); + List suggestions = new ArrayList<>(); for (int[] val : vals) { - suggestions.add(new SpanSuggestion(val[0], RECOMMENDER_ID, RECOMMENDER_NAME, - aFeat.getLayer().getId(), aFeat.getName(), doc.getName(), val[1], val[2], - COVERED_TEXT, null, UI_LABEL, CONFIDENCE, CONFIDENCE_EXPLANATION, NEVER)); + var suggestion = SpanSuggestion.builder().withId(val[0]).withRecommender(rec) + .withDocument(doc).withPosition(val[1], val[2]).withCoveredText(COVERED_TEXT) + .withScore(CONFIDENCE).withScoreExplanation(CONFIDENCE_EXPLANATION).build(); + suggestions.add(suggestion); } return new SuggestionDocumentGroup<>(suggestions); @@ -79,31 +80,15 @@ public static SuggestionDocumentGroup makeRelationSuggestion { List suggestions = new ArrayList<>(); for (int[] val : vals) { - suggestions.add(new RelationSuggestion(val[0], RECOMMENDER_ID, RECOMMENDER_NAME, - aFeat.getLayer().getId(), aFeat.getName(), doc.getName(), val[1], val[2], - val[3], val[4], null, UI_LABEL, CONFIDENCE, CONFIDENCE_EXPLANATION, NEVER)); + var suggestion = RelationSuggestion.builder().withId(val[0]) + .withRecommenderId(RECOMMENDER_ID).withRecommenderName(RECOMMENDER_NAME) + .withFeature(aFeat.getName()).withLayerId(aFeat.getLayer().getId()) + .withDocument(doc) + .withPosition(new RelationPosition(val[1], val[2], val[3], val[4])) + .withScore(CONFIDENCE).withScoreExplanation(CONFIDENCE_EXPLANATION).build(); + suggestions.add(suggestion); } return new SuggestionDocumentGroup<>(suggestions); } - - public static SpanSuggestion makeSuggestion(int aBegin, int aEnd, String aLabel, - SourceDocument aDoc, AnnotationLayer aLayer, AnnotationFeature aFeature) - { - return new SpanSuggestion(0, // aId, - 0, // aRecommenderId, - "", // aRecommenderName - aLayer.getId(), // aLayerId, - aFeature.getName(), // aFeature, - aDoc.getName(), // aDocumentName - aBegin, // aBegin - aEnd, // aEnd - "", // aCoveredText, - aLabel, // aLabel - aLabel, // aUiLabel - 0.0, // aScore - "", // aScoreExplanation, - NEVER // autoAccept - ); - } } diff --git a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplIntegrationTest.java b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplIntegrationTest.java index 9609e383c55..bcafa0d907b 100644 --- a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplIntegrationTest.java +++ b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplIntegrationTest.java @@ -354,21 +354,19 @@ public void thatSpanSuggestionsCanBeRecorded() var sourceDoc = createSourceDocument("doc"); var layer = createAnnotationLayer("layer"); var feature = createAnnotationFeature(layer, FEATURE_NAME); + var rec = Recommender.builder().withId(1337l).withName("testRecommender").withLayer(layer) + .withFeature(feature).build(); var suggestion = SpanSuggestion.builder() // .withId(42) // - .withRecommenderId(1337) // - .withRecommenderName("testRecommender") // - .withLayerId(layer.getId()) // - .withFeature(feature.getName()) // - .withDocumentName(sourceDoc.getName()) // - .withPosition(new Offset(7, 14)) // + .withRecommender(rec) // + .withDocument(sourceDoc) // + .withPosition(7, 14) // .withCoveredText("aCoveredText") // .withLabel("testLabel") // .withUiLabel("testUiLabel") // .withScore(0.42) // .withScoreExplanation("Test confidence") // - .withAutoAcceptMode(NEVER) // .build(); sut.logRecord(USER_NAME, sourceDoc, USER_NAME, suggestion, feature, ACCEPTED, MAIN_EDITOR); @@ -437,28 +435,34 @@ void thatListingRecordsForRendering() var feature1 = createAnnotationFeature(layer1, "feat1"); var feature2 = createAnnotationFeature(layer2, "feat1"); + var rec1 = Recommender.builder().withId(1337l).withName("testRecommender").withLayer(layer1) + .withFeature(feature1).build(); + var rec2 = Recommender.builder().withId(1337l).withName("testRecommender2") + .withLayer(layer2).withFeature(feature2).build(); + + Offset position = new Offset(7, 14); sut.logRecord(USER_NAME, sourceDoc1, USER_NAME, - new SpanSuggestion(42, 1337, "testRecommender", layer1.getId(), feature1.getName(), - sourceDoc1.getName(), 7, 14, "aCoveredText", "testLabel", "testUiLabel", - 0.42, "Test confidence", NEVER), + SpanSuggestion.builder().withRecommender(rec1).withDocument(sourceDoc1) + .withPosition(position).withLabel("testLabel") + .withCoveredText("aCoveredText").build(), feature1, ACCEPTED, MAIN_EDITOR); sut.logRecord(USER_NAME, sourceDoc1, USER_NAME, - new SpanSuggestion(42, 1337, "testRecommender2", layer2.getId(), feature2.getName(), - sourceDoc1.getName(), 7, 14, "aCoveredText", "testLabel", "testUiLabel", - 0.42, "Test confidence", NEVER), + SpanSuggestion.builder().withRecommender(rec2).withDocument(sourceDoc1) + .withPosition(position).withLabel("testLabel") + .withCoveredText("aCoveredText").build(), feature2, ACCEPTED, MAIN_EDITOR); sut.logRecord(USER_NAME, sourceDoc2, USER_NAME, - new SpanSuggestion(42, 1337, "testRecommender", layer1.getId(), feature1.getName(), - sourceDoc2.getName(), 7, 14, "aCoveredText", "testLabel", "testUiLabel", - 0.42, "Test confidence", NEVER), + SpanSuggestion.builder().withRecommender(rec1).withDocument(sourceDoc1) + .withPosition(position).withLabel("testLabel") + .withCoveredText("aCoveredText").build(), feature1, ACCEPTED, MAIN_EDITOR); sut.logRecord(USER_NAME, sourceDoc2, USER_NAME, - new SpanSuggestion(42, 1337, "testRecommender2", layer2.getId(), feature2.getName(), - sourceDoc2.getName(), 7, 14, "aCoveredText", "testLabel", "testUiLabel", - 0.42, "Test confidence", NEVER), + SpanSuggestion.builder().withRecommender(rec2).withDocument(sourceDoc1) + .withPosition(position).withLabel("testLabel") + .withCoveredText("aCoveredText").build(), feature2, ACCEPTED, MAIN_EDITOR); assertThat(sut.listLearningRecords(USER_NAME, sourceDoc1, USER_NAME, feature1)).hasSize(1); @@ -473,9 +477,7 @@ void thatListingRecordsForRendering() private SourceDocument createSourceDocument(String aName) { - var doc = new SourceDocument(); - doc.setProject(project); - doc.setName(aName); + var doc = SourceDocument.builder().withProject(project).withName(aName).build(); return testEntityManager.persist(doc); } diff --git a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplTest.java b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplTest.java index f4c65e5a99a..e8132f4ec91 100644 --- a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplTest.java +++ b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/service/RecommendationServiceImplTest.java @@ -90,15 +90,15 @@ void testReconciliation() throws Exception var existingSuggestions = Arrays. asList( // SpanSuggestion.builder() // .withId(0) // - .withPosition(new Offset(0, 10)) // - .withDocumentName(doc.getName()) // + .withPosition(0, 10) // + .withDocument(doc) // .withLabel("aged") // .withRecommender(rec) // .build(), SpanSuggestion.builder() // .withId(1) // - .withPosition(new Offset(0, 10)) // - .withDocumentName(doc.getName()) // + .withPosition(0, 10) // + .withDocument(doc) // .withLabel("removed") // .withRecommender(rec) // .build()); @@ -108,15 +108,15 @@ void testReconciliation() throws Exception var newSuggestions = Arrays. asList( // SpanSuggestion.builder() // .withId(2) // - .withPosition(new Offset(0, 10)) // - .withDocumentName(doc.getName()) // + .withPosition(0, 10) // + .withDocument(doc) // .withLabel("aged") // .withRecommender(rec) // .build(), SpanSuggestion.builder() // .withId(3) // .withPosition(new Offset(0, 10)) // - .withDocumentName(doc.getName()) // + .withDocument(doc) // .withLabel("added") // .withRecommender(rec) // .build()); diff --git a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionVisibilityCalculationTest.java b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionVisibilityCalculationTest.java index 3f8f367c3fe..1d4ca843425 100644 --- a/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionVisibilityCalculationTest.java +++ b/inception/inception-recommendation/src/test/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionVisibilityCalculationTest.java @@ -22,9 +22,9 @@ import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.getInvisibleSuggestions; import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.getVisibleSuggestions; import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.makeSpanSuggestionGroup; -import static de.tudarmstadt.ukp.inception.recommendation.service.Fixtures.makeSuggestion; import static de.tudarmstadt.ukp.inception.recommendation.span.SpanSuggestionSupport.hideSuggestionsRejectedOrSkipped; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; import static org.assertj.core.api.Assertions.assertThat; @@ -52,7 +52,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecord; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction; -import de.tudarmstadt.ukp.inception.recommendation.api.model.Offset; +import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionDocumentGroup; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; @@ -212,28 +212,28 @@ public void thatVisibilityIsRestoredWhenOverlappingAnnotationIsRemoved() throws @Test public void thatOverlappingSuggestionsAreNotHiddenWhenStackingIsEnabled() throws Exception { - doReturn(new ArrayList<>()).when(learningRecordService).listLearningRecords(TEST_USER, - TEST_USER, layer); + doReturn(emptyList()).when(learningRecordService).listLearningRecords(TEST_USER, TEST_USER, + layer); layer.setOverlapMode(OverlapMode.ANY_OVERLAP); + var rec = Recommender.builder().withId(123l).withName("rec").withLayer(layer) + .withFeature(feature).build(); var cas = JCasFactory.createText("a b", "de"); var suggestion1 = SpanSuggestion.builder() // .withId(1) // - .withDocumentName(doc.getName()) // - .withLayerId(layer.getId()) // - .withFeature(NamedEntity._FeatName_value) // + .withDocument(doc) // + .withRecommender(rec) // .withLabel("blah") // - .withPosition(new Offset(0, 1)) // + .withPosition(0, 1) // .build(); var suggestion2 = SpanSuggestion.builder() // .withId(2) // - .withDocumentName(doc.getName()) // - .withLayerId(layer.getId()) // - .withFeature(NamedEntity._FeatName_value) // + .withDocument(doc) // + .withRecommender(rec) // .withLabel("blah") // - .withPosition(new Offset(1, 2)) // + .withPosition(1, 2) // .build(); var suggestions = new SuggestionDocumentGroup<>(asList(suggestion1, suggestion2)); @@ -278,17 +278,23 @@ public void thatOverlappingSuggestionsAreNotHiddenWhenStackingIsEnabled() throws @Test void thatRejectedSuggestionIsHidden() { + var rec1 = Recommender.builder().withId(1l).withLayer(layer).withFeature(feature).build(); + var rec2 = Recommender.builder().withId(1l).withLayer(layer2).withFeature(feature).build(); + var rec3 = Recommender.builder().withId(1l).withLayer(layer).withFeature(feature2).build(); + var label = "x"; + var records = asList(LearningRecord.builder() // .withSourceDocument(doc) // .withLayer(layer) // .withAnnotationFeature(feature) // .withOffsetBegin(0) // .withOffsetEnd(10) // - .withAnnotation("x") // + .withAnnotation(label) // .withUserAction(REJECTED) // .build()); - var docSuggestion = makeSuggestion(0, 10, "x", doc, layer, feature); + var docSuggestion = SpanSuggestion.builder().withRecommender(rec1).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); assertThat(docSuggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(docSuggestion, records); assertThat(docSuggestion.isVisible()) // @@ -296,21 +302,24 @@ void thatRejectedSuggestionIsHidden() .isFalse(); assertThat(docSuggestion.getReasonForHiding().trim()).isEqualTo("rejected"); - var doc2Suggestion = makeSuggestion(0, 10, "x", doc2, layer, feature); + var doc2Suggestion = SpanSuggestion.builder().withRecommender(rec1).withDocument(doc2) + .withLabel(label).withPosition(0, 10).build(); assertThat(doc2Suggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(doc2Suggestion, records); assertThat(doc2Suggestion.isVisible()) // .as("Suggestion in other document should not be hidden") // .isTrue(); - var doc3Suggestion = makeSuggestion(0, 10, "x", doc, layer2, feature); + var doc3Suggestion = SpanSuggestion.builder().withRecommender(rec2).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); assertThat(doc3Suggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(doc3Suggestion, records); assertThat(doc3Suggestion.isVisible()) // .as("Suggestion in other layer should not be hidden") // .isTrue(); - var doc4Suggestion = makeSuggestion(0, 10, "x", doc, layer, feature2); + var doc4Suggestion = SpanSuggestion.builder().withRecommender(rec3).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); assertThat(doc4Suggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(doc3Suggestion, records); assertThat(doc4Suggestion.isVisible()) // @@ -321,17 +330,23 @@ void thatRejectedSuggestionIsHidden() @Test void thatSkippedSuggestionIsHidden() { + var rec1 = Recommender.builder().withId(1l).withLayer(layer).withFeature(feature).build(); + var rec2 = Recommender.builder().withId(1l).withLayer(layer2).withFeature(feature).build(); + var rec3 = Recommender.builder().withId(1l).withLayer(layer).withFeature(feature2).build(); + var label = "x"; + var records = asList(LearningRecord.builder() // .withSourceDocument(doc) // .withLayer(layer) // .withAnnotationFeature(feature) // .withOffsetBegin(0) // .withOffsetEnd(10) // - .withAnnotation("x") // + .withAnnotation(label) // .withUserAction(SKIPPED) // .build()); - var docSuggestion = makeSuggestion(0, 10, "x", doc, layer, feature); + var docSuggestion = SpanSuggestion.builder().withRecommender(rec1).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); assertThat(docSuggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(docSuggestion, records); assertThat(docSuggestion.isVisible()) // @@ -339,21 +354,23 @@ void thatSkippedSuggestionIsHidden() .isFalse(); assertThat(docSuggestion.getReasonForHiding().trim()).isEqualTo("skipped"); - var doc2Suggestion = makeSuggestion(0, 10, "x", doc2, layer, feature); + var doc2Suggestion = SpanSuggestion.builder().withRecommender(rec1).withDocument(doc2) + .withLabel(label).withPosition(0, 10).build(); assertThat(doc2Suggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(doc2Suggestion, records); assertThat(doc2Suggestion.isVisible()) // .as("Suggestion in other document should not be hidden") // .isTrue(); - var doc3Suggestion = makeSuggestion(0, 10, "x", doc, layer2, feature); - assertThat(doc3Suggestion.isVisible()).isTrue(); + var doc3Suggestion = SpanSuggestion.builder().withRecommender(rec2).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); hideSuggestionsRejectedOrSkipped(doc3Suggestion, records); assertThat(doc3Suggestion.isVisible()) // .as("Suggestion in other layer should not be hidden") // .isTrue(); - var doc4Suggestion = makeSuggestion(0, 10, "x", doc, layer, feature2); + var doc4Suggestion = SpanSuggestion.builder().withRecommender(rec3).withDocument(doc) + .withLabel(label).withPosition(0, 10).build(); assertThat(doc4Suggestion.isVisible()).isTrue(); hideSuggestionsRejectedOrSkipped(doc3Suggestion, records); assertThat(doc4Suggestion.isVisible()) //