You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/12/20 21:32:52 UTC

[1/4] tika git commit: [TIKA-2189] fix for Default value mismatch for "enableImageProcessing" in TesseractOCRConfig.properties and TesseractOCRConfig.java

Repository: tika
Updated Branches:
  refs/heads/master 2dbd65122 -> ae44b9e50


[TIKA-2189] fix for Default value mismatch for "enableImageProcessing" in TesseractOCRConfig.properties and TesseractOCRConfig.java


Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/40401e51
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/40401e51
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/40401e51

Branch: refs/heads/master
Commit: 40401e51b8a135634f54c8c437dafc10378059be
Parents: 99b5924
Author: dasbipulkumar <ku...@gmail.com>
Authored: Fri Dec 2 18:49:08 2016 +0530
Committer: dasbipulkumar <ku...@gmail.com>
Committed: Fri Dec 2 18:51:47 2016 +0530

----------------------------------------------------------------------
 .../org/apache/tika/parser/ocr/TesseractOCRConfig.properties       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tika/blob/40401e51/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
----------------------------------------------------------------------
diff --git a/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties b/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
index 2380282..ddcd473 100644
--- a/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
+++ b/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
@@ -24,7 +24,7 @@ outputType=txt
 
 # properties for image processing
 # to enable processing, set enableImageProcessing to 1
-enableImageProcessing=1
+enableImageProcessing=0
 ImageMagickPath=
 density=300
 depth=4


[3/4] tika git commit: clean up tabs

Posted by ta...@apache.org.
clean up tabs


Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/c83f87b2
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/c83f87b2
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/c83f87b2

Branch: refs/heads/master
Commit: c83f87b2acc6a8fb69dc37991d43542367154c1a
Parents: 8e12ebe
Author: tballison <ta...@mitre.org>
Authored: Tue Dec 20 15:16:35 2016 -0500
Committer: tballison <ta...@mitre.org>
Committed: Tue Dec 20 15:16:35 2016 -0500

----------------------------------------------------------------------
 .../tika/parser/ocr/TesseractOCRConfig.java     | 808 ++++++++++---------
 1 file changed, 415 insertions(+), 393 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tika/blob/c83f87b2/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
----------------------------------------------------------------------
diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
index 7d6cd3f..a08b0e2 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
@@ -25,169 +25,172 @@ import java.util.Properties;
 
 /**
  * Configuration for TesseractOCRParser.
- *
+ * <p>
  * This allows to enable TesseractOCRParser and set its parameters:
  * <p>
  * TesseractOCRConfig config = new TesseractOCRConfig();<br>
  * config.setTesseractPath(tesseractFolder);<br>
  * parseContext.set(TesseractOCRConfig.class, config);<br>
  * </p>
- *
+ * <p>
  * Parameters can also be set by either editing the existing TesseractOCRConfig.properties file in,
  * tika-parser/src/main/resources/org/apache/tika/parser/ocr, or overriding it by creating your own
  * and placing it in the package org/apache/tika/parser/ocr on the classpath.
- *
  */
