Class RegexParser
java.lang.Object
com.microblink.photopay.entities.Entity<T>
com.microblink.photopay.entities.parsers.Parser<RegexParser.Result>
com.microblink.photopay.entities.parsers.regex.RegexParser
- All Implemented Interfaces:
android.os.Parcelable
Represents a parser which parses OCR result according to given regular expression.
Regular expression parsing is not performed with java's regex engine. Instead, it is performed
with custom regular expression engine which can work with multiple char recognition alternatives
(if enabled in
AbstractOCREngineOptions
). Due to differences between parsing normal strings
and OCR results, this parser does not support some regex features found in java's regex engine,
like back references. See setRegex(String)
for more information about what is supported.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class com.microblink.photopay.entities.parsers.Parser
CLASS_NAME
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
-
Constructor Summary
ConstructorsConstructorDescriptionRegexParser
(String regex) Constructor using default OCR engine options and provided regular expression.RegexParser
(String regex, AbstractOCREngineOptions ocrEngineOptions) Constructor using provided OCR engine options and provided regular expression. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears parser result.clone()
Create a copy of the entity.void
consumeResult
(RegexParser.Result resultToConsume) Consumes given result.void
consumeResultFrom
(Entity other) Consume result from other entity.protected void
deserializeNativeSettings
(byte[] serializedSettings) Returns the OCR engine options used in Regex OCR parser.getRegex()
Returns the currently set regular expression.protected byte[]
void
setEndWithWhitespace
(boolean mustEndWithWhitespace) If set to true, regex will not be matched if there is no whitespace after matched string.void
setOcrEngineOptions
(AbstractOCREngineOptions ocrEngineOptions) Sets the OCR engine options used in Regex OCR parser.void
Defines regex that will be used to parse OCR data.void
setStartWithWhitespace
(boolean mustStartWithWhitespace) If set to true, regex will not be matched if there is no whitespace before matched string.void
setUseSieve
(boolean useSieve) Enable the usage of algorithm for combining consecutive OCR results between video frames for improving OCR quality.boolean
Returns whether matched string must end with whitespace.boolean
Returns whether matched string must start with whitespace.boolean
Returns true if algorithm for combining consecutive OCR results between video frames for improving OCR quality is used.protected void
terminateNative
(long nativeContext) Methods inherited from class com.microblink.photopay.entities.parsers.Parser
getPriority, isRequired, setRequired
Methods inherited from class com.microblink.photopay.entities.Entity
describeContents, finalize, getNativeContext, getResult, nativeGetNativeResultContext, readFromParcel, writeToParcel
-
Field Details
-
CREATOR
-
-
Constructor Details
-
RegexParser
Constructor using default OCR engine options and provided regular expression. Since default OCR engine options does not have character whitelist, the regex alphabet is empty - this means that '.' metacharacter which represents any character is not supported. To use regular expressions that contain this metacharacter, useRegexParser(String, AbstractOCREngineOptions)
constructor. For more information about regex support, seesetRegex(String)
.- Parameters:
regex
- Regular expression.- Throws:
IllegalArgumentException
- if regular expression cannot be compiled
-
RegexParser
Constructor using provided OCR engine options and provided regular expression. Some regex metacharacters, like '.' (represents any character) may not be supported if provided OCR engine options do not have character whitelist. For more information about regex support, seesetRegex(String)
.- Parameters:
regex
- Regular expression.ocrEngineOptions
- OCR engine options used for performing OCR.- Throws:
IllegalArgumentException
- if regular expression cannot be compiled
-
-
Method Details
-
setRegex
Defines regex that will be used to parse OCR data. Note that not all java regex features are available, such as back references and '^' and '$' meta-character. '.' meta-character that represents any character and '^' inside brackets representing all characters except those in brackets are available only if alphabet is defined.- Parameters:
regex
- Regular expression to be used for parsing OCR result.- Throws:
IllegalArgumentException
- if regular expression cannot be compiled
-
getRegex
Returns the currently set regular expression.- Returns:
- the currently set regular expression.
-
setOcrEngineOptions
Sets the OCR engine options used in Regex OCR parser. By default, this is set to 'default instance ofBlinkOCREngineOptions
'.- Parameters:
ocrEngineOptions
- OCR engine options used in Regex OCR parser
-
getOcrEngineOptions
Returns the OCR engine options used in Regex OCR parser. By default, this is set to 'default instance ofBlinkOCREngineOptions
'.- Returns:
- OCR engine options used in Regex OCR parser
-
setUseSieve
public void setUseSieve(boolean useSieve) Enable the usage of algorithm for combining consecutive OCR results between video frames for improving OCR quality. By default this is turned off. Note: This option works together only with if instance ofBlinkOCREngineOptions
is given tosetOcrEngineOptions(AbstractOCREngineOptions)
. Otherwise, it will not be enabled andIllegalArgumentException
will be thrown.- Parameters:
useSieve
- whether or not sieve algorithm should be used
-
shouldUseSieve
public boolean shouldUseSieve()Returns true if algorithm for combining consecutive OCR results between video frames for improving OCR quality is used.- Returns:
- true if sieve algorithm is used
-
setStartWithWhitespace
public void setStartWithWhitespace(boolean mustStartWithWhitespace) If set to true, regex will not be matched if there is no whitespace before matched string. Whitespace is not returned in parsed result.- Parameters:
mustStartWithWhitespace
- whether or not whitespace is required before matched string
-
shouldStartWithWhitespace
public boolean shouldStartWithWhitespace()Returns whether matched string must start with whitespace.- Returns:
- whether matched string must start with whitespace.
-
setEndWithWhitespace
public void setEndWithWhitespace(boolean mustEndWithWhitespace) If set to true, regex will not be matched if there is no whitespace after matched string. Whitespace is not returned in parsed result.- Parameters:
mustEndWithWhitespace
- whether or not whitespace is required after matched string
-
shouldEndWithWhitespace
public boolean shouldEndWithWhitespace()Returns whether matched string must end with whitespace.- Returns:
- whether matched string must end with whitespace.
-
terminateNative
protected void terminateNative(long nativeContext) - Specified by:
terminateNative
in classEntity<RegexParser.Result>
-
serializeNativeSettings
@Nullable protected byte[] serializeNativeSettings()- Specified by:
serializeNativeSettings
in classEntity<RegexParser.Result>
-
deserializeNativeSettings
protected void deserializeNativeSettings(@NonNull byte[] serializedSettings) - Specified by:
deserializeNativeSettings
in classEntity<RegexParser.Result>
-
clone
Description copied from class:Entity
Create a copy of the entity. This is required if properties of the entity must be modified while background thread performs processing. In order to avoid race conditions, changing properties is not allowed while entity is used in background processing. However, you are able to make a copy of the entity, change properties of it and then update theRecognizerRunnerView
orRecognizerRunner
with the updated entity hierarchy.- Specified by:
clone
in classEntity<RegexParser.Result>
- Returns:
- a copy of the entity
-
consumeResultFrom
Description copied from class:Entity
Consume result from other entity. The result from other will be put instead current result of this entity. This method is used insideBaseIntentTransferable.loadFromIntent(Intent)
and similar methods to replace the result content of the saved entities with results that have arrived overIntent
- Specified by:
consumeResultFrom
in classEntity<RegexParser.Result>
- Parameters:
other
- Entity from which result should be consumed.
-
consumeResult
Description copied from class:Parser
Consumes given result. The given result will be put instead current result of this entity.- Specified by:
consumeResult
in classParser<RegexParser.Result>
- Parameters:
resultToConsume
- Result that should be consumed.
-
clearResult
public void clearResult()Description copied from class:Parser
Clears parser result.- Specified by:
clearResult
in classParser<RegexParser.Result>
-