diff --git a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java index d356f463684..0dd36ae367e 100644 --- a/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java +++ b/inception/inception-imls-ollama/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/ollama/OllamaRecommender.java @@ -49,6 +49,7 @@ import de.tudarmstadt.ukp.inception.recommendation.imls.ollama.response.ResponseAsLabelExtractor; import de.tudarmstadt.ukp.inception.recommendation.imls.ollama.response.ResponseExtractor; import de.tudarmstadt.ukp.inception.rendering.model.Range; +import de.tudarmstadt.ukp.inception.support.logging.LogMessage; public class OllamaRecommender extends NonTrainableRecommenderEngineImplBase @@ -103,8 +104,9 @@ public Range predict(PredictionContext aContext, CAS aCas, int aBegin, int aEnd) responseExtractor.extract(this, aCas, promptContext, response); } catch (IOException e) { - aContext.error("Ollama [%s] failed to respond: %s", traits.getModel(), - ExceptionUtils.getRootCauseMessage(e)); + aContext.log(LogMessage.warn(getRecommender().getName(), + "Ollama [%s] failed to respond: %s", traits.getModel(), + ExceptionUtils.getRootCauseMessage(e))); LOG.error("Ollama [{}] failed to respond: {}", traits.getModel(), ExceptionUtils.getRootCauseMessage(e)); } diff --git a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/doccat/OpenNlpDoccatRecommender.java b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/doccat/OpenNlpDoccatRecommender.java index 115b1180055..f8ee25f0058 100644 --- a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/doccat/OpenNlpDoccatRecommender.java +++ b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/doccat/OpenNlpDoccatRecommender.java @@ -56,6 +56,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability; import de.tudarmstadt.ukp.inception.rendering.model.Range; +import de.tudarmstadt.ukp.inception.support.logging.LogMessage; import opennlp.tools.doccat.DoccatFactory; import opennlp.tools.doccat.DoccatModel; import opennlp.tools.doccat.DocumentCategorizerME; @@ -108,13 +109,14 @@ public void train(RecommenderContext aContext, List aCasses) throws Recomme var docSamples = extractSamples(aCasses); if (docSamples.size() < 2) { - aContext.warn("Not enough training data: [%d] items", docSamples.size()); + aContext.log(LogMessage.warn(getRecommender().getName(), + "Not enough training data: [%d] items", docSamples.size())); return; } if (docSamples.stream().map(DocumentSample::getCategory).distinct().count() <= 1) { - aContext.warn("Training data requires at least two different labels", - docSamples.size()); + aContext.log(LogMessage.warn(getRecommender().getName(), + "Training data requires at least two different labels", docSamples.size())); return; } 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 8b20115d904..fc8f0a86be2 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 @@ -50,6 +50,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability; import de.tudarmstadt.ukp.inception.rendering.model.Range; +import de.tudarmstadt.ukp.inception.support.logging.LogMessage; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import opennlp.tools.ml.BeamSearch; @@ -95,7 +96,8 @@ public void train(RecommenderContext aContext, List aCasses) throws Recomme var nameSamples = extractNameSamples(aCasses); if (nameSamples.size() < 2) { - aContext.warn("Not enough training data: [%d] items", nameSamples.size()); + aContext.log(LogMessage.warn(getRecommender().getName(), + "Not enough training data: [%d] items", nameSamples.size())); return; } diff --git a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/pos/OpenNlpPosRecommender.java b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/pos/OpenNlpPosRecommender.java index 7a67d4d6552..db2af3c001c 100644 --- a/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/pos/OpenNlpPosRecommender.java +++ b/inception/inception-imls-opennlp/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/opennlp/pos/OpenNlpPosRecommender.java @@ -55,6 +55,7 @@ import de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommenderContext.Key; import de.tudarmstadt.ukp.inception.recommendation.api.recommender.TrainingCapability; import de.tudarmstadt.ukp.inception.rendering.model.Range; +import de.tudarmstadt.ukp.inception.support.logging.LogMessage; import opennlp.tools.ml.BeamSearch; import opennlp.tools.postag.POSModel; import opennlp.tools.postag.POSSample; @@ -97,7 +98,8 @@ public void train(RecommenderContext aContext, List aCasses) throws Recomme var posSamples = extractPosSamples(aCasses); if (posSamples.size() < 2) { - aContext.warn("Not enough training data: [%d] items", posSamples.size()); + aContext.log(LogMessage.warn(getRecommender().getName(), + "Not enough training data: [%d] items", posSamples.size())); return; } diff --git a/inception/inception-imls-stringmatch/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/stringmatch/span/StringMatchingRecommender.java b/inception/inception-imls-stringmatch/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/stringmatch/span/StringMatchingRecommender.java index 294a9b6d5e2..328979b37ab 100644 --- a/inception/inception-imls-stringmatch/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/stringmatch/span/StringMatchingRecommender.java +++ b/inception/inception-imls-stringmatch/src/main/java/de/tudarmstadt/ukp/inception/recommendation/imls/stringmatch/span/StringMatchingRecommender.java @@ -69,6 +69,7 @@ import de.tudarmstadt.ukp.inception.recommendation.imls.stringmatch.span.trie.Trie; import de.tudarmstadt.ukp.inception.recommendation.imls.stringmatch.span.trie.WhitespaceNormalizingSanitizer; import de.tudarmstadt.ukp.inception.rendering.model.Range; +import de.tudarmstadt.ukp.inception.support.logging.LogMessage; public class StringMatchingRecommender extends RecommendationEngine @@ -138,7 +139,9 @@ public void pretrain(List aData, RecommenderContext aContext) for (GazeteerEntry entry : aData) { learn(dict, entry.text, entry.label); } - aContext.info("Loaded [%d] entries from gazeteer", aData.size()); + + aContext.log(LogMessage.info(getRecommender().getName(), + "Loaded [%d] entries from gazeteer", aData.size())); } aContext.put(KEY_MODEL, dict); @@ -159,8 +162,8 @@ public void train(RecommenderContext aContext, List aCasses) throws Recomme pretrain(gazeteerService.readGazeteerFile(gaz), aContext); } catch (IOException e) { - aContext.error("Unable to load gazeteer [%s]: %s", gaz.getName(), - e.getMessage()); + aContext.log(LogMessage.error(getRecommender().getName(), + "Unable to load gazeteer [%s]: %s", gaz.getName(), e.getMessage())); log.error( "Unable to load gazeteer [{}] for recommender [{}]({}) in project [{}]({})", gaz.getName(), gaz.getRecommender().getName(), @@ -192,8 +195,9 @@ public void train(RecommenderContext aContext, List aCasses) throws Recomme } } - aContext.info("Learned dictionary model with %d entries on %d documents", dict.size(), - aCasses.size()); + aContext.log(LogMessage.info(getRecommender().getName(), + "Learned dictionary model with %d entries on %d documents", dict.size(), + aCasses.size())); aContext.put(KEY_MODEL, dict); } diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/PredictionContext.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/PredictionContext.java index 2020df9a604..c509be7da93 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/PredictionContext.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/PredictionContext.java @@ -44,31 +44,13 @@ synchronized public Optional get(Key aKey) return modelContext.get(aKey); } - synchronized public void info(String aFormat, Object... aValues) + synchronized public void log(LogMessage aMessage) { if (closed) { throw new IllegalStateException("Adding data to a closed context is not permitted."); } - messages.add(LogMessage.info(this, aFormat, aValues)); - } - - synchronized public void warn(String aFormat, Object... aValues) - { - if (closed) { - throw new IllegalStateException("Adding data to a closed context is not permitted."); - } - - messages.add(LogMessage.warn(this, aFormat, aValues)); - } - - synchronized public void error(String aFormat, Object... aValues) - { - if (closed) { - throw new IllegalStateException("Adding data to a closed context is not permitted."); - } - - messages.add(LogMessage.error(this, aFormat, aValues)); + messages.add(aMessage); } public List getMessages() diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/RecommenderContext.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/RecommenderContext.java index db159e58c5e..c86e048dcfd 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/RecommenderContext.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/recommender/RecommenderContext.java @@ -55,31 +55,13 @@ synchronized public void put(Key aKey, T aValue) store.put(aKey.name, aValue); } - synchronized public void info(String aFormat, Object... aValues) + synchronized public void log(LogMessage aMessage) { if (closed) { throw new IllegalStateException("Adding data to a closed context is not permitted."); } - messages.add(LogMessage.info(this, aFormat, aValues)); - } - - synchronized public void warn(String aFormat, Object... aValues) - { - if (closed) { - throw new IllegalStateException("Adding data to a closed context is not permitted."); - } - - messages.add(LogMessage.warn(this, aFormat, aValues)); - } - - synchronized public void error(String aFormat, Object... aValues) - { - if (closed) { - throw new IllegalStateException("Adding data to a closed context is not permitted."); - } - - messages.add(LogMessage.error(this, aFormat, aValues)); + messages.add(aMessage); } public List getMessages()