
com.googlecode.jhocr.element.HocrCarea Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jhocr Show documentation
Show all versions of jhocr Show documentation
Library to parse and perform conversion from hocr files to pdf, merging the image files and mapping the hocr data into one document.
The newest version!
/**
* Copyright (©) 2013 Pablo Filetti Moreira
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.googlecode.jhocr.element;
import java.util.ArrayList;
import java.util.List;
import com.googlecode.jhocr.attribute.BBox;
/**
* Class used to store information "ocr_carea" element and its children.
*
* Element example: {@code }
*/
public class HocrCarea extends HocrElement {
public static final String TAGNAME = "div";
public static final String CLASSNAME = "ocr_carea";
private HocrPage page;
private List paragraphs = new ArrayList();
/**
* Constructs an HocrCarea
with a unique id and a coordinates BBox
.
*
* @param id Set the id of element.
* @param bbox Sets the coordinates of element.
*/
public HocrCarea(String id, BBox bbox) {
super(id, bbox);
}
/**
* @return The children HocrParagraph
of this.
*/
public List getParagraphs() {
return paragraphs;
}
/**
* Set the children HocrParagraph
of this.
* @param paragraphs The children HocrParagraph
of this.
*/
public void setParagraphs(List paragraphs) {
this.paragraphs = paragraphs;
}
/**
* Add new paragraph.
*
* @param paragraph The new paragraph.
*/
public void addParagraph(HocrParagraph paragraph) {
paragraph.setCarea(this);
getParagraphs().add(paragraph);
}
@Override
public String getClassName() {
return CLASSNAME;
}
@Override
public String getTagName() {
return TAGNAME;
}
/**
* @return The parent HocrPage
of this.
*/
public HocrPage getPage() {
return page;
}
/**
* Set the parent HocrPage
of this.
* @param page The parent HocrPage
of this.
*/
public void setPage(HocrPage page) {
this.page = page;
}
/**
* @return The children HocrLine
of this.
*/
public List getLines() {
List lines = new ArrayList();
for (HocrParagraph paragraph : getParagraphs()) {
lines.addAll(paragraph.getLines());
}
return lines;
}
/**
* @return The children HocrWord
of this.
*/
public List getWords() {
List words = new ArrayList();
for (HocrLine line : getLines()) {
words.addAll(line.getWords());
}
return words;
}
/**
* Returns the informations of this element as a String
.
*
* @return the informations of this element as a String
.
*/
@Override
public String toString() {
return "HocrCarea{" + super.toString() + ", paragraphs=" + paragraphs.size() + "}";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy