@Test public void testSetReadingOrder() throws TransformationException, IOException { for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) { String filename = e.nextElement().getName(); if (!filename.endsWith(".xml")) { continue; } BxDocument doc = getDocumentFromZip(filename); BxDocument modelOrderedDoc = getDocumentFromZip(filename + ".out"); HierarchicalReadingOrderResolver roa = new HierarchicalReadingOrderResolver(); BxDocument orderedDoc = roa.resolve(doc); assertTrue(areDocumentsEqual(orderedDoc, modelOrderedDoc)); } }
@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);  }