package pl.edu.icm.yadda.analysis.metadata.zoneclassification.tools;

import java.util.Map;
import pl.edu.icm.yadda.analysis.textr.model.BxDocument;
import pl.edu.icm.yadda.analysis.textr.model.BxPage;
import pl.edu.icm.yadda.analysis.textr.model.BxZone;
import pl.edu.icm.yadda.analysis.textr.model.BxZoneLabel;
import pl.edu.icm.yadda.analysis.textr.tools.BxBoundsBuilder;
import pl.edu.icm.yadda.analysis.textr.tools.BxModelUtils;

/**
 * Zone classification utilitu class.
 *
 * @author Dominika Tkaczyk (d.tkaczyk@icm.edu.pl)
 */
public class ZoneClassificationUtils {

    public static void sortZones(BxDocument document, double tolerance) {
        for (BxPage page : document.getPages()) {
            BxModelUtils.sortZonesRecursively(page);
            BxModelUtils.sortZonesYX(page, tolerance);
        }
    }

    public static void mapZoneLabels(BxDocument document, Map<BxZoneLabel, BxZoneLabel> labelMap) {
        for (BxPage page : document.getPages()) {
            for (BxZone zone : page.getZones()) {
                if (labelMap.get(zone.getLabel()) != null) {
                    zone.setLabel(labelMap.get(zone.getLabel()));
                }
            }
        }
    }

    public static void correctPagesBounds(BxDocument document) {
        BxBoundsBuilder builder = new BxBoundsBuilder();
        for (BxPage page : document.getPages()) {
            builder.expand(page.getBounds());
        }
        for (BxPage page : document.getPages()) {
            page.setBounds(builder.getBounds());
        }
    }
}

@@ -306,16 +306,90 @@
 eLabel;%0A
+import pl.edu.icm.yadda.analysis.textr.readingorder.ReadingOrderAnalyzer;%0A
 import p
@@ -438,24 +438,24 @@
 ndsBuilder;%0A
-
 import pl.ed
@@ -535,17 +535,17 @@
 n utilit
-u
+y
  class.%0A
@@ -720,175 +720,144 @@
 ) %7B%0A
-        for (BxPage page : document.getPages()) %7B%0A            BxModelUtils.sortZonesRecursively(page);%0A            BxModelUtils.sortZonesYX(page, tolerance);%0A        %7D
+%09%09ReadingOrderAnalyzer roa = new ReadingOrderAnalyzer();%0A%09%09BxDocument sortedDoc = roa.setReadingOrder(document);%0A%09%09document = sortedDoc;
 %0A   

Change method used for resolving reading order