Search in sources :

Example 1 with GraphicsDao

use of com.joliciel.jochre.graphics.GraphicsDao in project jochre by urieli.

the class JochrePage method getImages.

public List<JochreImage> getImages() {
    if (this.jochreImages == null) {
        if (this.id == 0)
            this.jochreImages = new ArrayList<JochreImage>();
        else {
            GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
            this.jochreImages = graphicsDao.findImages(this);
        }
    }
    return this.jochreImages;
}
Also used : GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) ArrayList(java.util.ArrayList)

Example 2 with GraphicsDao

use of com.joliciel.jochre.graphics.GraphicsDao in project jochre by urieli.

the class ImageController method doAfterCompose.

@Override
public void doAfterCompose(Window window) throws Exception {
    super.doAfterCompose(window);
    Session session = Sessions.getCurrent();
    currentUser = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
    if (currentUser == null)
        Executions.sendRedirect("login.zul");
    // comp.setVariable(comp.getId() + "Ctrl", this, true);
    hebrewAccentsSpan.setContent("var hebrewAccents=\"" + HEBREW_ACCENTS + "\";");
    rowGrid.setRowRenderer(new ImageGridRowRenderer());
    HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
    imageId = Integer.parseInt(request.getParameter("imageId"));
    GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
    currentImage = graphicsDao.loadJochreImage(imageId);
    docId = currentImage.getPage().getDocumentId();
    currentImageOwner = (currentUser.getRole().equals(UserRole.ADMIN) || currentImage.getOwner().equals(currentUser));
    if (!currentImageOwner) {
        btnSave.setVisible(false);
        btnSave2.setVisible(false);
        btnSaveAndExit.setVisible(false);
        btnSaveAndExit2.setVisible(false);
        cmbStatus.setVisible(false);
        lblImageStatus.setVisible(true);
    } else {
        btnSave.setVisible(true);
        btnSave2.setVisible(true);
        btnSaveAndExit.setVisible(true);
        btnSaveAndExit2.setVisible(true);
        cmbStatus.setVisible(true);
        lblImageStatus.setVisible(false);
    }
    if (currentUser.getRole().equals(UserRole.ADMIN)) {
        cmbOwner.setVisible(true);
        lblOwner.setVisible(false);
        SecurityDao securityDao = SecurityDao.getInstance(jochreSession);
        List<User> users = securityDao.findUsers();
        List<Comboitem> cmbOwnerItems = cmbOwner.getItems();
        Comboitem selectedUser = null;
        for (User user : users) {
            Comboitem item = new Comboitem(user.getFullName());
            item.setValue(user);
            if (currentImage.getOwner().equals(user))
                selectedUser = item;
            cmbOwnerItems.add(item);
        }
        cmbOwner.setSelectedItem(selectedUser);
    } else {
        cmbOwner.setVisible(false);
        lblOwner.setVisible(true);
        lblOwner.setValue(currentImage.getOwner().getFullName());
    }
    String pageTitle = Labels.getLabel("image.title");
    winJochreImage.getPage().setTitle(pageTitle);
    String windowTitle = Labels.getLabel("image.winJochreImage.title", new Object[] { currentImage.getPage().getDocument().getName(), currentImage.getPage().getIndex() });
    winJochreImage.setTitle(windowTitle);
    List<Comboitem> cmbStatusItems = cmbStatus.getItems();
    Comboitem selectedItem = null;
    List<ImageStatus> imageStatuses = new ArrayList<ImageStatus>();
    if (currentUser.getRole().equals(UserRole.ADMIN)) {
        for (ImageStatus imageStatus : ImageStatus.values()) {
            imageStatuses.add(imageStatus);
        }
    } else if (currentImage.getImageStatus().equals(ImageStatus.AUTO_NEW) || currentImage.getImageStatus().equals(ImageStatus.AUTO_VALIDATED)) {
        imageStatuses.add(ImageStatus.AUTO_NEW);
        imageStatuses.add(ImageStatus.AUTO_VALIDATED);
    } else {
        // a bit dangerous - leaving the image as "training" and allowing
        // modifications, but oh well!
        imageStatuses.add(currentImage.getImageStatus());
    }
    for (ImageStatus imageStatus : imageStatuses) {
        String statusLabel = Labels.getLabel("ImageStatus." + imageStatus.getCode());
        Comboitem item = new Comboitem(statusLabel);
        item.setValue(imageStatus.getId());
        if (currentImage.getImageStatus().equals(imageStatus))
            selectedItem = item;
        cmbStatusItems.add(item);
    }
    cmbStatus.setSelectedItem(selectedItem);
    lblImageStatus.setValue(Labels.getLabel("ImageStatus." + currentImage.getImageStatus().getCode()));
    reloadRowGrid();
}
Also used : User(com.joliciel.jochre.security.User) ImageStatus(com.joliciel.jochre.graphics.ImageStatus) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) Comboitem(org.zkoss.zul.Comboitem) JochreSession(com.joliciel.jochre.JochreSession) Session(org.zkoss.zk.ui.Session) SecurityDao(com.joliciel.jochre.security.SecurityDao)

