Skip to content

Commit

Permalink
add Kotlin lintered files
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon committed Jun 11, 2024
1 parent 5c88149 commit 9c7049c
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 338 deletions.
4 changes: 2 additions & 2 deletions kotlin/services/textract/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:textract:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.sdk.kotlin:textract:1.2.28")
implementation("aws.sdk.kotlin:secretsmanager:1.2.28")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
implementation("com.google.code.gson:gson:2.10")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.textract

// snippet-start:[textract.kotlin._analyze_doc.import]
import aws.sdk.kotlin.services.textract.TextractClient
import aws.sdk.kotlin.services.textract.model.AnalyzeDocumentRequest
import aws.sdk.kotlin.services.textract.model.Document
import aws.sdk.kotlin.services.textract.model.FeatureType
import java.io.File
import java.io.FileInputStream
import kotlin.system.exitProcess
// snippet-end:[textract.kotlin._analyze_doc.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {

val usage = """
Usage:
<sourceDoc>
Where:
sourceDoc - The path where the document is located (must be an image, for example, C:/AWS/book.png).
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val sourceDoc = args[0]
analyzeDoc(sourceDoc)
}

// snippet-start:[textract.kotlin._analyze_doc.main]
suspend fun analyzeDoc(sourceDoc: String?) {

val sourceStream = FileInputStream(File(sourceDoc))
val sourceBytes = sourceStream.readBytes()

// Get the input Document object as bytes.
val myDoc = Document {
bytes = sourceBytes
}

val featureTypesOb = mutableListOf<FeatureType>()
featureTypesOb.add(FeatureType.Forms)
featureTypesOb.add(FeatureType.Tables)

val analyzeDocumentRequest = AnalyzeDocumentRequest {
featureTypes = featureTypesOb
document = myDoc
}

TextractClient { region = "us-east-1" }.use { textractClient ->
val response = textractClient.analyzeDocument(analyzeDocumentRequest)
response.blocks?.forEach { block ->
println("The block type is ${block.blockType}")
}
}
}
// snippet-end:[textract.kotlin._analyze_doc.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.textract

// snippet-start:[textract.kotlin._analyze_doc.import]
import aws.sdk.kotlin.services.textract.TextractClient
import aws.sdk.kotlin.services.textract.model.AnalyzeDocumentRequest
import aws.sdk.kotlin.services.textract.model.Document
import aws.sdk.kotlin.services.textract.model.FeatureType
import java.io.File
import java.io.FileInputStream
import kotlin.system.exitProcess
// snippet-end:[textract.kotlin._analyze_doc.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
val usage = """
Usage:
<sourceDoc>
Where:
sourceDoc - The path where the document is located (must be an image, for example, C:/AWS/book.png).
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val sourceDoc = args[0]
analyzeDoc(sourceDoc)
}

// snippet-start:[textract.kotlin._analyze_doc.main]
suspend fun analyzeDoc(sourceDoc: String?) {
val sourceStream = FileInputStream(File(sourceDoc))
val sourceBytes = sourceStream.readBytes()

// Get the input Document object as bytes.
val myDoc =
Document {
bytes = sourceBytes
}

val featureTypesOb = mutableListOf<FeatureType>()
featureTypesOb.add(FeatureType.Forms)
featureTypesOb.add(FeatureType.Tables)

val analyzeDocumentRequest =
AnalyzeDocumentRequest {
featureTypes = featureTypesOb
document = myDoc
}

TextractClient { region = "us-east-1" }.use { textractClient ->
val response = textractClient.analyzeDocument(analyzeDocumentRequest)
response.blocks?.forEach { block ->
println("The block type is ${block.blockType}")
}
}
}
// snippet-end:[textract.kotlin._analyze_doc.main]
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.textract

// snippet-start:[textract.kotlin._detect_doc_text.import]
import aws.sdk.kotlin.services.textract.TextractClient
import aws.sdk.kotlin.services.textract.model.DetectDocumentTextRequest
import aws.sdk.kotlin.services.textract.model.Document
import java.io.File
import java.io.FileInputStream
import kotlin.system.exitProcess
// snippet-end:[textract.kotlin._detect_doc_text.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {

val usage = """
Usage:
<sourceDoc>
Where:
sourceDoc - The path where the document is located (must be an image, for example, C:/AWS/book.png).
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val sourceDoc = args[0]
detectDocText(sourceDoc)
}

// snippet-start:[textract.kotlin._detect_doc_text.main]
suspend fun detectDocText(sourceDoc: String) {

val sourceStream = FileInputStream(File(sourceDoc))
val sourceBytes = sourceStream.readBytes()

// Get the input Document object as bytes.
val myDoc = Document {
bytes = sourceBytes
}

val detectDocumentTextRequest = DetectDocumentTextRequest {
document = myDoc
}

TextractClient { region = "us-east-1" }.use { textractClient ->
val response = textractClient.detectDocumentText(detectDocumentTextRequest)
response.blocks?.forEach { block ->
println("The block type is ${block.blockType}")
}

val documentMetadata = response.documentMetadata
if (documentMetadata != null) {
println("The number of pages in the document is ${documentMetadata.pages}")
}
}
}
// snippet-end:[textract.kotlin._detect_doc_text.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.textract

// snippet-start:[textract.kotlin._detect_doc_text.import]
import aws.sdk.kotlin.services.textract.TextractClient
import aws.sdk.kotlin.services.textract.model.DetectDocumentTextRequest
import aws.sdk.kotlin.services.textract.model.Document
import java.io.File
import java.io.FileInputStream
import kotlin.system.exitProcess
// snippet-end:[textract.kotlin._detect_doc_text.import]

/**
Before running this Kotlin code example, set up your development environment,
including your credentials.
For more information, see the following documentation topic:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html
*/
suspend fun main(args: Array<String>) {
val usage = """
Usage:
<sourceDoc>
Where:
sourceDoc - The path where the document is located (must be an image, for example, C:/AWS/book.png).
"""

if (args.size != 1) {
println(usage)
exitProcess(0)
}

val sourceDoc = args[0]
detectDocText(sourceDoc)
}

// snippet-start:[textract.kotlin._detect_doc_text.main]
suspend fun detectDocText(sourceDoc: String) {
val sourceStream = FileInputStream(File(sourceDoc))
val sourceBytes = sourceStream.readBytes()

// Get the input Document object as bytes.
val myDoc =
Document {
bytes = sourceBytes
}

val detectDocumentTextRequest =
DetectDocumentTextRequest {
document = myDoc
}

TextractClient { region = "us-east-1" }.use { textractClient ->
val response = textractClient.detectDocumentText(detectDocumentTextRequest)
response.blocks?.forEach { block ->
println("The block type is ${block.blockType}")
}

val documentMetadata = response.documentMetadata
if (documentMetadata != null) {
println("The number of pages in the document is ${documentMetadata.pages}")
}
}
}
// snippet-end:[textract.kotlin._detect_doc_text.main]
Loading

0 comments on commit 9c7049c

Please sign in to comment.