/** * TODO #176 use the document Id once it it available in the CAS * * Get the predictions of a document for a given window in a flattened list. * If the parameters {@code aWindowBegin} and {@code aWindowEnd} are {@code -1}, * then they are ignored respectively. This is useful when all suggestions should be fetched. */ private List<AnnotationSuggestion> getFlattenedPredictions(String aDocumentName, AnnotationLayer aLayer, int aWindowBegin, int aWindowEnd) { List<Map.Entry<ExtendedId, AnnotationSuggestion>> p = predictions.entrySet().stream() .filter(f -> f.getKey().getDocumentName().equals(aDocumentName)) .filter(f -> f.getKey().getLayerId() == aLayer.getId()) .filter(f -> aWindowBegin == -1 || (f.getKey().getBegin() >= aWindowBegin)) .filter(f -> aWindowEnd == -1 || (f.getKey().getEnd() <= aWindowEnd)) .sorted(Comparator.comparingInt(e2 -> e2.getValue().getBegin())) .collect(Collectors.toList()); return p.stream() .map(Map.Entry::getValue) .collect(Collectors.toList()); }
/** * TODO #176 use the document Id once it it available in the CAS * Returns a list of predictions for a given token that matches the given layer and * the annotation feature in the given document * * @param aDocumentName the given document name * @param aLayer the given layer * @param aBegin the offset character begin * @param aEnd the offset character end * @param aFeature the given annotation feature name * @return */ public List<AnnotationSuggestion> getPredictionsByTokenAndFeature(String aDocumentName, AnnotationLayer aLayer, int aBegin, int aEnd, String aFeature) { return predictions.entrySet().stream() .filter(f -> f.getKey().getDocumentName().equals(aDocumentName)) .filter(f -> f.getKey().getLayerId() == aLayer.getId()) .filter(f -> f.getKey().getOffset().getBeginCharacter() == aBegin) .filter(f -> f.getKey().getOffset().getEndCharacter() == aEnd) .filter(f -> f.getValue().getFeature().equals(aFeature)) .map(Map.Entry::getValue) .collect(Collectors.toList()); } }