Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
urieli committed Sep 20, 2023
2 parents beb165b + cde7ff6 commit 259f213
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion jochre_core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<build>
Expand Down
18 changes: 10 additions & 8 deletions jochre_core/src/main/java/com/joliciel/jochre/Jochre.java
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,12 @@ public void doCommandTransform(CorpusSelectionCriteria criteria, List<DocumentOb
public void doCommandAnalyse(File sourceFile, MostLikelyWordChooser wordChooser, Set<Integer> pages,
List<DocumentObserver> observers, List<PdfImageObserver> imageObservers) throws IOException {

JochreDocumentGenerator documentGenerator = this.getDocumentGenerator(sourceFile.getName(), wordChooser, pages, observers, imageObservers);
boolean imageFile = sourceFile.getName().toLowerCase().endsWith(".png")
|| sourceFile.getName().toLowerCase().endsWith(".jpg") || sourceFile.getName().toLowerCase().endsWith(".jpeg")
|| sourceFile.getName().toLowerCase().endsWith(".gif") || sourceFile.getName().toLowerCase().endsWith(".tif")
|| sourceFile.getName().toLowerCase().endsWith(".tiff");

JochreDocumentGenerator documentGenerator = this.getDocumentGenerator(sourceFile.getName(), wordChooser, pages, observers, imageObservers, imageFile);

if (!sourceFile.exists())
throw new JochreException("The file " + sourceFile.getPath() + " does not exist");
Expand All @@ -1089,10 +1094,7 @@ public void doCommandAnalyse(File sourceFile, MostLikelyWordChooser wordChooser,
pdfDocumentProcessor.addImageObserver(imageObserver);
}
pdfDocumentProcessor.process();
} else if (sourceFile.getName().toLowerCase().endsWith(".png")
|| sourceFile.getName().toLowerCase().endsWith(".jpg") || sourceFile.getName().toLowerCase().endsWith(".jpeg")
|| sourceFile.getName().toLowerCase().endsWith(".gif") || sourceFile.getName().toLowerCase().endsWith(".tif")
|| sourceFile.getName().toLowerCase().endsWith(".tiff")) {
} else if (imageFile) {
ImageFileDocumentExtractor extractor = new ImageFileDocumentExtractor(sourceFile, documentGenerator);
extractor.extractDocument();
} else if (sourceFile.isDirectory()) {
Expand All @@ -1104,7 +1106,7 @@ public void doCommandAnalyse(File sourceFile, MostLikelyWordChooser wordChooser,
}

private JochreDocumentGenerator getDocumentGenerator(String fileName, MostLikelyWordChooser wordChooser, Set<Integer> pages,
List<DocumentObserver> observers, List<PdfImageObserver> imageObservers) throws IOException {
List<DocumentObserver> observers, List<PdfImageObserver> imageObservers, boolean exitOnError) throws IOException {

ClassificationModel letterModel = jochreSession.getLetterModel();

Expand Down Expand Up @@ -1134,7 +1136,7 @@ private JochreDocumentGenerator getDocumentGenerator(String fileName, MostLikely
ImageAnalyser analyser = new BeamSearchImageAnalyser(boundaryDetector, letterGuesser, wordChooser, jochreSession);
analyser.addObserver(letterGuessObserver);

JochreDocumentGenerator documentGenerator = new JochreDocumentGenerator(fileName, "", jochreSession);
JochreDocumentGenerator documentGenerator = new JochreDocumentGenerator(fileName, "", jochreSession, exitOnError);
documentGenerator.addDocumentObserver(analyser);

for (DocumentObserver observer : observers)
Expand Down Expand Up @@ -1546,7 +1548,7 @@ public void imageToAlto4(BufferedImage image, String fileName, Writer writer) th
List<DocumentObserver> documentObservers = new ArrayList<>();
AltoXMLExporter altoXMLExporter = new AltoXMLExporter(writer, 4);
documentObservers.add(altoXMLExporter);
JochreDocumentGenerator documentGenerator = this.getDocumentGenerator(fileName, wordChooser, myPages, documentObservers, new ArrayList<>());
JochreDocumentGenerator documentGenerator = this.getDocumentGenerator(fileName, wordChooser, myPages, documentObservers, new ArrayList<>(), true);
ImageDocumentExtractor documentExtractor = new ImageDocumentExtractor(image, fileName, documentGenerator);
documentExtractor.extractDocument();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class JochreDocumentGenerator implements SourceFileProcessor, Monitorable
private List<DocumentObserver> documentObservers = new ArrayList<>();

private final JochreSession jochreSession;
private final boolean exitOnError;

/**
* Constructor for existing documents.
Expand All @@ -89,6 +90,7 @@ public class JochreDocumentGenerator implements SourceFileProcessor, Monitorable
public JochreDocumentGenerator(JochreDocument jochreDocument, JochreSession jochreSession) {
this.jochreSession = jochreSession;
this.doc = jochreDocument;
this.exitOnError = false;
}

/**
Expand All @@ -100,9 +102,14 @@ public JochreDocumentGenerator(JochreDocument jochreDocument, JochreSession joch
* user-friendly name for the document (required if saving)
*/
public JochreDocumentGenerator(String filename, String userFriendlyName, JochreSession jochreSession) {
this(filename, userFriendlyName, jochreSession, false);
}

public JochreDocumentGenerator(String filename, String userFriendlyName, JochreSession jochreSession, boolean exitOnError) {
this.jochreSession = jochreSession;
this.filename = filename;
this.userFriendlyName = userFriendlyName;
this.exitOnError = exitOnError;
}

@Override
Expand Down Expand Up @@ -214,6 +221,9 @@ public JochreImage onImageFound(JochrePage jochrePage, BufferedImage image, Stri
} catch (SegmentationException se) {
LOG.error("segmentation failed", se);
sourceImage.clearSegmentation();
if (exitOnError) {
throw se;
}
}

if (currentMonitor != null)
Expand Down
2 changes: 1 addition & 1 deletion jochre_distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<build>
Expand Down
2 changes: 1 addition & 1 deletion jochre_parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<packaging>pom</packaging>
<name>Jochre</name>
<description>Java Optical CHaracter Recognition</description>
Expand Down
2 changes: 1 addition & 1 deletion jochre_search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion jochre_search_webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion jochre_utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<build>
Expand Down
2 changes: 1 addition & 1 deletion jochre_web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion jochre_yiddish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.joliciel.jochre</groupId>
<artifactId>jochre-parent</artifactId>
<version>2.6.3</version>
<version>2.6.4</version>
<relativePath>../jochre_parent</relativePath>
</parent>
<packaging>jar</packaging>
Expand Down

0 comments on commit 259f213

Please sign in to comment.