use of com.joliciel.jochre.JochreSession in project jochre by urieli.
the class VectorizerImplTest method testGetLinesToEdge.
@Test
public void testGetLinesToEdge() throws Exception {
System.setProperty("config.file", "src/test/resources/test.conf");
ConfigFactory.invalidateCaches();
Config config = ConfigFactory.load();
JochreSession jochreSession = new JochreSession(config);
final int threshold = 100;
final int whiteGapFillFactor = 5;
int[] pixels = { // row
0, // row
1, // row
1, // row
0, // row
0, // row
1, // row
1, // row
1, // row
0, // row
1, // row
1, // row
1, // row
0, // row
1, // row
1, // row
1, // row
0, // row
0, // row
1, // row
1, // row
0, // row
0, // row
1, // row
1, // row
0, // row
0, // row
1, // row
1, // row
0, // row
1, // row
1, // row
0, // row
0, // row
0, // row
0, // row
1, // row
1, // row
1, // row
1, // row
0, // row
0, // row
0, // row
0, // row
1, // row
1, // row
1, // row
0, // row
0, // row
0, // row
0, // row
1, // row
1, // row
1, // row
0, // row
0, // row
0, // row
1, // row
1, // row
1, // row
1, // row
1, // row
0, // row
0, // row
0 };
Shape shape = new ShapeMock(pixels, 8, 8, jochreSession);
Vectorizer vectorizer = new Vectorizer();
vectorizer.setWhiteGapFillFactor(whiteGapFillFactor);
List<LineSegment> lines = vectorizer.getLinesToEdge(shape, 2, 2, threshold);
assertEquals(6, lines.size());
}
use of com.joliciel.jochre.JochreSession in project jochre by urieli.
the class RecursiveShapeSplitterTest method testSplitShape.
/**
* Make sure we get 5 equally weighted sequences in the case of a 50/50 prob for
* splitting each time.
*/
@SuppressWarnings("unchecked")
@Test
public void testSplitShape() throws Exception {
System.setProperty("config.file", "src/test/resources/test.conf");
ConfigFactory.invalidateCaches();
Config config = ConfigFactory.load();
JochreSession jochreSession = new JochreSession(config);
BufferedImage originalImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
final JochreImage jochreImage = new JochreImage(originalImage, jochreSession);
final Shape shape = new Shape(jochreImage, 0, 0, 63, 15, jochreSession);
shape.setBaseLine(12);
shape.setMeanLine(4);
final Shape shape1 = new Shape(jochreImage, 0, 0, 31, 15, jochreSession);
shape1.setBaseLine(12);
shape1.setMeanLine(4);
final Shape shape2 = new Shape(jochreImage, 32, 0, 63, 15, jochreSession);
shape2.setBaseLine(12);
shape2.setMeanLine(4);
final SplitCandidateFinder splitCandidateFinder = mock(SplitCandidateFinder.class);
final DecisionMaker decisionMaker = mock(DecisionMaker.class);
Split split = new Split(shape, jochreSession);
split.setPosition(31);
List<Split> splits = new ArrayList<>();
splits.add(split);
when(splitCandidateFinder.findSplitCandidates(shape)).thenReturn(splits);
Decision yesDecision = new Decision(SplitOutcome.DO_SPLIT.name(), 0.5);
Decision noDecision = new Decision(SplitOutcome.DO_NOT_SPLIT.name(), 0.5);
List<Decision> decisions = new ArrayList<>();
decisions.add(yesDecision);
decisions.add(noDecision);
when(decisionMaker.decide(anyList())).thenReturn(decisions);
Split split1 = new Split(shape1, jochreSession);
split1.setPosition(15);
List<Split> splits1 = new ArrayList<>();
splits1.add(split1);
when(splitCandidateFinder.findSplitCandidates(shape1)).thenReturn(splits1);
Split split2 = new Split(shape2, jochreSession);
split2.setPosition(15);
List<Split> splits2 = new ArrayList<>();
splits2.add(split2);
when(splitCandidateFinder.findSplitCandidates(shape2)).thenReturn(splits2);
Set<SplitFeature<?>> splitFeatures = new TreeSet<>();
RecursiveShapeSplitter splitter = new RecursiveShapeSplitter(splitCandidateFinder, splitFeatures, decisionMaker, jochreSession);
splitter.setBeamWidth(10);
splitter.setMaxDepth(2);
splitter.setMinWidthRatio(1.0);
List<ShapeSequence> shapeSequences = splitter.split(shape);
assertEquals(5, shapeSequences.size());
for (ShapeSequence shapeSequence : shapeSequences) {
assertEquals(1.0, shapeSequence.getScore(), 0.0001);
}
}
use of com.joliciel.jochre.JochreSession in project jochre by urieli.
the class TrainingCorpusShapeSplitterTest method testSplit.
@Test
public void testSplit() throws Exception {
System.setProperty("config.file", "src/test/resources/testDualCharacters.conf");
ConfigFactory.invalidateCaches();
Config config = ConfigFactory.load();
final JochreSession jochreSession = new JochreSession(config);
final Shape shape = mock(Shape.class);
final Shape shape1 = mock(Shape.class);
final Shape shape2 = mock(Shape.class);
final Shape shape3 = mock(Shape.class);
final Shape shape4 = mock(Shape.class);
final GroupOfShapes group = mock(GroupOfShapes.class);
final RowOfShapes row = mock(RowOfShapes.class);
final Paragraph paragraph = mock(Paragraph.class);
final JochreImage jochreImage = mock(JochreImage.class);
final JochrePage jochrePage = mock(JochrePage.class);
final JochreDocument jochreDocument = mock(JochreDocument.class);
final Iterator<Split> i = (Iterator<Split>) mock(Iterator.class);
final List<Split> splits = (List<Split>) mock(List.class);
final Split split1 = mock(Split.class);
final Split split2 = mock(Split.class);
final Split split3 = mock(Split.class);
when(shape.getLetter()).thenReturn("אָבּער");
when(shape.getLeft()).thenReturn(100);
when(shape.getRight()).thenReturn(200);
when(shape.getTop()).thenReturn(100);
when(shape.getBottom()).thenReturn(200);
when(shape.getGroup()).thenReturn(group);
when(shape.getJochreImage()).thenReturn(jochreImage);
when(group.getRow()).thenReturn(row);
when(row.getParagraph()).thenReturn(paragraph);
when(paragraph.getImage()).thenReturn(jochreImage);
when(jochreImage.getPage()).thenReturn(jochrePage);
when(jochrePage.getDocument()).thenReturn(jochreDocument);
when(jochreDocument.getLocale()).thenReturn(jochreSession.getLocale());
when(shape.getSplits()).thenReturn(splits);
when(splits.iterator()).thenReturn(i);
when(i.hasNext()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
when(i.next()).thenReturn(split1).thenReturn(split2).thenReturn(split3);
when(split1.getPosition()).thenReturn(35);
when(split2.getPosition()).thenReturn(59);
when(split3.getPosition()).thenReturn(82);
when(jochreImage.getShape(100, 100, 135, 200)).thenReturn(shape1);
when(jochreImage.getShape(136, 100, 159, 200)).thenReturn(shape2);
when(jochreImage.getShape(160, 100, 182, 200)).thenReturn(shape3);
when(jochreImage.getShape(183, 100, 200, 200)).thenReturn(shape4);
LOG.debug(shape.toString());
LOG.debug(shape.getLetter());
TrainingCorpusShapeSplitter splitter = new TrainingCorpusShapeSplitter(jochreSession);
List<ShapeSequence> result = splitter.split(shape);
ShapeSequence shapeSequence = result.get(0);
assertEquals(4, shapeSequence.size());
LOG.debug("Split into: " + shapeSequence.toString());
verify(shape1).setLetter("אָ");
verify(shape2).setLetter("בּ");
verify(shape3).setLetter("ע");
verify(shape4).setLetter("ר");
}
use of com.joliciel.jochre.JochreSession in project jochre by urieli.
the class UpdateDocumentController method doAfterCompose.
@Override
public void doAfterCompose(Window window) throws Exception {
super.doAfterCompose(window);
Session session = Sessions.getCurrent();
User user = (User) session.getAttribute(LoginController.SESSION_JOCHRE_USER);
if (user == null)
Executions.sendRedirect("login.zul");
DocumentDao documentDao = DocumentDao.getInstance(jochreSession);
List<Author> authors = documentDao.findAuthors();
List<Comboitem> authorItems = cmbAuthors.getItems();
for (Author author : authors) {
Comboitem item = new Comboitem(author.getFullName());
item.setValue(author.getId());
authorItems.add(item);
}
lstAuthors.setItemRenderer(new AuthorListItemRenderer());
winUpdateDocument.addEventListener("onModalOpen", new UpdateDocumentControllerModalListener());
}
use of com.joliciel.jochre.JochreSession 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();
}
Aggregations