diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java index c5a3a36e..49e01176 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java @@ -299,6 +299,30 @@ public class ComponentCreationService { } + /** + * Computes the number of rows in table with values in the collection of entities and creates a component with the result. + * + * @param ruleIdentifier the identifier of the rule + * @param name the name of the record + * @param entities the collection of entities to count row values from + */ + public void rowValueCount(String ruleIdentifier, String name, Collection entities) { + + entities.stream().collect(Collectors.groupingBy(this::getFirstTable)).forEach((optionalTable, groupedEntities) -> { + + long count = groupedEntities.stream() + .filter(entity -> entity.getContainingNode() instanceof TableCell) + .collect(Collectors.groupingBy(entity -> ((TableCell) entity.getContainingNode()).getRow())) + .entrySet() + .stream() + .sorted(Comparator.comparingInt(Map.Entry::getKey)) + .map(Map.Entry::getValue) + .count(); + create(ruleIdentifier, name, String.valueOf(count), "Count rows with values in the entity references in same table", entities); + }); + } + + /** * Creates a component for each sentence in the collection of entities. *