use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.
the class JochreCorpusImageProcessor method process.
public void process() {
this.initialiseStream();
JochreDocument currentDoc = null;
JochrePage currentPage = null;
for (JochreImage image : this.getImages()) {
if (!image.getPage().equals(currentPage)) {
if (currentPage != null) {
for (DocumentObserver observer : observers) {
observer.onPageComplete(currentPage);
}
LOG.debug("completed page: " + currentPage);
}
}
if (!image.getPage().getDocument().equals(currentDoc)) {
if (currentDoc != null) {
for (DocumentObserver observer : observers) {
observer.onDocumentComplete(currentDoc);
}
LOG.debug("completed doc: " + currentDoc);
}
currentDoc = image.getPage().getDocument();
LOG.debug("next doc: " + currentDoc);
for (DocumentObserver observer : observers) {
observer.onDocumentStart(currentDoc);
}
}
if (!image.getPage().equals(currentPage)) {
currentPage = image.getPage();
LOG.debug("next page: " + currentPage);
for (DocumentObserver observer : observers) {
observer.onPageStart(currentPage);
}
}
LOG.debug("next image: " + image);
for (DocumentObserver observer : observers) {
observer.onImageStart(image);
}
for (DocumentObserver observer : observers) {
observer.onImageComplete(image);
}
LOG.debug("completed image: " + image);
image.clearMemory();
}
if (currentPage != null) {
for (DocumentObserver observer : observers) {
observer.onPageComplete(currentPage);
}
LOG.debug("completed page: " + currentPage);
}
if (currentDoc != null) {
for (DocumentObserver observer : observers) {
observer.onDocumentComplete(currentDoc);
}
LOG.debug("completed doc: " + currentDoc);
}
for (DocumentObserver observer : observers) {
observer.onAnalysisComplete();
}
}
use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.
the class TextController method onTimer$startRenderTimer.
@Listen("onTimer = #startRenderTimer")
public void onTimer$startRenderTimer(Event event) {
try {
progressBox.setVisible(true);
if (currentImage != null) {
Html html = new Html();
StringWriter out = new StringWriter();
DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
textGetter.onImageComplete(currentImage);
html.setContent(out.toString());
htmlContent.appendChild(html);
progressMeter1.setValue(100);
// progressBox.setVisible(false);
} else {
if (currentPageIndex < currentDoc.getPages().size()) {
JochrePage page = currentDoc.getPages().get(currentPageIndex);
for (JochreImage image : page.getImages()) {
Html html = new Html();
StringWriter out = new StringWriter();
DocumentObserver textGetter = new TextGetter(out, TextFormat.XHTML);
textGetter.onImageComplete(image);
out.append("<HR/>");
html.setContent(out.toString());
htmlContent.appendChild(html);
}
page.clearMemory();
currentPageIndex++;
double percentComplete = ((double) currentPageIndex / (double) currentDoc.getPages().size()) * 100;
progressMeter1.setValue(new Double(percentComplete).intValue());
startRenderTimer.setRunning(true);
} else {
progressMeter1.setValue(100);
// progressBox.setVisible(false);
}
}
} catch (Exception e) {
LOG.error("Failure in onTimer$startRenderTimer", e);
throw new RuntimeException(e);
}
}
use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.
the class DocumentController method getDocumentTree.
public TreeModel<TreeNode<DocOrImage>> getDocumentTree() {
LOG.debug("getDocumentTree2");
DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
List<JochreDocument> docs = documentDao.findDocuments();
List<TreeNode<DocOrImage>> docNodeList = new ArrayList<>();
for (JochreDocument doc : docs) {
List<TreeNode<DocOrImage>> imageNodeList = new ArrayList<>();
for (JochrePage page : doc.getPages()) {
LOG.debug("page " + page.getIndex());
for (JochreImage image : page.getImages()) {
DefaultTreeNode<DocOrImage> imageNode = new DefaultTreeNode<DocumentController.DocOrImage>(new DocOrImage(image));
imageNodeList.add(imageNode);
if (imageId == image.getId())
currentImage = image;
}
// have images?
}
boolean open = docId == doc.getId();
if (open)
currentDoc = doc;
DefaultTreeNode<DocOrImage> docNode = new DirectoryTreeNode<DocumentController.DocOrImage>(new DocOrImage(doc), imageNodeList, open);
docNodeList.add(docNode);
}
DefaultTreeNode<DocOrImage> root = new DefaultTreeNode<DocumentController.DocOrImage>(null, docNodeList);
TreeModel<TreeNode<DocOrImage>> docTree = new DefaultTreeModel<>(root);
this.reloadDoc();
this.reloadImage();
return docTree;
}
use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.
the class SplitController method doAfterCompose.
@Override
public void doAfterCompose(Window window) throws Exception {
super.doAfterCompose(window);
String pageTitle = Labels.getLabel("splits.title");
winSplits.getPage().setTitle(pageTitle);
Session session = Sessions.getCurrent();
currentUser = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
if (currentUser == null)
Executions.sendRedirect("login.zul");
GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
shapesToSplit = graphicsDao.findShapesToSplit(jochreSession.getLocale());
for (Shape shape : shapesToSplit) {
Row shapeRow = new Row();
Image shapeImage = new Image();
org.zkoss.image.Image convertedImage = Images.encode("shape_" + shape.getId() + ".png", shape.getImage());
shapeImage.setContent(convertedImage);
shapeImage.setWidth(shape.getImage().getWidth() + "px");
shapeImage.setHeight((shape.getImage().getHeight()) + "px");
Cell shapeCell = new Cell();
Div shapeDiv = new Div();
shapeDiv.setStyle("position: relative;");
shapeCell.appendChild(shapeDiv);
int shapeWidth = shape.getImage().getWidth();
shapeCell.setWidth((shapeWidth + 100) + "px");
shapeImage.addEventListener("onClick", new ShapeImageOnClickEventListener(shape, shapeDiv));
shapeDiv.appendChild(shapeImage);
for (Split split : shape.getSplits()) {
Div verticalLine = new Div();
verticalLine.setWidth("1px");
verticalLine.setHeight("100px");
verticalLine.setStyle("position: absolute; top:0px; left: " + split.getPosition() + "px;background-color:RED;");
verticalLine.setId("shape" + shape.getId() + "split" + split.getPosition());
verticalLine.addEventListener("onClick", new SplitOnClickEventListener(shape, shapeDiv, verticalLine, split));
shapeDiv.appendChild(verticalLine);
}
shapeRow.appendChild(shapeCell);
Cell letterCell = new Cell();
Label letterLabel = new Label();
letterLabel.setValue(shape.getLetter());
letterCell.appendChild(letterLabel);
letterCell.setWidth("100px");
shapeRow.appendChild(letterCell);
Cell detailsCell = new Cell();
Label detailsLabel = new Label();
JochrePage page = shape.getGroup().getRow().getParagraph().getImage().getPage();
JochreDocument doc = page.getDocument();
detailsLabel.setValue(doc.getName() + ", page " + page.getIndex());
detailsCell.appendChild(detailsLabel);
shapeRow.appendChild(detailsCell);
splitGridRows.appendChild(shapeRow);
}
}
use of com.joliciel.jochre.doc.JochrePage in project jochre by urieli.
the class SplitCandidateFinderImplTest method testFindSplitCanidates.
@Test
public void testFindSplitCanidates() throws Exception {
System.setProperty("config.file", "src/test/resources/test.conf");
ConfigFactory.invalidateCaches();
Config config = ConfigFactory.load();
JochreSession jochreSession = new JochreSession(config);
InputStream imageFileStream = getClass().getResourceAsStream("shape_370454.png");
assertNotNull(imageFileStream);
BufferedImage image = ImageIO.read(imageFileStream);
final JochrePage page = mock(JochrePage.class);
JochreImage jochreImage = new SourceImage(page, "name", image, jochreSession);
Shape shape = jochreImage.getShape(0, 0, jochreImage.getWidth() - 1, jochreImage.getHeight() - 1);
SplitCandidateFinder splitCandidateFinder = new SplitCandidateFinder(jochreSession);
List<Split> splits = splitCandidateFinder.findSplitCandidates(shape);
int[] trueSplitPositions = new int[] { 38, 59, 82 };
boolean[] foundSplit = new boolean[] { false, false, false };
for (Split splitCandidate : splits) {
LOG.debug("Split candidate at " + splitCandidate.getPosition());
for (int i = 0; i < trueSplitPositions.length; i++) {
int truePos = trueSplitPositions[i];
int distance = splitCandidate.getPosition() - truePos;
if (distance < 0)
distance = 0 - distance;
if (distance < splitCandidateFinder.getMinDistanceBetweenSplits()) {
foundSplit[i] = true;
LOG.debug("Found split: " + truePos + ", distance " + distance);
}
}
}
for (int i = 0; i < trueSplitPositions.length; i++) {
assertTrue("didn't find split " + trueSplitPositions[i], foundSplit[i]);
}
}
Aggregations