# 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).

require 'date'
require 'oci'

# Create a default config using DEFAULT profile in default location
# Refer to https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File for more info
config = OCI::ConfigFileLoader.load_config

# Initialize service client with default config file
ai_document_client =
  OCI::AiDocument::AIServiceDocumentClient.new(config: config)

# Send the request to service, some parameters are not required, see API doc for more info
analyze_document_response =
  ai_document_client.analyze_document(
    OCI::AiDocument::Models::AnalyzeDocumentDetails.new(
      features: [
        OCI::AiDocument::Models::DocumentTableExtractionFeature.new(
          feature_type: 'TABLE_EXTRACTION'
        )
      ],
      document:
        OCI::AiDocument::Models::ObjectStorageDocumentDetails.new(
          source: 'OBJECT_STORAGE',
          namespace_name: 'EXAMPLE-namespaceName-Value',
          bucket_name: 'EXAMPLE-bucketName-Value',
          object_name: 'EXAMPLE-objectName-Value'
        ),
      compartment_id: 'ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value',
      output_location:
        OCI::AiDocument::Models::OutputLocation.new(
          namespace_name: 'EXAMPLE-namespaceName-Value',
          bucket_name: 'EXAMPLE-bucketName-Value',
          prefix: 'EXAMPLE-prefix-Value'
        ),
      language: 'EXAMPLE-language-Value',
      document_type: 'PASSPORT',
      ocr_data:
        OCI::AiDocument::Models::AnalyzeDocumentResult.new(
          document_metadata:
            OCI::AiDocument::Models::DocumentMetadata.new(
              page_count: 386, mime_type: 'EXAMPLE-mimeType-Value'
            ),
          pages: [
            OCI::AiDocument::Models::Page.new(
              page_number: 652,
              dimensions:
                OCI::AiDocument::Models::Dimensions.new(
                  width: 6953.87, height: 1206.7455, unit: 'INCH'
                ),
              detected_document_types: [
                OCI::AiDocument::Models::DetectedDocumentType.new(
                  document_type: 'EXAMPLE-documentType-Value',
                  confidence: 0.38272268
                )
              ],
              detected_languages: [
                OCI::AiDocument::Models::DetectedLanguage.new(
                  language: 'EXAMPLE-language-Value', confidence: 0.033904433
                )
              ],
              words: [
                OCI::AiDocument::Models::Word.new(
                  text: 'EXAMPLE-text-Value',
                  confidence: 0.6829166,
                  bounding_polygon:
                    OCI::AiDocument::Models::BoundingPolygon.new(
                      normalized_vertices: [
                        OCI::AiDocument::Models::NormalizedVertex.new(
                          x: 0.03948939, y: 0.18585902
                        )
                      ]
                    )
                )
              ],
              lines: [
                OCI::AiDocument::Models::Line.new(
                  text: 'EXAMPLE-text-Value',
                  confidence: 0.49444848,
                  bounding_polygon:
                    OCI::AiDocument::Models::BoundingPolygon.new(
                      normalized_vertices: [
                        OCI::AiDocument::Models::NormalizedVertex.new(
                          x: 0.80519354, y: 0.555152
                        )
                      ]
                    ),
                  word_indexes: [305]
                )
              ],
              tables: [
                OCI::AiDocument::Models::Table.new(
                  row_count: 587,
                  column_count: 428,
                  header_rows: [
                    OCI::AiDocument::Models::TableRow.new(
                      cells: [
                        OCI::AiDocument::Models::Cell.new(
                          text: 'EXAMPLE-text-Value',
                          row_index: 346,
                          column_index: 647,
                          confidence: 0.61226815,
                          bounding_polygon:
                            OCI::AiDocument::Models::BoundingPolygon.new(
                              normalized_vertices: [
                                OCI::AiDocument::Models::NormalizedVertex.new(
                                  x: 0.6075643, y: 0.5917017
                                )
                              ]
                            ),
                          word_indexes: [637]
                        )
                      ]
                    )
                  ],
                  confidence: 0.53518015,
                  bounding_polygon:
                    OCI::AiDocument::Models::BoundingPolygon.new(
                      normalized_vertices: [
                        OCI::AiDocument::Models::NormalizedVertex.new(
                          x: 0.9565623, y: 0.35131764
                        )
                      ]
                    )
                )
              ],
              document_fields: [
                OCI::AiDocument::Models::DocumentField.new(
                  field_type: 'KEY_VALUE',
                  field_value:
                    OCI::AiDocument::Models::ValueTime.new(
                      value_type: 'TIME',
                      confidence: 0.94901425,
                      bounding_polygon:
                        OCI::AiDocument::Models::BoundingPolygon.new(
                          normalized_vertices: [
                            OCI::AiDocument::Models::NormalizedVertex.new(
                              x: 0.9334849, y: 0.7823925
                            )
                          ]
                        ),
                      word_indexes: [45],
                      value: DateTime.parse('2006-11-11T05:18:01.839Z'),
                      text: 'EXAMPLE-text-Value'
                    ),
                  field_label:
                    OCI::AiDocument::Models::FieldLabel.new(
                      name: 'EXAMPLE-name-Value', confidence: 0.9216826
                    ),
                  field_name:
                    OCI::AiDocument::Models::FieldName.new(
                      name: 'EXAMPLE-name-Value',
                      confidence: 0.9231316,
                      bounding_polygon:
                        OCI::AiDocument::Models::BoundingPolygon.new(
                          normalized_vertices: [
                            OCI::AiDocument::Models::NormalizedVertex.new(
                              x: 0.91406524, y: 0.5188462
                            )
                          ]
                        ),
                      word_indexes: [346]
                    )
                )
              ]
            )
          ],
          detected_document_types: [
            OCI::AiDocument::Models::DetectedDocumentType.new(
              document_type: 'EXAMPLE-documentType-Value', confidence: 0.7823387
            )
          ],
          detected_languages: [
            OCI::AiDocument::Models::DetectedLanguage.new(
              language: 'EXAMPLE-language-Value', confidence: 0.042288303
            )
          ],
          document_classification_model_version:
            'EXAMPLE-documentClassificationModelVersion-Value',
          language_classification_model_version:
            'EXAMPLE-languageClassificationModelVersion-Value',
          text_extraction_model_version:
            'EXAMPLE-textExtractionModelVersion-Value',
          key_value_extraction_model_version:
            'EXAMPLE-keyValueExtractionModelVersion-Value',
          table_extraction_model_version:
            'EXAMPLE-tableExtractionModelVersion-Value',
          errors: [
            OCI::AiDocument::Models::ProcessingError.new(
              code: 'EXAMPLE-code-Value', message: 'EXAMPLE-message-Value'
            )
          ],
          searchable_pdf: 'N5ZgLTHbKcagkTelQmm7'
        )
    )
  )

# Get the data from response
puts "#{analyze_document_response.data}"

Was this article helpful?