Example 3 with GraphicsDao

use of com.joliciel.jochre.graphics.GraphicsDao in project jochre by urieli.

the class Jochre method doCommandLogImage.

/**
 * Log a shape's image to the log file, to make sure it got segmented and stored
 * correctly.
 */
public void doCommandLogImage(int shapeId) {
    // correctly
    if (shapeId > 0) {
        GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
        Shape shape = graphicsDao.loadShape(shapeId);
        shape.writeImageToLog();
        LOG.debug("Letter: " + shape.getLetter());
    }
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao)

Example 4 with GraphicsDao

use of com.joliciel.jochre.graphics.GraphicsDao in project jochre by urieli.

the class Jochre method doCommandTestFeature.

/**
 * Test a feature on a particular shape.
 */
public void doCommandTestFeature(int shapeId) {
    // just a utility for testing a feature on a particular shape
    ShapeFeature<?> feature = new VerticalElongationFeature();
    GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
    if (shapeId > 0) {
        Shape shape = graphicsDao.loadShape(shapeId);
        shape.writeImageToLog();
        RuntimeEnvironment env = new RuntimeEnvironment();
        feature.check(shape, env);
    } else {
        // String result = "false";
        // TrainingServiceLocator trainingServiceLocator =
        // locator.getTrainingServiceLocator();
        // TrainingService trainingService =
        // trainingServiceLocator.getTrainingService();
        // List<Integer> shapeIds =
        // trainingService.findShapesForFeature("ג", feature, result);
        List<Integer> shapeIds = graphicsDao.findShapeIds("—");
        Map<Object, Integer> outcomeMap = new HashMap<>();
        for (int oneShapeId : shapeIds) {
            Shape shape = graphicsDao.loadShape(oneShapeId);
            shape.writeImageToLog();
            RuntimeEnvironment env = new RuntimeEnvironment();
            FeatureResult<?> weightedOutcome = feature.check(shape, env);
            Object outcome = weightedOutcome.getOutcome();
            Integer count = outcomeMap.get(outcome);
            if (count == null)
                outcomeMap.put(outcome, 1);
            else
                outcomeMap.put(outcome, count.intValue() + 1);
        }
        LOG.debug("Outcomes:");
        for (Object outcome : outcomeMap.keySet()) {
            LOG.debug("Outcome " + outcome.toString() + ", count " + outcomeMap.get(outcome));
        }
    }
}
Also used : Shape(com.joliciel.jochre.graphics.Shape) RuntimeEnvironment(com.joliciel.talismane.machineLearning.features.RuntimeEnvironment) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) VerticalElongationFeature(com.joliciel.jochre.graphics.features.VerticalElongationFeature)

Example 5 with GraphicsDao

use of com.joliciel.jochre.graphics.GraphicsDao in project jochre by urieli.

the class ImageController method save.

