src/main/java/eu/digitisation/layout/HOCRPage.java
TextComponent parse(org.jsoup.nodes.Element element) {
        String id = element.attr("id");
        String subtype = element.attr("class");
        ComponentType type = ComponentType.valueOf(FileType.HOCR, subtype);
        String content = element.text();
        Polygon frontier = null;
        List<TextComponent> array = new ArrayList<TextComponent>();

        // extract coordinates
        String title = element.attr("title").trim();
        if (title.contains("bbox")) {
            int pos = title.indexOf("bbox");
            String[] coords = title.substring(pos).split("\\p{Space}+");
            int x0 = Integer.parseInt(coords[1]);
            int y0 = Integer.parseInt(coords[2]);
            int x1 = Integer.parseInt(coords[3]);
            int y1 = Integer.parseInt(coords[4]);
            
            frontier = new BoundingBox(x0, y0, x1, y1).asPolygon();
        } else if (title.contains("poly")) {
            int pos = title.indexOf("poly");
            String[] coords = title.substring(pos).split("\\p{Space}+");
            int n = 1;
            frontier = new Polygon();
            while (n + 1 < coords.length && !coords[n].equals(";")) {
                int x = Integer.parseInt(coords[n]);
                int y = Integer.parseInt(coords[n + 1]);
                frontier.addPoint(x, y);
                n += 2;
            }
        }
        // get subcomponents

        org.jsoup.select.Elements children = element.children();

        for (org.jsoup.nodes.Element child : children) {
            if (child.hasAttr("class")) {
                String cat = child.attr("class");
                if (cat.equals("ocr_carea") 
                        || cat.equals("ocr_par")
                        || cat.equals("ocr_line")
                        || cat.equals("ocr_word")
                        || cat.equals("ocrx_word")) {
                    TextComponent subcomponent = parse(child);
                    array.add(subcomponent);
                }
            }
        }

        TextComponent component = new TextComponent(id, type, subtype, content, frontier);
        components.add(component);
        System.out.println(component);
        subcomponents.put(component, array);
        return component;
    }
/**
     * Parse an XML element and retrieve the associated text component
     *
     * @param element an HTML element
     * @return the text component associated with this element
     */
Parse an XML element and retrieve the associated text component
@param element an HTML element
@return the text component associated with this element
Parse an XML element and retrieve the associated text component @param element an HTML element @return the text component associated with this element
TextComponent parse(org.jsoup.nodes.Element element) {
        String id = element.attr("id");
        String subtype = element.attr("class");
        ComponentType type = ComponentType.valueOf(FileType.HOCR, subtype);
        String content = element.text();
        Polygon frontier = null;
        List<TextComponent> array = new ArrayList<TextComponent>();
        String title = element.attr("title").trim();
        if (title.contains("bbox")) {
            int pos = title.indexOf("bbox");
            String[] coords = title.substring(pos).split("\\p{Space}+");
            int x0 = Integer.parseInt(coords[1]);
            int y0 = Integer.parseInt(coords[2]);
            int x1 = Integer.parseInt(coords[3]);
            int y1 = Integer.parseInt(coords[4]);
            frontier = new BoundingBox(x0, y0, x1, y1).asPolygon();
        } else if (title.contains("poly")) {
            int pos = title.indexOf("poly");
            String[] coords = title.substring(pos).split("\\p{Space}+");
            int n = 1;
            frontier = new Polygon();
            while (n + 1 < coords.length && !coords[n].equals(";")) {
                int x = Integer.parseInt(coords[n]);
                int y = Integer.parseInt(coords[n + 1]);
                frontier.addPoint(x, y);
                n += 2;
            }
        }
        org.jsoup.select.Elements children = element.children();
        for (org.jsoup.nodes.Element child : children) {
            if (child.hasAttr("class")) {
                String cat = child.attr("class");
                if (cat.equals("ocr_carea") 
                        || cat.equals("ocr_par")
                        || cat.equals("ocr_line")
                        || cat.equals("ocr_word")
                        || cat.equals("ocrx_word")) {
                    TextComponent subcomponent = parse(child);
                    array.add(subcomponent);
                }
            }
        }
        TextComponent component = new TextComponent(id, type, subtype, content, frontier);
        components.add(component);
        System.out.println(component);
        subcomponents.put(component, array);
        return component;
    }
TextComponent parse ( org . jsoup . nodes . Element element ) { String id = element . attr ( "id" ) ; String subtype = element . attr ( "class" ) ; ComponentType type = ComponentType . valueOf ( FileType . HOCR , subtype ) ; String content = element . text ( ) ; Polygon frontier = null ; List < TextComponent > array = new ArrayList < TextComponent > ( ) ; String title = element . attr ( "title" ) . trim ( ) ; if ( title . contains ( "bbox" ) ) { int pos = title . indexOf ( "bbox" ) ; String [ ] coords = title . substring ( pos ) . split ( "\\p{Space}+" ) ; int x0 = Integer . parseInt ( coords [ 1 ] ) ; int y0 = Integer . parseInt ( coords [ 2 ] ) ; int x1 = Integer . parseInt ( coords [ 3 ] ) ; int y1 = Integer . parseInt ( coords [ 4 ] ) ; frontier = new BoundingBox ( x0 , y0 , x1 , y1 ) . asPolygon ( ) ; } else if ( title . contains ( "poly" ) ) { int pos = title . indexOf ( "poly" ) ; String [ ] coords = title . substring ( pos ) . split ( "\\p{Space}+" ) ; int n = 1 ; frontier = new Polygon ( ) ; while ( n + 1 < coords . length && ! coords [ n ] . equals ( ";" ) ) { int x = Integer . parseInt ( coords [ n ] ) ; int y = Integer . parseInt ( coords [ n + 1 ] ) ; frontier . addPoint ( x , y ) ; n += 2 ; } } org . jsoup . select . Elements children = element . children ( ) ; for ( org . jsoup . nodes . Element child : children ) { if ( child . hasAttr ( "class" ) ) { String cat = child . attr ( "class" ) ; if ( cat . equals ( "ocr_carea" ) || cat . equals ( "ocr_par" ) || cat . equals ( "ocr_line" ) || cat . equals ( "ocr_word" ) || cat . equals ( "ocrx_word" ) ) { TextComponent subcomponent = parse ( child ) ; array . add ( subcomponent ) ; } } } TextComponent component = new TextComponent ( id , type , subtype , content , frontier ) ; components . add ( component ) ; System . out . println ( component ) ; subcomponents . put ( component , array ) ; return component ; }
Parse an XML element and retrieve the associated text component
 @param element an HTML element
 @return the text component associated with this element
Parse an XML element and retrieve the associated text component @param element an HTML element @return the text component associated with this element
// extract coordinates // get subcomponents