RED-10200: Spike performant rules update logic
This commit is contained in:
parent
104496c3cc
commit
3a9bd3958e
@ -10,18 +10,18 @@ import com.iqser.red.service.redaction.v1.server.model.document.nodes.Page;
|
|||||||
import com.iqser.red.service.redaction.v1.server.model.document.nodes.SemanticNode;
|
import com.iqser.red.service.redaction.v1.server.model.document.nodes.SemanticNode;
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.textblock.TextBlock;
|
import com.iqser.red.service.redaction.v1.server.model.document.textblock.TextBlock;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
public final class EntityCreationUtility {
|
||||||
|
|
||||||
@UtilityClass
|
private EntityCreationUtility() {throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");}
|
||||||
public class EntityCreationUtility {
|
|
||||||
|
|
||||||
public void checkIfBothStartAndEndAreEmpty(String start, String end) {
|
|
||||||
|
public static void checkIfBothStartAndEndAreEmpty(String start, String end) {
|
||||||
|
|
||||||
checkIfBothStartAndEndAreEmpty(List.of(start), List.of(end));
|
checkIfBothStartAndEndAreEmpty(List.of(start), List.of(end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public <T> void checkIfBothStartAndEndAreEmpty(List<T> start, List<T> end) {
|
public static <T> void checkIfBothStartAndEndAreEmpty(List<T> start, List<T> end) {
|
||||||
|
|
||||||
if ((start == null || start.isEmpty()) && (end == null || end.isEmpty())) {
|
if ((start == null || start.isEmpty()) && (end == null || end.isEmpty())) {
|
||||||
throw new IllegalArgumentException("Start and end values are empty!");
|
throw new IllegalArgumentException("Start and end values are empty!");
|
||||||
@ -29,7 +29,7 @@ public class EntityCreationUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int truncateEndIfLineBreakIsBetween(int end, int expandedEnd, TextBlock textBlock) {
|
public static int truncateEndIfLineBreakIsBetween(int end, int expandedEnd, TextBlock textBlock) {
|
||||||
|
|
||||||
if (textBlock.getNextLinebreak(end) < expandedEnd) {
|
if (textBlock.getNextLinebreak(end) < expandedEnd) {
|
||||||
return end;
|
return end;
|
||||||
@ -38,7 +38,7 @@ public class EntityCreationUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<SemanticNode> findIntersectingSubNodes(SemanticNode initialIntersectingNode, TextRange textRange) {
|
public static Set<SemanticNode> findIntersectingSubNodes(SemanticNode initialIntersectingNode, TextRange textRange) {
|
||||||
|
|
||||||
IntersectingNodeVisitor visitor = new IntersectingNodeVisitor(textRange);
|
IntersectingNodeVisitor visitor = new IntersectingNodeVisitor(textRange);
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class EntityCreationUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addToPages(TextEntity entity) {
|
public static void addToPages(TextEntity entity) {
|
||||||
|
|
||||||
Set<Page> pages = entity.getDeepestFullyContainingNode().getPages(entity.getTextRange());
|
Set<Page> pages = entity.getDeepestFullyContainingNode().getPages(entity.getTextRange());
|
||||||
entity.getPages().addAll(pages);
|
entity.getPages().addAll(pages);
|
||||||
@ -58,14 +58,14 @@ public class EntityCreationUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addEntityToNodeEntitySets(TextEntity entity) {
|
public static void addEntityToNodeEntitySets(TextEntity entity) {
|
||||||
|
|
||||||
entity.getIntersectingNodes()
|
entity.getIntersectingNodes()
|
||||||
.forEach(node -> node.getEntities().add(entity));
|
.forEach(node -> node.getEntities().add(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean allEntitiesIntersectAndHaveSameTypes(List<TextEntity> entitiesToMerge) {
|
public static boolean allEntitiesIntersectAndHaveSameTypes(List<TextEntity> entitiesToMerge) {
|
||||||
|
|
||||||
if (entitiesToMerge.isEmpty()) {
|
if (entitiesToMerge.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
@ -83,7 +83,7 @@ public class EntityCreationUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TextRange toLineAfterTextRange(TextBlock textBlock, TextRange textRange) {
|
public static TextRange toLineAfterTextRange(TextBlock textBlock, TextRange textRange) {
|
||||||
|
|
||||||
if (textBlock.getTextRange().end() == textRange.end()) {
|
if (textBlock.getTextRange().end() == textRange.end()) {
|
||||||
return new TextRange(textRange.end(), textRange.end());
|
return new TextRange(textRange.end(), textRange.end());
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.service.document;
|
package com.iqser.red.service.redaction.v1.server.service.document;
|
||||||
|
|
||||||
import static com.iqser.red.service.redaction.v1.server.service.document.EntityCreationUtility.allEntitiesIntersectAndHaveSameTypes;
|
import static com.iqser.red.service.redaction.v1.server.utils.EntityCreationUtility.*;
|
||||||
import static com.iqser.red.service.redaction.v1.server.service.document.EntityCreationUtility.checkIfBothStartAndEndAreEmpty;
|
|
||||||
import static com.iqser.red.service.redaction.v1.server.service.document.EntityCreationUtility.findIntersectingSubNodes;
|
|
||||||
import static com.iqser.red.service.redaction.v1.server.service.document.EntityCreationUtility.toLineAfterTextRange;
|
|
||||||
import static com.iqser.red.service.redaction.v1.server.service.document.EntityCreationUtility.truncateEndIfLineBreakIsBetween;
|
|
||||||
import static com.iqser.red.service.redaction.v1.server.utils.SeparatorUtils.boundaryIsSurroundedBySeparators;
|
import static com.iqser.red.service.redaction.v1.server.utils.SeparatorUtils.boundaryIsSurroundedBySeparators;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -47,7 +43,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class EntityCreationService {
|
public class EntityCreationService {
|
||||||
|
|
||||||
KieSessionUpdater kieSessionUpdater = null;
|
KieSessionUpdater kieSessionUpdater;
|
||||||
|
|
||||||
|
|
||||||
public EntityCreationService(KieSessionUpdater kieSessionUpdater) {
|
public EntityCreationService(KieSessionUpdater kieSessionUpdater) {
|
||||||
|
|||||||
@ -1,94 +0,0 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.service.document;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.TextRange;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.entity.TextEntity;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.nodes.Page;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.nodes.SemanticNode;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.model.document.textblock.TextBlock;
|
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class EntityCreationUtility {
|
|
||||||
|
|
||||||
public void checkIfBothStartAndEndAreEmpty(String start, String end) {
|
|
||||||
|
|
||||||
checkIfBothStartAndEndAreEmpty(List.of(start), List.of(end));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public <T> void checkIfBothStartAndEndAreEmpty(List<T> start, List<T> end) {
|
|
||||||
|
|
||||||
if ((start == null || start.isEmpty()) && (end == null || end.isEmpty())) {
|
|
||||||
throw new IllegalArgumentException("Start and end values are empty!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int truncateEndIfLineBreakIsBetween(int end, int expandedEnd, TextBlock textBlock) {
|
|
||||||
|
|
||||||
if (textBlock.getNextLinebreak(end) < expandedEnd) {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
return expandedEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Set<SemanticNode> findIntersectingSubNodes(SemanticNode initialIntersectingNode, TextRange textRange) {
|
|
||||||
|
|
||||||
IntersectingNodeVisitor visitor = new IntersectingNodeVisitor(textRange);
|
|
||||||
|
|
||||||
if (initialIntersectingNode.getTextRange().intersects(textRange)) {
|
|
||||||
initialIntersectingNode.accept(visitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return visitor.getIntersectingNodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addToPages(TextEntity entity) {
|
|
||||||
|
|
||||||
Set<Page> pages = entity.getDeepestFullyContainingNode().getPages(entity.getTextRange());
|
|
||||||
entity.getPages().addAll(pages);
|
|
||||||
pages.forEach(page -> page.getEntities().add(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addEntityToNodeEntitySets(TextEntity entity) {
|
|
||||||
|
|
||||||
entity.getIntersectingNodes()
|
|
||||||
.forEach(node -> node.getEntities().add(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean allEntitiesIntersectAndHaveSameTypes(List<TextEntity> entitiesToMerge) {
|
|
||||||
|
|
||||||
if (entitiesToMerge.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TextEntity previousEntity = entitiesToMerge.get(0);
|
|
||||||
for (TextEntity textEntity : entitiesToMerge.subList(1, entitiesToMerge.size())) {
|
|
||||||
boolean typeMatches = textEntity.type().equals(previousEntity.type());
|
|
||||||
boolean entityTypeMatches = textEntity.getEntityType().equals(previousEntity.getEntityType());
|
|
||||||
boolean intersects = textEntity.intersects(previousEntity);
|
|
||||||
if (!typeMatches || !entityTypeMatches || !intersects) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public TextRange toLineAfterTextRange(TextBlock textBlock, TextRange textRange) {
|
|
||||||
|
|
||||||
if (textBlock.getTextRange().end() == textRange.end()) {
|
|
||||||
return new TextRange(textRange.end(), textRange.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TextRange(textRange.end(), textBlock.getNextLinebreak(textRange.end())).trim(textBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user