/** * Categorizes the given text. * * @param text the text to categorize */ @Override public double[] categorize(String[] text) { return this.categorize(text, Collections.emptyMap()); }
/** * Returns a map with the score as a key in ascending order. * The value is a Set of categories with the score. * Many categories can have the same score, hence the Set as value * * @param text the input text to classify * @return the sorted score map */ @Override public SortedMap<Double, Set<String>> sortedScoreMap(String[] text) { SortedMap<Double, Set<String>> descendingMap = new TreeMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); double score = categorize[getIndex(category)]; if (descendingMap.containsKey(score)) { descendingMap.get(score).add(category); } else { Set<String> newset = new HashSet<>(); newset.add(category); descendingMap.put(score, newset); } } return descendingMap; }
/** * Returns a map in which the key is the category name and the value is the score * * @param text the input text to classify * @return the score map */ @Override public Map<String, Double> scoreMap(String[] text) { Map<String, Double> probDist = new HashMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); probDist.put(category, categorize[getIndex(category)]); } return probDist; }
/** * Categorizes the given text. * * @param text the text to categorize */ @Override public double[] categorize(String[] text) { return this.categorize(text, Collections.emptyMap()); }
/** * Categorizes the given text. * * @param text the text to categorize */ @Override public double[] categorize(String[] text) { return this.categorize(text, Collections.emptyMap()); }
String[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(document); double[] prob = documentCategorizerME.categorize(tokens); String category = documentCategorizerME.getBestCategory(prob);
/** * Returns a map in which the key is the category name and the value is the score * * @param text the input text to classify * @return the score map */ @Override public Map<String, Double> scoreMap(String[] text) { Map<String, Double> probDist = new HashMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); probDist.put(category, categorize[getIndex(category)]); } return probDist; }
/** * Returns a map with the score as a key in ascending order. * The value is a Set of categories with the score. * Many categories can have the same score, hence the Set as value * * @param text the input text to classify * @return the sorted score map */ @Override public SortedMap<Double, Set<String>> sortedScoreMap(String[] text) { SortedMap<Double, Set<String>> descendingMap = new TreeMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); double score = categorize[getIndex(category)]; if (descendingMap.containsKey(score)) { descendingMap.get(score).add(category); } else { Set<String> newset = new HashSet<>(); newset.add(category); descendingMap.put(score, newset); } } return descendingMap; }
/** * Returns a map with the score as a key in ascending order. * The value is a Set of categories with the score. * Many categories can have the same score, hence the Set as value * * @param text the input text to classify * @return the sorted score map */ @Override public SortedMap<Double, Set<String>> sortedScoreMap(String[] text) { SortedMap<Double, Set<String>> descendingMap = new TreeMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); double score = categorize[getIndex(category)]; if (descendingMap.containsKey(score)) { descendingMap.get(score).add(category); } else { Set<String> newset = new HashSet<>(); newset.add(category); descendingMap.put(score, newset); } } return descendingMap; }
/** * Returns a map in which the key is the category name and the value is the score * * @param text the input text to classify * @return the score map */ @Override public Map<String, Double> scoreMap(String[] text) { Map<String, Double> probDist = new HashMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { String category = getCategory(i); probDist.put(category, categorize[getIndex(category)]); } return probDist; }
init(); double[] categorize = documentCategorizerME.categorize(text); int catSize = documentCategorizerME.getNumberOfCategories(); for (int i = 0; i < catSize; i++) {
double[] outcome = categorizer.categorize(tokenizer.tokenize(s)); System.out.print("{ action: '" + categorizer.getBestCategory(outcome) + "', args: { ");
@Override public void predict(RecommenderContext aContext, CAS aCas) throws RecommendationException { DoccatModel model = aContext.get(KEY_MODEL).orElseThrow(() -> new RecommendationException("Key [" + KEY_MODEL + "] not found in context")); DocumentCategorizerME finder = new DocumentCategorizerME(model); Type sentenceType = getType(aCas, Sentence.class); Type predictionType = getAnnotationType(aCas, PredictedSpan.class); Type tokenType = getType(aCas, Token.class); Feature confidenceFeature = predictionType.getFeatureByBaseName("score"); Feature labelFeature = predictionType.getFeatureByBaseName("label"); for (AnnotationFS sentence : select(aCas, sentenceType)) { List<AnnotationFS> tokenAnnotations = selectCovered(tokenType, sentence); String[] tokens = tokenAnnotations.stream() .map(AnnotationFS::getCoveredText) .toArray(String[]::new); double[] outcome = finder.categorize(tokens); String label = finder.getBestCategory(outcome); AnnotationFS annotation = aCas.createAnnotation(predictionType, sentence.getBegin(), sentence.getEnd()); annotation.setDoubleValue(confidenceFeature, NumberUtils.max(outcome)); annotation.setStringValue(labelFeature, label); aCas.addFsToIndexes(annotation); } }
String[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(document); double[] prob = documentCategorizerME.categorize(tokens); String category = documentCategorizerME.getBestCategory(prob);
String[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(document); double[] prob = documentCategorizerME.categorize(tokens); String category = documentCategorizerME.getBestCategory(prob);