Skip to content

Latest commit

 

History

History
57 lines (52 loc) · 1.45 KB

ocr_library.md

File metadata and controls

57 lines (52 loc) · 1.45 KB

Folder Structure

/src
  /ocr
    /index.ts
    /google-vision
    /your-library-goes-here

Configuration changes

src/constants.ts

Constants.OCR_AGENTS = {
  GOOGLE_VISION: "google-vision"
  // Add new OCR library here
};

Implementation changes

src/ocr/google-vision/index.ts

import YourLibrary from "./your-library-goes-here";

// Make strategy for new document
OCR[Constants.OCR_AGENTS.YOUR_LIBRARY] = {
  extractDocumentText: YourLibrary.extractDocumentText
};

src/ocr/your-library-goes-here/index.ts

  • Your library should expose a function called extractDocumentText.
  • For function contract check src/interfaces/OCR.ts
  • For reference please check the source code of google-vision integration.
import {
  ExtractDocumentTypeRequest,
  ExtractDocumentTypeResponse
} from "../../interfaces/OCR";

// ******************************************************* //
// Logic for API handlers starts here                      //
// ******************************************************* //
YourLibrary.extractDocumentText = async (
  params: ExtractDocumentTypeRequest
): Promise<ExtractDocumentTypeResponse> => {
  ....
  ....
  ....
  return {
    raw_text: _.split(text, "\n")
  };
};
// ******************************************************* //
// Logic for API handlers ends here                        //
// ******************************************************* //

export default YourLibrary;