From 7a4ec0836e56de5091ae0c0315a3205132b13362 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Thu, 4 Apr 2024 00:05:29 +0200 Subject: [PATCH] #4525 - Support recommendations for non-string primitive features - Support boolean feature values in OpenNLP sequence classifier --- .../imls/opennlp/ner/OpenNlpNerRecommender.java | 2 +- .../ner/OpenNlpNerRecommenderFactory.java | 3 ++- .../opennlp/ner/OpenNlpNerRecommenderTest.java | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommender.java b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommender.java index 94dc189a44d..a7dcd1ce827 100644 --- a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommender.java +++ b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommender.java @@ -187,7 +187,7 @@ public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd) var end = tokens.get(prediction.getEnd() - 1).getEnd(); var annotation = aCas.createAnnotation(predictedType, begin, end); - annotation.setStringValue(predictedFeature, label); + annotation.setFeatureValueFromString(predictedFeature, label); if (scoreFeature != null) { annotation.setDoubleValue(scoreFeature, prediction.getProb()); } diff --git a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderFactory.java b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderFactory.java index 97b4307e828..77038bbf48a 100644 --- a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderFactory.java +++ b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderFactory.java @@ -70,7 +70,8 @@ public boolean accepts(AnnotationLayer aLayer, AnnotationFeature aFeature) return (asList(SINGLE_TOKEN, TOKENS, SENTENCES).contains(aLayer.getAnchoringMode())) && SpanLayerSupport.TYPE.equals(aLayer.getType()) - && (CAS.TYPE_NAME_STRING.equals(aFeature.getType()) || aFeature.isVirtualFeature()); + && (asList(CAS.TYPE_NAME_STRING, CAS.TYPE_NAME_BOOLEAN).contains(aFeature.getType()) + || aFeature.isVirtualFeature()); } @Override diff --git a/inception/inception-imls-opennlp/src/test/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderTest.java b/inception/inception-imls-opennlp/src/test/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderTest.java index f62a65df98b..99039e40c8a 100644 --- a/inception/inception-imls-opennlp/src/test/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderTest.java +++ b/inception/inception-imls-opennlp/src/test/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/ner/OpenNlpNerRecommenderTest.java @@ -215,10 +215,10 @@ public void thatEvaluationWorks() throws Exception var precision = result.computePrecisionScore(); var recall = result.computeRecallScore(); - System.out.printf("F1-Score: %f%n", fscore); - System.out.printf("Accuracy: %f%n", accuracy); - System.out.printf("Precision: %f%n", precision); - System.out.printf("Recall: %f%n", recall); + LOG.info("F1-Score: {}", fscore); + LOG.info("Accuracy: {}", accuracy); + LOG.info("Precision: {}", precision); + LOG.info("Recall: {}", recall); assertThat(fscore).isBetween(0.0, 1.0); assertThat(precision).isBetween(0.0, 1.0); @@ -243,10 +243,10 @@ public void thatEvaluationWorksNoLabels() throws Exception var precision = result.computePrecisionScore(); var recall = result.computeRecallScore(); - System.out.printf("F1-Score: %f%n", fscore); - System.out.printf("Accuracy: %f%n", accuracy); - System.out.printf("Precision: %f%n", precision); - System.out.printf("Recall: %f%n", recall); + LOG.info("F1-Score: {}", fscore); + LOG.info("Accuracy: {}", accuracy); + LOG.info("Precision: {}", precision); + LOG.info("Recall: {}", recall); assertThat(fscore).isBetween(0.0, 1.0); assertThat(precision).isBetween(0.0, 1.0);