-public class TesseractOCRConfig implements Serializable{
+public class TesseractOCRConfig implements Serializable {
 
-	private static final long serialVersionUID = -4861942486845757891L;
+    private static final long serialVersionUID = -4861942486845757891L;
 
-	public enum OUTPUT_TYPE {
-		TXT,
-		HOCR
-	}
+    public enum OUTPUT_TYPE {
+        TXT,
+        HOCR
+    }
 
-	// Path to tesseract installation folder, if not on system path.
-	private  String tesseractPath = "";
+    // Path to tesseract installation folder, if not on system path.
+    private String tesseractPath = "";
 
     // Path to the 'tessdata' folder, which contains language files and config files.
     private String tessdataPath = "";
 
-	// Language dictionary to be used.
-	private  String language = "eng";
-
-	// Tesseract page segmentation mode.
-	private  String pageSegMode = "1";
-
-	// Minimum file size to submit file to ocr.
-	private  int minFileSizeToOcr = 0;
-
-	// Maximum file size to submit file to ocr.
-	private  int maxFileSizeToOcr = Integer.MAX_VALUE;
-
-	// Maximum time (seconds) to wait for the ocring process termination
-	private int timeout = 120;
-	
-	// The format of the ocr'ed output to be returned, txt or hocr.
-	private OUTPUT_TYPE outputType = OUTPUT_TYPE.TXT;
-
-	// enable image processing (optional)
-	private int enableImageProcessing = 0;
-
-	// Path to ImageMagick program, if not on system path.
-	private String ImageMagickPath = "";
-	
-	// resolution of processed image (in dpi).
-	private int density = 300;
-	
-	// number of bits in a color sample within a pixel.
-	private int depth = 4;
-	
-	// colorspace of processed image.
-	private String colorspace = "gray";
-	
-	// filter to be applied to the processed image.
-	private String filter = "triangle";
-	
-	// factor by which image is to be scaled.
-	private int resize = 900;
-	
-	/**
-	 * Default contructor.
-	 */
-	public TesseractOCRConfig() {
-		init(this.getClass().getResourceAsStream("TesseractOCRConfig.properties"));
-	}
-
-	/**
-	 * Loads properties from InputStream and then tries to close InputStream.
-	 * If there is an IOException, this silently swallows the exception
-	 * and goes back to the default.
-	 *
-	 * @param is
-	 */
-	public TesseractOCRConfig(InputStream is) {
-		init(is);
-	}
-
-	private void init(InputStream is) {
-		if (is == null) {
-			return;
-		}
-		Properties props = new Properties();
-		try {
-			props.load(is);
-		} catch (IOException e) {
-		} finally {
-			if (is != null) {
-				try {
-					is.close();
-				} catch (IOException e) {
-					//swallow
-				}
-			}
-		}
-
-		// set parameters for Tesseract
-		setTesseractPath(
-				getProp(props, "tesseractPath", getTesseractPath()));
+    // Language dictionary to be used.
+    private String language = "eng";
+
+    // Tesseract page segmentation mode.
+    private String pageSegMode = "1";
+
+    // Minimum file size to submit file to ocr.
+    private int minFileSizeToOcr = 0;
+
+    // Maximum file size to submit file to ocr.
+    private int maxFileSizeToOcr = Integer.MAX_VALUE;
+
+    // Maximum time (seconds) to wait for the ocring process termination
+    private int timeout = 120;
+
+    // The format of the ocr'ed output to be returned, txt or hocr.
+    private OUTPUT_TYPE outputType = OUTPUT_TYPE.TXT;
+
+    // enable image processing (optional)
+    private int enableImageProcessing = 0;
+
+    // Path to ImageMagick program, if not on system path.
+    private String ImageMagickPath = "";
+
+    // resolution of processed image (in dpi).
+    private int density = 300;
+
+    // number of bits in a color sample within a pixel.
+    private int depth = 4;
+
+    // colorspace of processed image.
+    private String colorspace = "gray";
+
+    // filter to be applied to the processed image.
+    private String filter = "triangle";
+
+    // factor by which image is to be scaled.
+    private int resize = 900;
+
+    /**
+     * Default contructor.
+     */
+    public TesseractOCRConfig() {
+        init(this.getClass().getResourceAsStream("TesseractOCRConfig.properties"));
+    }
+
+    /**
+     * Loads properties from InputStream and then tries to close InputStream.
+     * If there is an IOException, this silently swallows the exception
+     * and goes back to the default.
+     *
+     * @param is
+     */
+    public TesseractOCRConfig(InputStream is) {
+        init(is);
+    }
+
+    private void init(InputStream is) {
+        if (is == null) {
+            return;
+        }
+        Properties props = new Properties();
+        try {
+            props.load(is);
+        } catch (IOException e) {
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    //swallow
+                }
+            }
+        }
+
+        // set parameters for Tesseract
+        setTesseractPath(
+                getProp(props, "tesseractPath", getTesseractPath()));
         setTessdataPath(
                 getProp(props, "tessdataPath", getTessdataPath()));
-		setLanguage(
-				getProp(props, "language", getLanguage()));
-		setPageSegMode(
-				getProp(props, "pageSegMode", getPageSegMode()));
-		setMinFileSizeToOcr(
-				getProp(props, "minFileSizeToOcr", getMinFileSizeToOcr()));
-		setMaxFileSizeToOcr(
-				getProp(props, "maxFileSizeToOcr", getMaxFileSizeToOcr()));
-		setTimeout(
+        setLanguage(
+                getProp(props, "language", getLanguage()));
+        setPageSegMode(
+                getProp(props, "pageSegMode", getPageSegMode()));
+        setMinFileSizeToOcr(
+                getProp(props, "minFileSizeToOcr", getMinFileSizeToOcr()));
+        setMaxFileSizeToOcr(
+                getProp(props, "maxFileSizeToOcr", getMaxFileSizeToOcr()));
+        setTimeout(
                 getProp(props, "timeout", getTimeout()));
-		String outputTypeString = props.getProperty("outputType");
-		if ("txt".equals(outputTypeString)) {
-			setOutputType(OUTPUT_TYPE.TXT);
-		} else if ("hocr".equals(outputTypeString)) {
-			setOutputType(OUTPUT_TYPE.HOCR);
-		}
-
-		// set parameters for ImageMagick
-		setEnableImageProcessing(
-				getProp(props, "enableImageProcessing", isEnableImageProcessing()));
-		setImageMagickPath(
-				getProp(props, "ImageMagickPath", getImageMagickPath()));
-		setDensity(
-				getProp(props, "density", getDensity()));
-		setDepth(
-				getProp(props, "depth", getDepth()));
-		setColorspace(
-				getProp(props, "colorspace", getColorspace()));
-		setFilter(
-				getProp(props, "filter", getFilter()));
-		setResize(
-				getProp(props, "resize", getResize()));
-
-	}
-
-	/** @see #setTesseractPath(String tesseractPath)*/
-	public String getTesseractPath() {
-		return tesseractPath;
-	}
-
-	/**
-	 * Set the path to the Tesseract executable, needed if it is not on system path.
+        String outputTypeString = props.getProperty("outputType");
+        if ("txt".equals(outputTypeString)) {
+            setOutputType(OUTPUT_TYPE.TXT);
+        } else if ("hocr".equals(outputTypeString)) {
+            setOutputType(OUTPUT_TYPE.HOCR);
+        }
+
+        // set parameters for ImageMagick
+        setEnableImageProcessing(
+                getProp(props, "enableImageProcessing", isEnableImageProcessing()));
+        setImageMagickPath(
+                getProp(props, "ImageMagickPath", getImageMagickPath()));
+        setDensity(
+                getProp(props, "density", getDensity()));
+        setDepth(
+                getProp(props, "depth", getDepth()));
+        setColorspace(
+                getProp(props, "colorspace", getColorspace()));
+        setFilter(
+                getProp(props, "filter", getFilter()));
+        setResize(
+                getProp(props, "resize", getResize()));
+
+    }
+
+    /**
+     * @see #setTesseractPath(String tesseractPath)
+     */
+    public String getTesseractPath() {
+        return tesseractPath;
+    }
+
+    /**
+     * Set the path to the Tesseract executable, needed if it is not on system path.
      * <p>
      * Note that if you set this value, it is highly recommended that you also
      * set the path to the 'tessdata' folder using {@link #setTessdataPath}.
      * </p>
-	 */
-	public void setTesseractPath(String tesseractPath) {
-		if(!tesseractPath.isEmpty() && !tesseractPath.endsWith(File.separator))
-			tesseractPath += File.separator;
+     */
+    public void setTesseractPath(String tesseractPath) {
+        if (!tesseractPath.isEmpty() && !tesseractPath.endsWith(File.separator))
+            tesseractPath += File.separator;
 
-		this.tesseractPath = tesseractPath;
-	}
+        this.tesseractPath = tesseractPath;
+    }
 
-    /** @see #setTessdataPath(String tessdataPath) */
+    /**
+     * @see #setTessdataPath(String tessdataPath)
+     */
     public String getTessdataPath() {
         return tessdataPath;
     }
@@ -198,265 +201,284 @@ public class TesseractOCRConfig implements Serializable{
      * (such as when Tesseract is built from source), it may be located elsewhere.
      */
     public void setTessdataPath(String tessdataPath) {
-        if(!tessdataPath.isEmpty() && !tessdataPath.endsWith(File.separator))
+        if (!tessdataPath.isEmpty() && !tessdataPath.endsWith(File.separator))
             tessdataPath += File.separator;
 
         this.tessdataPath = tessdataPath;
     }
 
-	/** @see #setLanguage(String language)*/
-	public String getLanguage() {
-		return language;
-	}
-
-	/**
-	 * Set tesseract language dictionary to be used. Default is "eng".
-	 * Multiple languages may be specified, separated by plus characters.
-	 */
-	public void setLanguage(String language) {
-		if (!language.matches("([A-Za-z](\\+?))*")) {
-			throw new IllegalArgumentException("Invalid language code");
-		}
-		this.language = language;
-	}
-
-	/** @see #setPageSegMode(String pageSegMode)*/
-	public String getPageSegMode() {
-		return pageSegMode;
-	}
-
-	/**
-	 * Set tesseract page segmentation mode.
-	 * Default is 1 = Automatic page segmentation with OSD (Orientation and Script Detection)
-	 */
-	public void setPageSegMode(String pageSegMode) {
-		if (!pageSegMode.matches("[1-9]|10")) {
-			throw new IllegalArgumentException("Invalid language code");
-		}
-		this.pageSegMode = pageSegMode;
-	}
-
-	/** @see #setMinFileSizeToOcr(int minFileSizeToOcr)*/
-	public int getMinFileSizeToOcr() {
-		return minFileSizeToOcr;
-	}
-
-	/**
-	 * Set minimum file size to submit file to ocr.
-	 * Default is 0.
-	 */
-	public void setMinFileSizeToOcr(int minFileSizeToOcr) {
-		this.minFileSizeToOcr = minFileSizeToOcr;
-	}
-
-	/** @see #setMaxFileSizeToOcr(int maxFileSizeToOcr)*/
-	public int getMaxFileSizeToOcr() {
-		return maxFileSizeToOcr;
-	}
-
-	/**
-	 * Set maximum file size to submit file to ocr.
-	 * Default is Integer.MAX_VALUE.
-	 */
-	public void setMaxFileSizeToOcr(int maxFileSizeToOcr) {
-		this.maxFileSizeToOcr = maxFileSizeToOcr;
-	}
-
-	/**
-	 * Set maximum time (seconds) to wait for the ocring process to terminate.
-	 * Default value is 120s.
-	 */
-	public void setTimeout(int timeout) {
-		this.timeout = timeout;
-	}
-
-	/** @see #setTimeout(int timeout)
-	 * @return timeout value for Tesseract */
-	public int getTimeout() {
-		return timeout;
-	}	
-	
-	/**
-	 * Set output type from ocr process.  Default is "txt", but can be "hocr".
-	 * Default value is 120s.
-	 */
-	public void setOutputType(OUTPUT_TYPE outputType) {
-		this.outputType = outputType;
-	}
-
-	/** @see #setOutputType(OUTPUT_TYPE outputType) */
-	public OUTPUT_TYPE getOutputType() {
-		return outputType;
-	}	
-
-	/** @see #setEnableImageProcessing(int)
-	 * @return image processing is enabled or not */
-	public int isEnableImageProcessing() {
-		return enableImageProcessing;
-	}
-
-	/** 
-	 * Set the value to true if processing is to be enabled.
-	 * Default value is false.
-	 */
-	public void setEnableImageProcessing(int enableImageProcessing) {
-		this.enableImageProcessing = enableImageProcessing;
-	}
-
-	/**
-	 * @return the density
-	 */
-	public int getDensity() {
-		return density;
-	}
-
-	/**
-	 * @param density the density to set. Valid range of values is 150-1200.
-	 * Default value is 300.
-	 */
-	public void setDensity(int density) {
-		if(density < 150 || density > 1200) {
-			throw new IllegalArgumentException("Invalid density value. Valid range of values is 150-1200.");
-		}
-		this.density = density;
-	}
-
-	/**
-	 * @return the depth
-	 */
-	public int getDepth() {
-		return depth;
-	}
-
-	/**
-	 * @param depth the depth to set. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.
-	 * Default value is 4.
-	 */
-	public void setDepth(int depth) {
-		int[] allowedValues = {2, 4, 8, 16, 32, 64, 256, 4096};
-		for (int i = 0; i < allowedValues.length; i++) {
-			if(depth == allowedValues[i]) {
-				this.depth = depth;
-				return;
-			}
-		}
-		throw new IllegalArgumentException("Invalid depth value. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.");
-	}
-
-	/**
-	 * @return the colorspace
-	 */
-	public String getColorspace() {
-		return colorspace;
-	}
-
-	/**
-	 * @param colorspace the colorspace to set
-	 * Deafult value is gray.
-	 */
-	public void setColorspace(String colorspace) {
-		if(!colorspace.equals(null)) {
-			this.colorspace = colorspace;
-		} else {
-			throw new IllegalArgumentException("Colorspace value cannot be null.");
-		}
-	}
-
-	/**
-	 * @return the filter
-	 */
-	public String getFilter() {
-		return filter;
-	}
-
-	/**
-	 * @param filter the filter to set. Valid values are point, hermite, cubic, box, gaussian, catrom, triangle, quadratic and mitchell.
-	 * Default value is triangle.
-	 */
-	public void setFilter(String filter) {
-		if(filter.equals(null)) {
-			throw new IllegalArgumentException("Filter value cannot be null. Valid values are point, hermite, "
-					+ "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
-		}
-		
-		String[] allowedFilters = {"Point", "Hermite", "Cubic", "Box", "Gaussian", "Catrom", "Triangle", "Quadratic", "Mitchell"};
-		for (int i = 0; i < allowedFilters.length; i++) {
-			if(filter.equalsIgnoreCase(allowedFilters[i])) {
-				this.filter = filter;
-				return;
-			}
-		}
-		throw new IllegalArgumentException("Invalid filter value. Valid values are point, hermite, "
-					+ "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
-	}
-
-	/**
-	 * @return the resize
-	 */
-	public int getResize() {
-		return resize;
-	}
-
-	/**
-	 * @param resize the resize to set. Valid range of values is 100-900.
-	 * Default value is 900.
-	 */
-	public void setResize(int resize) {
-		for(int i=1;i<10;i++) {
-			if(resize == i*100) {
-				this.resize = resize;
-				return;
-			}
-		}
-		throw new IllegalArgumentException("Invalid resize value. Valid range of values is 100-900.");
-	}
-
-	/** @see #setImageMagickPath(String ImageMagickPath)
-	 * @return path to ImageMagick file. */
-	public String getImageMagickPath() {
-		
-		return ImageMagickPath;
-	}
-	
-	/**
-	 * Set the path to the ImageMagick executable, needed if it is not on system path.
-	 * @param ImageMagickPath to ImageMagick file.
-	 */
-	public void setImageMagickPath(String ImageMagickPath) {
-		if(!ImageMagickPath.isEmpty() && !ImageMagickPath.endsWith(File.separator))
-			ImageMagickPath += File.separator;
-		
-		this.ImageMagickPath = ImageMagickPath;
-	}
-	
-	/**
-	 * Get property from the properties file passed in.
-	 * @param properties properties file to read from.
-	 * @param property the property to fetch.
-	 * @param defaultMissing default parameter to use.
-	 * @return the value.
-	 */
-	private int getProp(Properties properties, String property, int defaultMissing) {
-		String p = properties.getProperty(property);
-		if (p == null || p.isEmpty()){
-			return defaultMissing;
-		}
-		try {
-			return Integer.parseInt(p);
-		} catch (Throwable ex) {
-			throw new RuntimeException(String.format(Locale.ROOT, "Cannot parse TesseractOCRConfig variable %s, invalid integer value",
-					property), ex);
-		}
-	}
-
-	/**
-	 * Get property from the properties file passed in.
-	 * @param properties properties file to read from.
-	 * @param property the property to fetch.
-	 * @param defaultMissing default parameter to use.
-	 * @return the value.
-	 */
-	private String getProp(Properties properties, String property, String defaultMissing) {
-		return properties.getProperty(property, defaultMissing);
-	}
+    /**
+     * @see #setLanguage(String language)
+     */
+    public String getLanguage() {
+        return language;
+    }
+
+    /**
+     * Set tesseract language dictionary to be used. Default is "eng".
+     * Multiple languages may be specified, separated by plus characters.
+     */
+    public void setLanguage(String language) {
+        if (!language.matches("([A-Za-z](\\+?))*")) {
+            throw new IllegalArgumentException("Invalid language code");
+        }
+        this.language = language;
+    }
+
+    /**
+     * @see #setPageSegMode(String pageSegMode)
+     */
+    public String getPageSegMode() {
+        return pageSegMode;
+    }
+
+    /**
+     * Set tesseract page segmentation mode.
+     * Default is 1 = Automatic page segmentation with OSD (Orientation and Script Detection)
+     */
+    public void setPageSegMode(String pageSegMode) {
+        if (!pageSegMode.matches("[1-9]|10")) {
+            throw new IllegalArgumentException("Invalid language code");
+        }
+        this.pageSegMode = pageSegMode;
+    }
+
+    /**
+     * @see #setMinFileSizeToOcr(int minFileSizeToOcr)
+     */
+    public int getMinFileSizeToOcr() {
+        return minFileSizeToOcr;
+    }
+
+    /**
+     * Set minimum file size to submit file to ocr.
+     * Default is 0.
+     */
+    public void setMinFileSizeToOcr(int minFileSizeToOcr) {
+        this.minFileSizeToOcr = minFileSizeToOcr;
+    }
+
+    /**
+     * @see #setMaxFileSizeToOcr(int maxFileSizeToOcr)
+     */
+    public int getMaxFileSizeToOcr() {
+        return maxFileSizeToOcr;
+    }
+
+    /**
+     * Set maximum file size to submit file to ocr.
+     * Default is Integer.MAX_VALUE.
+     */
+    public void setMaxFileSizeToOcr(int maxFileSizeToOcr) {
+        this.maxFileSizeToOcr = maxFileSizeToOcr;
+    }
+
+    /**
+     * Set maximum time (seconds) to wait for the ocring process to terminate.
+     * Default value is 120s.
+     */
+    public void setTimeout(int timeout) {
+        this.timeout = timeout;
+    }
+
+    /**
+     * @return timeout value for Tesseract
+     * @see #setTimeout(int timeout)
+     */
+    public int getTimeout() {
+        return timeout;
+    }
+
+    /**
+     * Set output type from ocr process.  Default is "txt", but can be "hocr".
+     * Default value is 120s.
+     */
+    public void setOutputType(OUTPUT_TYPE outputType) {
+        this.outputType = outputType;
+    }
+
+    /**
+     * @see #setOutputType(OUTPUT_TYPE outputType)
+     */
+    public OUTPUT_TYPE getOutputType() {
+        return outputType;
+    }
+
+    /**
+     * @return image processing is enabled or not
+     * @see #setEnableImageProcessing(int)
+     */
+    public int isEnableImageProcessing() {
+        return enableImageProcessing;
+    }
+
+    /**
+     * Set the value to true if processing is to be enabled.
+     * Default value is false.
+     */
+    public void setEnableImageProcessing(int enableImageProcessing) {
+        this.enableImageProcessing = enableImageProcessing;
+    }
+
+    /**
+     * @return the density
+     */
+    public int getDensity() {
+        return density;
+    }
+
+    /**
+     * @param density the density to set. Valid range of values is 150-1200.
+     *                Default value is 300.
+     */
+    public void setDensity(int density) {
+        if (density < 150 || density > 1200) {
+            throw new IllegalArgumentException("Invalid density value. Valid range of values is 150-1200.");
+        }
+        this.density = density;
+    }
+
+    /**
+     * @return the depth
+     */
+    public int getDepth() {
+        return depth;
+    }
+
+    /**
+     * @param depth the depth to set. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.
+     *              Default value is 4.
+     */
+    public void setDepth(int depth) {
+        int[] allowedValues = {2, 4, 8, 16, 32, 64, 256, 4096};
+        for (int i = 0; i < allowedValues.length; i++) {
+            if (depth == allowedValues[i]) {
+                this.depth = depth;
+                return;
+            }
+        }
+        throw new IllegalArgumentException("Invalid depth value. Valid values are 2, 4, 8, 16, 32, 64, 256, 4096.");
+    }
+
+    /**
+     * @return the colorspace
+     */
+    public String getColorspace() {
+        return colorspace;
+    }
+
+    /**
+     * @param colorspace the colorspace to set
+     *                   Deafult value is gray.
+     */
+    public void setColorspace(String colorspace) {
+        if (!colorspace.equals(null)) {
+            this.colorspace = colorspace;
+        } else {
+            throw new IllegalArgumentException("Colorspace value cannot be null.");
+        }
+    }
+
+    /**
+     * @return the filter
+     */
+    public String getFilter() {
+        return filter;
+    }
+
+    /**
+     * @param filter the filter to set. Valid values are point, hermite, cubic, box, gaussian, catrom, triangle, quadratic and mitchell.
+     *               Default value is triangle.
+     */
+    public void setFilter(String filter) {
+        if (filter.equals(null)) {
+            throw new IllegalArgumentException("Filter value cannot be null. Valid values are point, hermite, "
+                    + "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
+        }
+
+        String[] allowedFilters = {"Point", "Hermite", "Cubic", "Box", "Gaussian", "Catrom", "Triangle", "Quadratic", "Mitchell"};
+        for (int i = 0; i < allowedFilters.length; i++) {
+            if (filter.equalsIgnoreCase(allowedFilters[i])) {
+                this.filter = filter;
+                return;
+            }
+        }
+        throw new IllegalArgumentException("Invalid filter value. Valid values are point, hermite, "
+                + "cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
+    }
+
+    /**
+     * @return the resize
+     */
+    public int getResize() {
+        return resize;
+    }
+
+    /**
+     * @param resize the resize to set. Valid range of values is 100-900.
+     *               Default value is 900.
+     */
+    public void setResize(int resize) {
+        for (int i = 1; i < 10; i++) {
+            if (resize == i * 100) {
+                this.resize = resize;
+                return;
+            }
+        }
+        throw new IllegalArgumentException("Invalid resize value. Valid range of values is 100-900.");
+    }
+
+    /**
+     * @return path to ImageMagick file.
+     * @see #setImageMagickPath(String ImageMagickPath)
+     */
+    public String getImageMagickPath() {
+
+        return ImageMagickPath;
+    }
+
+    /**
+     * Set the path to the ImageMagick executable, needed if it is not on system path.
+     *
+     * @param ImageMagickPath to ImageMagick file.
+     */
+    public void setImageMagickPath(String ImageMagickPath) {
+        if (!ImageMagickPath.isEmpty() && !ImageMagickPath.endsWith(File.separator))
+            ImageMagickPath += File.separator;
+
+        this.ImageMagickPath = ImageMagickPath;
+    }
+
+    /**
+     * Get property from the properties file passed in.
+     *
+     * @param properties     properties file to read from.
+     * @param property       the property to fetch.
+     * @param defaultMissing default parameter to use.
+     * @return the value.
+     */
+    private int getProp(Properties properties, String property, int defaultMissing) {
+        String p = properties.getProperty(property);
+        if (p == null || p.isEmpty()) {
+            return defaultMissing;
+        }
+        try {
+            return Integer.parseInt(p);
+        } catch (Throwable ex) {
+            throw new RuntimeException(String.format(Locale.ROOT, "Cannot parse TesseractOCRConfig variable %s, invalid integer value",
+                    property), ex);
+        }
+    }
+
+    /**
+     * Get property from the properties file passed in.
+     *
+     * @param properties     properties file to read from.
+     * @param property       the property to fetch.
+     * @param defaultMissing default parameter to use.
+     * @return the value.
+     */
+    private String getProp(Properties properties, String property, String defaultMissing) {
+        return properties.getProperty(property, defaultMissing);
+    }
 }


[4/4] tika git commit: TIKA-2190 -- add configurability for preserve interword spacing

Posted by ta...@apache.org.
TIKA-2190 -- add configurability for preserve interword spacing


Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/ae44b9e5
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/ae44b9e5
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/ae44b9e5

Branch: refs/heads/master
Commit: ae44b9e507dbb11b9b9f5c57cf342b47966ffb66
Parents: c83f87b
Author: tballison <ta...@mitre.org>
Authored: Tue Dec 20 16:32:44 2016 -0500
Committer: tballison <ta...@mitre.org>
Committed: Tue Dec 20 16:32:44 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |   3 ++
 .../tika/parser/ocr/TesseractOCRConfig.java     |  38 +++++++++++++++++++
 .../tika/parser/ocr/TesseractOCRParser.java     |  10 +++--
 .../parser/ocr/TesseractOCRConfig.properties    |   1 +
 .../tika/parser/ocr/TesseractOCRParserTest.java |  22 +++++++++++
 .../test-documents/testOCR_spacing.png          | Bin 0 -> 7232 bytes
 6 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e215499..bd6a45e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,8 @@
 Release 1.15 - ??
 
+  * Add configurability of "preserve-interword-spacing" to
+    TesseractOCRParser (TIKA-2190).
+
   * Added experimental SAX parser for .pptx files. To select this parser,
     set useSAXPptxExtractor(true) on OfficeParserConfig (TIKA-2210).
 

http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
----------------------------------------------------------------------
diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
index a08b0e2..27853d3 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRConfig.java
@@ -91,6 +91,10 @@ public class TesseractOCRConfig implements Serializable {
     // factor by which image is to be scaled.
     private int resize = 900;
 
+    // whether or not to preserve interword spacing
+    private boolean preserveInterwordSpacing = false;
+
+
     /**
      * Default contructor.
      */
@@ -148,6 +152,7 @@ public class TesseractOCRConfig implements Serializable {
         } else if ("hocr".equals(outputTypeString)) {
             setOutputType(OUTPUT_TYPE.HOCR);
         }
+        setPreserveInterwordSpacing(getProp(props, "preserveInterwordSpacing", false));
 
         // set parameters for ImageMagick
         setEnableImageProcessing(
@@ -244,6 +249,22 @@ public class TesseractOCRConfig implements Serializable {
     }
 
     /**
+     * Whether or not to maintain interword spacing.  Default is <code>false</code>.
+     *
+     * @param preserveInterwordSpacing
+     */
+    public void setPreserveInterwordSpacing(boolean preserveInterwordSpacing) {
+        this.preserveInterwordSpacing = preserveInterwordSpacing;
+    }
+
+    /**
+     *
+     * @return whether or not to maintain interword spacing.
+     */
+    public boolean getPreserveInterwordSpacing() {
+        return preserveInterwordSpacing;
+    }
+    /**
      * @see #setMinFileSizeToOcr(int minFileSizeToOcr)
      */
     public int getMinFileSizeToOcr() {
@@ -481,4 +502,21 @@ public class TesseractOCRConfig implements Serializable {
     private String getProp(Properties properties, String property, String defaultMissing) {
         return properties.getProperty(property, defaultMissing);
     }
+
+    private boolean getProp(Properties properties, String property, boolean defaultMissing) {
+        String propVal = properties.getProperty(property);
+        if (propVal == null) {
+            return defaultMissing;
+        }
+        if (propVal.equalsIgnoreCase("true")) {
+            return true;
+        } else if (propVal.equalsIgnoreCase("false")) {
+            return false;
+        }
+
+        throw new RuntimeException(String.format(Locale.ROOT,
+                "Cannot parse TesseractOCRConfig variable %s, invalid boolean value: %s",
+                property, propVal));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
----------------------------------------------------------------------
diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
index ffbef1c..46a3f55 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
@@ -417,9 +417,12 @@ public class TesseractOCRParser extends AbstractParser {
      *           if an input error occurred
      */
     private void doOCR(File input, File output, TesseractOCRConfig config) throws IOException, TikaException {
-        String[] cmd = { config.getTesseractPath() + getTesseractProg(), input.getPath(), output.getPath(), "-l",
-                config.getLanguage(), "-psm", config.getPageSegMode(), config.getOutputType().name().toLowerCase(Locale.US)};
 
+        String[] cmd = { config.getTesseractPath() + getTesseractProg(), input.getPath(), output.getPath(), "-l",
+                config.getLanguage(), "-psm", config.getPageSegMode(),
+                config.getOutputType().name().toLowerCase(Locale.US),
+                "-c",
+                (config.getPreserveInterwordSpacing())? "preserve_interword_spaces=1" : "preserve_interword_spaces=0"};
         ProcessBuilder pb = new ProcessBuilder(cmd);
         setEnv(config, pb);
         final Process process = pb.start();
@@ -479,8 +482,9 @@ public class TesseractOCRParser extends AbstractParser {
         try (Reader reader = new InputStreamReader(stream, UTF_8)) {
             char[] buffer = new char[1024];
             for (int n = reader.read(buffer); n != -1; n = reader.read(buffer)) {
-                if (n > 0)
+                if (n > 0) {
                     xhtml.characters(buffer, 0, n);
+                }
             }
         }
         xhtml.endElement("div");

http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
----------------------------------------------------------------------
diff --git a/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties b/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
index ddcd473..3cc2bcd 100644
--- a/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
+++ b/tika-parsers/src/main/resources/org/apache/tika/parser/ocr/TesseractOCRConfig.properties
@@ -21,6 +21,7 @@ maxFileSizeToOcr=2147483647
 minFileSizeToOcr=0
 timeout=120
 outputType=txt
+preserveInterwordSpacing=false
 
 # properties for image processing
 # to enable processing, set enableImageProcessing to 1

http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/tika-parsers/src/test/java/org/apache/tika/parser/ocr/TesseractOCRParserTest.java
----------------------------------------------------------------------
diff --git a/tika-parsers/src/test/java/org/apache/tika/parser/ocr/TesseractOCRParserTest.java b/tika-parsers/src/test/java/org/apache/tika/parser/ocr/TesseractOCRParserTest.java
index e0f89ac..4c0ab76 100644
--- a/tika-parsers/src/test/java/org/apache/tika/parser/ocr/TesseractOCRParserTest.java
+++ b/tika-parsers/src/test/java/org/apache/tika/parser/ocr/TesseractOCRParserTest.java
@@ -23,6 +23,8 @@ import static org.junit.Assume.assumeTrue;
 
 import java.io.InputStream;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.tika.TikaTest;
 import org.apache.tika.metadata.Metadata;
@@ -256,4 +258,24 @@ public class TesseractOCRParserTest extends TikaTest {
     }
 
     //TODO: add unit tests for jp2/jpx/ppm TIKA-2174
+
+    @Test
+    public void testInterwordSpacing() throws Exception {
+        assumeTrue(canRun());
+        //default
+        String xml = getXML("testOCR_spacing.png").xml;
+        assertContains("The quick", xml);
+
+        TesseractOCRConfig tesseractOCRConfigconfig = new TesseractOCRConfig();
+        tesseractOCRConfigconfig.setPreserveInterwordSpacing(true);
+        ParseContext parseContext = new ParseContext();
+        parseContext.set(TesseractOCRConfig.class, tesseractOCRConfigconfig);
+
+        //with preserve interwordspacing "on"
+        //allow some flexibility in case Tesseract is computing spaces
+        //somewhat differently in different versions/OS's, etc.
+        xml = getXML("testOCR_spacing.png", parseContext).xml;
+        Matcher m = Pattern.compile("The\\s{5,20}quick").matcher(xml);
+        assertTrue(m.find());
+    }
 }

http://git-wip-us.apache.org/repos/asf/tika/blob/ae44b9e5/tika-parsers/src/test/resources/test-documents/testOCR_spacing.png
----------------------------------------------------------------------
diff --git a/tika-parsers/src/test/resources/test-documents/testOCR_spacing.png b/tika-parsers/src/test/resources/test-documents/testOCR_spacing.png
new file mode 100644
index 0000000..10a7e40
Binary files /dev/null and b/tika-parsers/src/test/resources/test-documents/testOCR_spacing.png differ


[2/4] tika git commit: Merge branch 'bug_TIKA-2189' of https://github.com/dasbipulkumar/tika

Posted by ta...@apache.org.
Merge branch 'bug_TIKA-2189' of https://github.com/dasbipulkumar/tika


Project: http://git-wip-us.apache.org/repos/asf/tika/repo
Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/8e12ebea
Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/8e12ebea
Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/8e12ebea

Branch: refs/heads/master
Commit: 8e12ebea4178048373c3c946eb159d6f68baa4e9
Parents: 2dbd651 40401e5
Author: tballison <ta...@mitre.org>
Authored: Tue Dec 20 15:04:01 2016 -0500
Committer: tballison <ta...@mitre.org>
Committed: Tue Dec 20 15:04:01 2016 -0500

----------------------------------------------------------------------
 .../org/apache/tika/parser/ocr/TesseractOCRConfig.properties       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------