UNPKG

react-native-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS

334 lines (303 loc) 9.91 kB
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten. /// Generated from core/schemas/TextPatternScannerTypes.yaml import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes'; import { DeepPartial, PartiallyConstructible, Rectangle } from '../utils/utils'; /** Grammar of pattern matching. - `WILDCARD`: Simple pattern matching where # stands for any digit and ? stands for any character. All other characters represent themselves. - `REGEX`: Regular expression pattern matching. Uses ECMAScript grammar. */ export type PatternGrammar = 'WILDCARD' | 'REGEX'; export const PatternGrammarValues: PatternGrammar[] = ['WILDCARD', 'REGEX']; /** Structure containing recognized word text and bounds. */ export class WordBox extends PartiallyConstructible { /** Recognized word text. */ public readonly text: string; /** Bounding rectangle of the recognized word. */ public readonly boundingRect: Rectangle; /** Confidence of the recognition. Default is 0.0 */ public readonly recognitionConfidence: number = 0.0; /** @param source {@displayType `DeepPartial<WordBox>`} */ public constructor(source: DeepPartial<WordBox> = {}) { super(); if (source.text !== undefined) { this.text = source.text; } else { throw new Error('text must be present in constructor argument'); } if (source.boundingRect !== undefined) { this.boundingRect = { x: source.boundingRect.x, y: source.boundingRect.y, width: source.boundingRect.width, height: source.boundingRect.height, }; } else { throw new Error('boundingRect must be present in constructor argument'); } if (source.recognitionConfidence !== undefined) { this.recognitionConfidence = source.recognitionConfidence; } } public serialize(config: ToJsonConfiguration = new ToJsonConfiguration()): DeepPartial<WordBox> { return { text: this.text, boundingRect: this.boundingRect, recognitionConfidence: this.recognitionConfidence, }; } } /** Structure containing recognized symbol text and bounds. */ export class SymbolBox extends PartiallyConstructible { /** Recognized symbol text. */ public readonly symbol: string; /** Bounding rectangle of the recognized symbol. */ public readonly boundingRect: Rectangle; /** Confidence of the recognition. */ public readonly recognitionConfidence: number; /** @param source {@displayType `DeepPartial<SymbolBox>`} */ public constructor(source: DeepPartial<SymbolBox> = {}) { super(); if (source.symbol !== undefined) { this.symbol = source.symbol; } else { throw new Error('symbol must be present in constructor argument'); } if (source.boundingRect !== undefined) { this.boundingRect = { x: source.boundingRect.x, y: source.boundingRect.y, width: source.boundingRect.width, height: source.boundingRect.height, }; } else { throw new Error('boundingRect must be present in constructor argument'); } if (source.recognitionConfidence !== undefined) { this.recognitionConfidence = source.recognitionConfidence; } else { throw new Error('recognitionConfidence must be present in constructor argument'); } } public serialize( config: ToJsonConfiguration = new ToJsonConfiguration() ): DeepPartial<SymbolBox> { return { symbol: this.symbol, boundingRect: this.boundingRect, recognitionConfidence: this.recognitionConfidence, }; } } /** The result of the text line recognition. */ export class TextPatternScannerResult extends PartiallyConstructible { /** Raw recognized string. */ public readonly rawText: string; /** Boxes for each recognized word. */ public readonly wordBoxes: WordBox[]; /** Boxes for each recognized symbol. */ public readonly symbolBoxes: SymbolBox[]; /** Confidence of the recognition. Default is 0.0 */ public readonly confidence: number = 0.0; /** Whether the validation was successful. Default is false */ public readonly validationSuccessful: boolean = false; /** @param source {@displayType `DeepPartial<TextPatternScannerResult>`} */ public constructor(source: DeepPartial<TextPatternScannerResult> = {}) { super(); if (source.rawText !== undefined) { this.rawText = source.rawText; } else { throw new Error('rawText must be present in constructor argument'); } if (source.wordBoxes !== undefined) { this.wordBoxes = source.wordBoxes.map((it: any) => { return new WordBox(it); }); } else { throw new Error('wordBoxes must be present in constructor argument'); } if (source.symbolBoxes !== undefined) { this.symbolBoxes = source.symbolBoxes.map((it: any) => { return new SymbolBox(it); }); } else { throw new Error('symbolBoxes must be present in constructor argument'); } if (source.confidence !== undefined) { this.confidence = source.confidence; } if (source.validationSuccessful !== undefined) { this.validationSuccessful = source.validationSuccessful; } } public serialize( config: ToJsonConfiguration = new ToJsonConfiguration() ): DeepPartial<TextPatternScannerResult> { return { rawText: this.rawText, wordBoxes: this.wordBoxes.map((it: any) => { return it.serialize(config); }), symbolBoxes: this.symbolBoxes.map((it: any) => { return it.serialize(config); }), confidence: this.confidence, validationSuccessful: this.validationSuccessful, }; } } /** Base class for content validators. */ export type ContentValidator = DefaultContentValidator | PatternContentValidator; /** @internal */ export namespace ContentValidator { /** @internal */ export function From(source: { [key: string]: any }): ContentValidator { const _type = source._type; switch (_type) { case 'DefaultContentValidator': return new DefaultContentValidator(source); case 'PatternContentValidator': return new PatternContentValidator(source); default: throw `Unknown child class name: ${_type}`; } } } /** Default content validator. Accepts only non-empty strings. */ export class DefaultContentValidator extends PartiallyConstructible { public readonly _type: 'DefaultContentValidator' = 'DefaultContentValidator'; /** OCR whitelist. Empty string means no restriction. Default is "" */ public allowedCharacters: string = ''; /** @param source {@displayType `DeepPartial<DefaultContentValidator>`} */ public constructor(source: DeepPartial<DefaultContentValidator> = {}) { super(); if (source.allowedCharacters !== undefined) { this.allowedCharacters = source.allowedCharacters; } } } /** Pattern content validator. */ export class PatternContentValidator extends PartiallyConstructible { public readonly _type: 'PatternContentValidator' = 'PatternContentValidator'; /** OCR whitelist. Empty string means no restriction. Default is "" */ public allowedCharacters: string = ''; /** Pattern to match. It can be a simple pattern or a regular expression. */ public pattern: string; /** Whether the pattern should match the whole string or just a substring. Default is false */ public matchSubstring: boolean = false; /** Grammar of pattern matching. Default is WILDCARD */ public patternGrammar: PatternGrammar = 'WILDCARD'; /** @param source {@displayType `DeepPartial<PatternContentValidator>`} */ public constructor(source: DeepPartial<PatternContentValidator> = {}) { super(); if (source.allowedCharacters !== undefined) { this.allowedCharacters = source.allowedCharacters; } if (source.pattern !== undefined) { this.pattern = source.pattern; } else { throw new Error('pattern must be present in constructor argument'); } if (source.matchSubstring !== undefined) { this.matchSubstring = source.matchSubstring; } if (source.patternGrammar !== undefined) { this.patternGrammar = source.patternGrammar; } } } /** Configuration for the text pattern scanner. */ export class TextPatternScannerConfiguration extends PartiallyConstructible { /** Maximum image size (height or width) for OCR process. 0 - do not rescale. Default is 0 */ public ocrResolutionLimit: number = 0; /** Maximum number of accumulated frames to inspect before actual result is returned. Default is 3 */ public maximumNumberOfAccumulatedFrames: number = 3; /** Minimum number of accumulated frames that have equal result. Default is 2 */ public minimumNumberOfRequiredFramesWithEqualScanningResult: number = 2; /** Content validator. */ public validator: ContentValidator = new DefaultContentValidator({}); /** @param source {@displayType `DeepPartial<TextPatternScannerConfiguration>`} */ public constructor(source: DeepPartial<TextPatternScannerConfiguration> = {}) { super(); if (source.ocrResolutionLimit !== undefined) { this.ocrResolutionLimit = source.ocrResolutionLimit; } if (source.maximumNumberOfAccumulatedFrames !== undefined) { this.maximumNumberOfAccumulatedFrames = source.maximumNumberOfAccumulatedFrames; } if (source.minimumNumberOfRequiredFramesWithEqualScanningResult !== undefined) { this.minimumNumberOfRequiredFramesWithEqualScanningResult = source.minimumNumberOfRequiredFramesWithEqualScanningResult; } if (source.validator !== undefined) { this.validator = ContentValidator.From(source.validator); } } }