Pull request #78: Fixed duplicate Textblock in Tables
Merge in RED/redaction-service from FixDuplicate to master * commit 'c90eee23c4f9f1fbc319cedb3c2aa8ce63a72101': Fixed duplicate Textblock in Tables
This commit is contained in:
commit
9b7deca3db
@ -30,12 +30,14 @@ public class TableExtractionService {
|
|||||||
|
|
||||||
List<Cell> cells = findCells(cleanRulings.getHorizontal(), cleanRulings.getVertical());
|
List<Cell> cells = findCells(cleanRulings.getHorizontal(), cleanRulings.getVertical());
|
||||||
|
|
||||||
|
List<TextBlock> toBeRemoved = new ArrayList<>();
|
||||||
|
|
||||||
for (AbstractTextContainer abstractTextContainer : page.getTextBlocks()) {
|
for (AbstractTextContainer abstractTextContainer : page.getTextBlocks()) {
|
||||||
TextBlock textBlock = (TextBlock) abstractTextContainer;
|
TextBlock textBlock = (TextBlock) abstractTextContainer;
|
||||||
for (Cell cell : cells) {
|
for (Cell cell : cells) {
|
||||||
if (cell.intersects(textBlock.getMinX(), textBlock.getMinY(), textBlock.getWidth(),
|
if (cell.intersects(textBlock.getMinX(), textBlock.getMinY(), textBlock.getWidth(), textBlock.getHeight())) {
|
||||||
textBlock.getHeight())) {
|
|
||||||
cell.addTextBlock(textBlock);
|
cell.addTextBlock(textBlock);
|
||||||
|
toBeRemoved.add(textBlock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +46,6 @@ public class TableExtractionService {
|
|||||||
cells = new ArrayList<>(new HashSet<>(cells));
|
cells = new ArrayList<>(new HashSet<>(cells));
|
||||||
Utils.sort(cells, Rectangle.ILL_DEFINED_ORDER);
|
Utils.sort(cells, Rectangle.ILL_DEFINED_ORDER);
|
||||||
|
|
||||||
|
|
||||||
List<Rectangle> spreadsheetAreas = findSpreadsheetsFromCells(cells).stream()
|
List<Rectangle> spreadsheetAreas = findSpreadsheetsFromCells(cells).stream()
|
||||||
.filter(r -> r.getWidth() > 0f && r.getHeight() > 0f)
|
.filter(r -> r.getWidth() > 0f && r.getHeight() > 0f)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -67,25 +68,23 @@ public class TableExtractionService {
|
|||||||
Iterator<AbstractTextContainer> itty = page.getTextBlocks().iterator();
|
Iterator<AbstractTextContainer> itty = page.getTextBlocks().iterator();
|
||||||
while (itty.hasNext()) {
|
while (itty.hasNext()) {
|
||||||
AbstractTextContainer textBlock = itty.next();
|
AbstractTextContainer textBlock = itty.next();
|
||||||
if (table.contains(textBlock)) {
|
if (table.contains(textBlock) && position == -1) {
|
||||||
if (position == -1) {
|
position = page.getTextBlocks().indexOf(textBlock);
|
||||||
position = page.getTextBlocks().indexOf(textBlock);
|
|
||||||
}
|
|
||||||
itty.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
page.getTextBlocks().add(position, table);
|
page.getTextBlocks().add(position, table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page.getTextBlocks().removeAll(toBeRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Cell> findCells(List<Ruling> horizontalRulingLines, List<Ruling> verticalRulingLines) {
|
public List<Cell> findCells(List<Ruling> horizontalRulingLines, List<Ruling> verticalRulingLines) {
|
||||||
|
|
||||||
List<Cell> cellsFound = new ArrayList<>();
|
List<Cell> cellsFound = new ArrayList<>();
|
||||||
Map<Point2D, Ruling[]> intersectionPoints = Ruling.findIntersections(horizontalRulingLines,
|
Map<Point2D, Ruling[]> intersectionPoints = Ruling.findIntersections(horizontalRulingLines, verticalRulingLines);
|
||||||
verticalRulingLines);
|
|
||||||
List<Point2D> intersectionPointsList = new ArrayList<>(intersectionPoints.keySet());
|
List<Point2D> intersectionPointsList = new ArrayList<>(intersectionPoints.keySet());
|
||||||
intersectionPointsList.sort(POINT_COMPARATOR);
|
intersectionPointsList.sort(POINT_COMPARATOR);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user