diff --git a/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/sidebar/MetadataSuggestionSupport.java b/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/sidebar/MetadataSuggestionSupport.java index c15e30476f9..5175775f7a6 100644 --- a/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/sidebar/MetadataSuggestionSupport.java +++ b/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/sidebar/MetadataSuggestionSupport.java @@ -292,7 +292,7 @@ public static void extractSuggestion(ExtractionContext ctx, TOP predictedFS) .withId(MetadataSuggestion.NEW_ID) // .withGeneration(ctx.getGeneration()) // .withRecommender(ctx.getRecommender()) // - .withDocumentName(ctx.getDocument().getName()) // + .withDocument(ctx.getDocument()) // .withLabel(label) // .withUiLabel(label) // .withScore(score) // diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/MetadataSuggestion.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/MetadataSuggestion.java index 7bc98f300cc..90219ba92df 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/MetadataSuggestion.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/model/MetadataSuggestion.java @@ -19,6 +19,8 @@ import java.io.Serializable; +import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; + public class MetadataSuggestion extends AnnotationSuggestion implements Serializable @@ -129,31 +131,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; 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 46c1d0bffda..bf4602f917d 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 @@ -41,21 +41,6 @@ private RelationSuggestion(Builder builder) this.position = builder.position; } - /** - * @deprecated Use builder instead - */ - @Deprecated - public RelationSuggestion(int aId, long aRecommenderId, String aRecommenderName, long aLayerId, - String aFeature, String aDocumentName, int aSourceBegin, int aSourceEnd, - int aTargetBegin, int aTargetEnd, 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 RelationPosition(aSourceBegin, aSourceEnd, aTargetBegin, aTargetEnd); - } - // Getter and setter @Override @@ -184,25 +169,29 @@ 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; @@ -268,5 +257,4 @@ public RelationSuggestion build() return new RelationSuggestion(this); } } - } 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 5719102c648..c1be4b712cd 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 @@ -78,11 +78,12 @@ public static SuggestionDocumentGroup makeSpanSuggestionGroup( public static SuggestionDocumentGroup makeRelationSuggestionGroup( 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) { - var suggestion = RelationSuggestion.builder().withId(val[0]) - .withRecommenderId(RECOMMENDER_ID).withRecommenderName(RECOMMENDER_NAME) - .withFeature(aFeat.getName()).withLayerId(aFeat.getLayer().getId()) + var suggestion = RelationSuggestion.builder().withId(val[0]).withRecommender(rec) .withDocument(doc) .withPosition(new RelationPosition(val[1], val[2], val[3], val[4])) .withScore(CONFIDENCE).withScoreExplanation(CONFIDENCE_EXPLANATION).build(); 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 bcafa0d907b..8cdba07b2d5 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 @@ -23,7 +23,6 @@ import static de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService.FEATURE_NAME_IS_PREDICTION; import static de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService.FEATURE_NAME_SCORE_EXPLANATION_SUFFIX; import static de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService.FEATURE_NAME_SCORE_SUFFIX; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AutoAcceptMode.NEVER; import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordChangeLocation.DETAIL_EDITOR; import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordChangeLocation.MAIN_EDITOR; import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.ACCEPTED; @@ -73,6 +72,7 @@ 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.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.recommender.RecommendationEngineFactory; @@ -397,10 +397,13 @@ public void thatRelationSuggestionsCanBeRecorded() 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 = new RelationSuggestion(42, 1337, "testRecommender", layer.getId(), - feature.getName(), sourceDoc.getName(), 7, 14, 21, 28, "testLabel", "testUiLabel", - 0.42, "Test confidence", NEVER); + var suggestion = RelationSuggestion.builder().withId(42).withRecommender(rec) + .withDocument(sourceDoc).withPosition(new RelationPosition(7, 14, 21, 28)) + .withLabel("testLabel").withUiLabel("testUiLabel").withScore(0.42) + .withScoreExplanation("Test confidence").build(); sut.logRecord(USER_NAME, sourceDoc, USER_NAME, suggestion, feature, LearningRecordUserAction.REJECTED, DETAIL_EDITOR);