-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
359 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 69 additions & 69 deletions
138
kotlin/services/textract/src/main/kotlin/com/kotlin/textract/AnalyzeDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
136 changes: 68 additions & 68 deletions
136
kotlin/services/textract/src/main/kotlin/com/kotlin/textract/DetectDocumentText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Oops, something went wrong.