// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).
import * as aidocument from "oci-aidocument";
import common = require("oci-common");
// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();
(async () => {
try {
// Create a service client
const client = new aidocument.AIServiceDocumentClient({ authenticationDetailsProvider: provider });
// Create a request and dependent object(s).
const analyzeDocumentDetails = {
features: [{
featureType: "DOCUMENT_ELEMENTS_EXTRACTION", modelId: "ocid1.test.oc1..<unique_ID>EXAMPLE-modelId-Value"
}
],
document: {
source: "OBJECT_STORAGE", namespaceName: "EXAMPLE-namespaceName-Value",
bucketName: "EXAMPLE-bucketName-Value",
objectName: "EXAMPLE-objectName-Value",
pageRange: ["EXAMPLE--Value" ]
}
,
compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
outputLocation: {
namespaceName: "EXAMPLE-namespaceName-Value",
bucketName: "EXAMPLE-bucketName-Value",
prefix: "EXAMPLE-prefix-Value",
}
,
language: "EXAMPLE-language-Value",
documentType: aidocument.models.DocumentType.Receipt,
ocrData: {
documentMetadata: {
pageCount: 279,
mimeType: "EXAMPLE-mimeType-Value",
}
,
pages: [{
pageNumber: 168,
dimensions: {
width: 6506.377,
height: 1836.6045,
unit: aidocument.models.Dimensions.Unit.Inch,
}
,
detectedDocumentTypes: [{
documentType: "EXAMPLE-documentType-Value",
documentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-documentId-Value",
confidence: 0.20636326,
}
],
detectedLanguages: [{
language: "EXAMPLE-language-Value",
confidence: 0.9804424,
}
],
words: [{
text: "EXAMPLE-text-Value",
confidence: 0.18925643,
boundingPolygon: {
normalizedVertices: [{
x: 0.7567968,
y: 0.16993767,
}
],
}
,
}
],
lines: [{
text: "EXAMPLE-text-Value",
confidence: 0.2521472,
boundingPolygon: {
normalizedVertices: [{
x: 0.26323795,
y: 0.69503534,
}
],
}
,
wordIndexes: [796 ],
}
],
tables: [{
rowCount: 337,
columnCount: 386,
headerRows: [{
cells: [{
text: "EXAMPLE-text-Value",
rowIndex: 862,
columnIndex: 665,
confidence: 0.37774736,
boundingPolygon: {
normalizedVertices: [{
x: 0.27124602,
y: 0.08899367,
}
],
}
,
wordIndexes: [986 ],
}
],
}
],
confidence: 0.5289005,
boundingPolygon: {
normalizedVertices: [{
x: 0.7253601,
y: 0.571634,
}
],
}
,
}
],
documentFields: [{
fieldType: aidocument.models.DocumentField.FieldType.LineItemField,
fieldLabel: {
name: "EXAMPLE-name-Value",
confidence: 0.99906224,
}
,
fieldName: {
name: "EXAMPLE-name-Value",
confidence: 0.12940931,
boundingPolygon: {
normalizedVertices: [{
x: 0.6239295,
y: 0.31811917,
}
],
}
,
wordIndexes: [287 ],
}
,
fieldValue: {
valueType: "INTEGER", value: 363,
text: "EXAMPLE-text-Value",
confidence: 0.81502527,
boundingPolygon: {
normalizedVertices: [{
x: 0.17849636,
y: 0.83037513,
}
],
}
,
wordIndexes: [928 ],
normalizedValue: "EXAMPLE-normalizedValue-Value",
normalizedConfidence: 0.44432253
}
,
}
],
signatures: [{
confidence: 0.053895116,
boundingPolygon: {
normalizedVertices: [{
x: 0.33834213,
y: 0.26724082,
}
],
}
,
}
],
barCodes: [{
confidence: 0.0715785,
value: "EXAMPLE-value-Value",
codeType: "EXAMPLE-codeType-Value",
boundingPolygon: {
normalizedVertices: [{
x: 0.45336193,
y: 0.13147873,
}
],
}
,
}
],
selectionMarks: [{
state: aidocument.models.SelectionMark.State.Unselected,
confidence: 0.6809422,
boundingPolygon: {
normalizedVertices: [{
x: 0.30912173,
y: 0.50898546,
}
],
}
,
}
],
}
],
detectedDocumentTypes: [{
documentType: "EXAMPLE-documentType-Value",
documentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-documentId-Value",
confidence: 0.9831584,
}
],
detectedLanguages: [{
language: "EXAMPLE-language-Value",
confidence: 0.2196948,
}
],
documentClassificationModelVersion: "EXAMPLE-documentClassificationModelVersion-Value",
languageClassificationModelVersion: "EXAMPLE-languageClassificationModelVersion-Value",
textExtractionModelVersion: "EXAMPLE-textExtractionModelVersion-Value",
keyValueExtractionModelVersion: "EXAMPLE-keyValueExtractionModelVersion-Value",
tableExtractionModelVersion: "EXAMPLE-tableExtractionModelVersion-Value",
signatureExtractionModelVersion: "EXAMPLE-signatureExtractionModelVersion-Value",
barCodeExtractionModelVersion: "EXAMPLE-barCodeExtractionModelVersion-Value",
errors: [{
code: "EXAMPLE-code-Value",
message: "EXAMPLE-message-Value",
}
],
searchablePdf: "some Byte data",
}
,
}
const analyzeDocumentRequest: aidocument.requests.AnalyzeDocumentRequest = {
analyzeDocumentDetails: analyzeDocumentDetails,
ifMatch: "EXAMPLE-ifMatch-Value",
opcRequestId: "MNREAKWJSDFRX2NFLO7N<unique_ID>",
};
// Send request to the Client.
const analyzeDocumentResponse = await client.analyzeDocument(analyzeDocumentRequest);
}
catch (error) {
console.log("analyzeDocument Failed with error " + error);
}
})();