void save() {
    try {
        Comboitem selectedItem = cmbStatus.getSelectedItem();
        ImageStatus imageStatus = ImageStatus.forId((Integer) selectedItem.getValue());
        currentImage.setImageStatus(imageStatus);
        if (currentUser.getRole().equals(UserRole.ADMIN)) {
            User owner = (User) cmbOwner.getSelectedItem().getValue();
            currentImage.setOwner(owner);
        }
        GraphicsDao graphicsDao = GraphicsDao.getInstance(jochreSession);
        graphicsDao.saveJochreImage(currentImage);
        for (Paragraph paragraph : currentImage.getParagraphs()) {
            LOG.trace("Paragraph " + paragraph.getIndex() + ", " + paragraph.getRows().size() + " rows");
            for (RowOfShapes row : paragraph.getRows()) {
                List<List<String>> letterGroups = this.getLetterGroups(row);
                LOG.trace("Row " + row.getIndex() + ", " + row.getGroups().size() + " groups, " + letterGroups.size() + " letter groups");
                Iterator<List<String>> iLetterGroups = letterGroups.iterator();
                for (GroupOfShapes group : row.getGroups()) {
                    LOG.trace("Group " + group.getIndex() + " text : " + group.getWord());
                    boolean hasChange = false;
                    List<String> letters = null;
                    if (iLetterGroups.hasNext())
                        letters = iLetterGroups.next();
                    else
                        letters = new ArrayList<String>();
                    LOG.trace("Found " + letters.size() + " letters in text");
                    Iterator<String> iLetters = letters.iterator();
                    for (Shape shape : group.getShapes()) {
                        String currentLetter = shape.getLetter();
                        if (currentLetter == null)
                            currentLetter = "";
                        String newLetter = "";
                        if (iLetters.hasNext())
                            newLetter = iLetters.next();
                        if (newLetter.startsWith("[") && newLetter.endsWith("]")) {
                            newLetter = newLetter.substring(1, newLetter.length() - 1);
                        }
                        LOG.trace("currentLetter:  " + currentLetter + ", newLetter: " + newLetter);
                        if (!currentLetter.equals(newLetter)) {
                            LOG.trace("newLetter: " + newLetter);
                            shape.setLetter(newLetter);
                            shape.save();
                            hasChange = true;
                        }
                    }
                    if (hasChange)
                        LOG.trace("Group text after : " + group.getWord());
                }
            // next group
            }
        // next row
        }
        // next paragraph
        Messagebox.show(Labels.getLabel("button.saveComplete"));
    } catch (Exception e) {
        LOG.error("Failure in save", e);
        throw new RuntimeException(e);
    }
}
Also used : User(com.joliciel.jochre.security.User) Shape(com.joliciel.jochre.graphics.Shape) ImageStatus(com.joliciel.jochre.graphics.ImageStatus) ArrayList(java.util.ArrayList) RowOfShapes(com.joliciel.jochre.graphics.RowOfShapes) Paragraph(com.joliciel.jochre.graphics.Paragraph) GraphicsDao(com.joliciel.jochre.graphics.GraphicsDao) GroupOfShapes(com.joliciel.jochre.graphics.GroupOfShapes) Comboitem(org.zkoss.zul.Comboitem) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

GraphicsDao (com.joliciel.jochre.graphics.GraphicsDao)10 Shape (com.joliciel.jochre.graphics.Shape)5 ArrayList (java.util.ArrayList)4 JochreSession (com.joliciel.jochre.JochreSession)3 ImageStatus (com.joliciel.jochre.graphics.ImageStatus)3 User (com.joliciel.jochre.security.User)3 Session (org.zkoss.zk.ui.Session)3 DocumentDao (com.joliciel.jochre.doc.DocumentDao)2 JochreDocument (com.joliciel.jochre.doc.JochreDocument)2 JochrePage (com.joliciel.jochre.doc.JochrePage)2 JochreImage (com.joliciel.jochre.graphics.JochreImage)2 List (java.util.List)2 BeamSearchImageAnalyser (com.joliciel.jochre.analyser.BeamSearchImageAnalyser)1 ErrorLogger (com.joliciel.jochre.analyser.ErrorLogger)1 FScoreObserver (com.joliciel.jochre.analyser.FScoreObserver)1 ImageAnalyser (com.joliciel.jochre.analyser.ImageAnalyser)1 LetterAssigner (com.joliciel.jochre.analyser.LetterAssigner)1 LetterGuessObserver (com.joliciel.jochre.analyser.LetterGuessObserver)1 OriginalShapeLetterAssigner (com.joliciel.jochre.analyser.OriginalShapeLetterAssigner)1 SimpleLetterFScoreObserver (com.joliciel.jochre.analyser.SimpleLetterFScoreObserver)1