@Test public void testConstantElementsNumber() throws TransformationException, IOException { for (String filename : TEST_FILENAMES) { BxDocument doc = getDocumentFromZip(filename); HierarchicalReadingOrderResolver roa = new HierarchicalReadingOrderResolver(); BxDocument orderedDoc = roa.resolve(doc); List<BxPage> pages1 = Lists.newArrayList(doc.asPages()); List<BxPage> pages2 = Lists.newArrayList(orderedDoc.asPages()); List<BxZone> zones1 = Lists.newArrayList(doc.asZones()); List<BxZone> zones2 = Lists.newArrayList(orderedDoc.asZones()); List<BxLine> lines1 = Lists.newArrayList(doc.asLines()); List<BxLine> lines2 = Lists.newArrayList(orderedDoc.asLines()); List<BxWord> words1 = Lists.newArrayList(doc.asWords()); List<BxWord> words2 = Lists.newArrayList(orderedDoc.asWords()); List<BxChunk> chunks1 = Lists.newArrayList(doc.asChunks()); List<BxChunk> chunks2 = Lists.newArrayList(orderedDoc.asChunks()); assertEquals(pages1.size(), pages2.size()); assertEquals(zones1.size(), zones2.size()); assertEquals(lines1.size(), lines2.size()); assertEquals(words1.size(), words2.size()); assertEquals(chunks1.size(), chunks2.size()); } }
@Override public BxDocument resolve(BxDocument messyDoc) { BxDocument orderedDoc = new BxDocument(); List<BxPage> pages = Lists.newArrayList(messyDoc); for (BxPage page : pages) { List<BxZone> zones = Lists.newArrayList(page); for (BxZone zone : zones) { List<BxLine> lines = Lists.newArrayList(zone); for (BxLine line : lines) { List<BxWord> words = Lists.newArrayList(line); for (BxWord word : words) { List<BxChunk> chunks = Lists.newArrayList(word); Collections.sort(chunks, X_ASCENDING_ORDER); word.resetText(); word.setChunks(chunks); } Collections.sort(words, X_ASCENDING_ORDER); line.resetText(); line.setWords(words); } Collections.sort(lines, YX_ASCENDING_ORDER); zone.resetText(); zone.setLines(lines); } List<BxZone> orderedZones; if (zones.size() > MAX_ZONES) { orderedZones = new ArrayList<BxZone>(zones); Collections.sort(orderedZones, YX_ASCENDING_ORDER); } else { orderedZones = reorderZones(zones); } page.setZones(orderedZones); page.resetText(); orderedDoc.addPage(page); TimeoutRegister.get().check(); } setIdsAndLinkTogether(orderedDoc); return orderedDoc; }
HierarchicalReadingOrderResolver implements ReadingOrderResolver { @Override public BxDocument resolve(BxDocument messyDoc) { BxDocument orderedDoc = new BxDocument(); List<BxPage> pages = Lists.newArrayList(messyDoc); for (BxPage page : pages) { List<BxZone> zones = Lists.newArrayList(page); for (BxZone zone : zones) { List<BxLine> lines = Lists.newArrayList(zone); for (BxLine line : lines) { List<BxWord> words = Lists.newArrayList(line); for (BxWord word : words) { List<BxChunk> chunks = Lists.newArrayList(word); Collections.sort(chunks, X_ASCENDING_ORDER); word.resetText(); word.setChunks(chunks); } Collections.sort(words, X_ASCENDING_ORDER); line.resetText(); line.setWords(words); } Collections.sort(lines, YX_ASCENDING_ORDER); zone.resetText(); zone.setLines(lines); } List<BxZone> orderedZones; if (zones.size() > MAX_ZONES) { orderedZones = new ArrayList<BxZone>(zones); Collections.sort(orderedZones, YX_ASCENDING_ORDER); } else { orderedZones = reorderZones(zones); } page.setZones(orderedZones); page.resetText(); orderedDoc.addPage(page); TimeoutRegister.get().check(); } setIdsAndLinkTogether(orderedDoc); return orderedDoc; } }
HierarchicalReadingOrderResolver implements ReadingOrderResolver { @Override public BxDocument resolve(BxDocument messyDoc) { BxDocument orderedDoc = new BxDocument(); List<BxPage> pages = Lists.newArrayList(messyDoc); for (BxPage page : pages) { List<BxZone> zones = Lists.newArrayList(page); for (BxZone zone : zones) { List<BxLine> lines = Lists.newArrayList(zone); for (BxLine line : lines) { List<BxWord> words = Lists.newArrayList(line); for (BxWord word : words) { List<BxChunk> chunks = Lists.newArrayList(word); Collections.sort(chunks, X_ASCENDING_ORDER); word.resetText(); word.setChunks(chunks); } Collections.sort(words, X_ASCENDING_ORDER); line.resetText(); line.setWords(words); } Collections.sort(lines, YX_ASCENDING_ORDER); zone.resetText(); zone.setLines(lines); } List<BxZone> orderedZones; if (zones.size() > MAX_ZONES) { orderedZones = new ArrayList<BxZone>(zones); Collections.sort(orderedZones, YX_ASCENDING_ORDER); } else { orderedZones = reorderZones(zones); } page.setZones(orderedZones); page.resetText(); orderedDoc.addPage(page); TimeoutRegister.get().check(); } setIdsAndLinkTogether(orderedDoc); return orderedDoc; }  }
HierarchicalReadingOrderResolver implements ReadingOrderResolver { @Override public BxDocument resolve(BxDocument messyDoc) { BxDocument orderedDoc = new BxDocument(); List<BxPage> pages = Lists.newArrayList(messyDoc); for (BxPage page : pages) { List<BxZone> zones = Lists.newArrayList(page); for (BxZone zone : zones) { List<BxLine> lines = Lists.newArrayList(zone); for (BxLine line : lines) { List<BxWord> words = Lists.newArrayList(line); for (BxWord word : words) { List<BxChunk> chunks = Lists.newArrayList(word); Collections.sort(chunks, X_ASCENDING_ORDER); word.resetText(); word.setChunks(chunks); } Collections.sort(words, X_ASCENDING_ORDER); line.resetText(); line.setWords(words); } Collections.sort(lines, YX_ASCENDING_ORDER); zone.resetText(); zone.setLines(lines); } List<BxZone> orderedZones; if (zones.size() > MAX_ZONES) { orderedZones = new ArrayList<BxZone>(zones); Collections.sort(orderedZones, YX_ASCENDING_ORDER); } else { orderedZones = reorderZones(zones); } page.setZones(orderedZones); page.resetText(); orderedDoc.addPage(page); TimeoutRegister.get().check(); } setIdsAndLinkTogether(orderedDoc); return orderedDoc; }  @Override BxDocument resolve(BxDocument messyDoc); }
HierarchicalReadingOrderResolver implements ReadingOrderResolver { @Override public BxDocument resolve(BxDocument messyDoc) { BxDocument orderedDoc = new BxDocument(); List<BxPage> pages = Lists.newArrayList(messyDoc); for (BxPage page : pages) { List<BxZone> zones = Lists.newArrayList(page); for (BxZone zone : zones) { List<BxLine> lines = Lists.newArrayList(zone); for (BxLine line : lines) { List<BxWord> words = Lists.newArrayList(line); for (BxWord word : words) { List<BxChunk> chunks = Lists.newArrayList(word); Collections.sort(chunks, X_ASCENDING_ORDER); word.resetText(); word.setChunks(chunks); } Collections.sort(words, X_ASCENDING_ORDER); line.resetText(); line.setWords(words); } Collections.sort(lines, YX_ASCENDING_ORDER); zone.resetText(); zone.setLines(lines); } List<BxZone> orderedZones; if (zones.size() > MAX_ZONES) { orderedZones = new ArrayList<BxZone>(zones); Collections.sort(orderedZones, YX_ASCENDING_ORDER); } else { orderedZones = reorderZones(zones); } page.setZones(orderedZones); page.resetText(); orderedDoc.addPage(page); TimeoutRegister.get().check(); } setIdsAndLinkTogether(orderedDoc); return orderedDoc; }  @Override BxDocument resolve(BxDocument messyDoc);  }