From f3293a56fbb9cd7c06f8df4f23c6d383bef7bc04 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Fri, 22 Apr 2022 12:37:14 -0700 Subject: [PATCH] chore: removed v1beta2 samples (#325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: removed v1beta2 samples * removed v1beta2 links in readme * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- document-ai/batch-parse-form.v1beta2.js | 139 ----------------- document-ai/batch-parse-table.v1beta2.js | 144 ------------------ document-ai/parse-form.v1beta2.js | 95 ------------ document-ai/parse-table.v1beta2.js | 105 ------------- document-ai/parse-with-model.v1beta2.js | 68 --------- document-ai/set-endpoint.v1beta2.js | 79 ---------- .../test/batch-parse-form.v1beta2.test.js | 52 ------- .../test/batch-parse-table.v1beta2.test.js | 52 ------- document-ai/test/parse-form.v1beta2.test.js | 38 ----- document-ai/test/parse-table.v1beta2.test.js | 38 ----- .../test/parse-with-model.v1beta2.test.js | 41 ----- document-ai/test/set-endpoint.v1beta2.test.js | 38 ----- 12 files changed, 889 deletions(-) delete mode 100644 document-ai/batch-parse-form.v1beta2.js delete mode 100644 document-ai/batch-parse-table.v1beta2.js delete mode 100644 document-ai/parse-form.v1beta2.js delete mode 100644 document-ai/parse-table.v1beta2.js delete mode 100644 document-ai/parse-with-model.v1beta2.js delete mode 100644 document-ai/set-endpoint.v1beta2.js delete mode 100644 document-ai/test/batch-parse-form.v1beta2.test.js delete mode 100644 document-ai/test/batch-parse-table.v1beta2.test.js delete mode 100644 document-ai/test/parse-form.v1beta2.test.js delete mode 100644 document-ai/test/parse-table.v1beta2.test.js delete mode 100644 document-ai/test/parse-with-model.v1beta2.test.js delete mode 100644 document-ai/test/set-endpoint.v1beta2.test.js diff --git a/document-ai/batch-parse-form.v1beta2.js b/document-ai/batch-parse-form.v1beta2.js deleted file mode 100644 index 5924296aae..0000000000 --- a/document-ai/batch-parse-form.v1beta2.js +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Copyright 2020 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const uuid = require('uuid'); - -async function main( - projectId = 'YOUR_PROJECT_ID', - location = 'YOUR_PROJECT_LOCATION', - gcsOutputUri = 'output-bucket', - gcsOutputUriPrefix = uuid.v4(), - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_batch_parse_form] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const gcsOutputUri = 'YOUR_STORAGE_BUCKET'; - // const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX'; - // const gcsInputUri = 'GCS URI of the PDF to process'; - - // Imports the Google Cloud client library - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - const {Storage} = require('@google-cloud/storage'); - - const client = new DocumentUnderstandingServiceClient(); - const storage = new Storage(); - - async function parseFormGCS(inputUri, outputUri, outputUriPrefix) { - const parent = `projects/${projectId}/locations/${location}`; - - // Configure the batch process request. - const request = { - inputConfig: { - gcsSource: { - uri: inputUri, - }, - mimeType: 'application/pdf', - }, - outputConfig: { - gcsDestination: { - uri: `${outputUri}/${outputUriPrefix}/`, - }, - pagesPerShard: 1, - }, - formExtractionParams: { - enabled: true, - keyValuePairHints: [ - { - key: 'Phone', - valueTypes: ['PHONE_NUMBER'], - }, - { - key: 'Contact', - valueTypes: ['EMAIL', 'NAME'], - }, - ], - }, - }; - - // Configure the request for batch process - const requests = { - parent, - requests: [request], - }; - - // Batch process document using a long-running operation. - // You can wait for now, or get results later. - const [operation] = await client.batchProcessDocuments(requests); - - // Wait for operation to complete. - await operation.promise(); - - console.log('Document processing complete.'); - - // Query Storage bucket for the results file(s). - const query = { - prefix: outputUriPrefix, - }; - - console.log('Fetching results ...'); - - // List all of the files in the Storage bucket - const [files] = await storage.bucket(gcsOutputUri).getFiles(query); - - files.forEach(async (fileInfo, index) => { - // Get the file as a buffer - const [file] = await fileInfo.download(); - - console.log(`Fetched file #${index + 1}:`); - - // Read the results - const results = JSON.parse(file.toString()); - - // Get all of the document text as one big string. - const {text} = results; - - // Utility to extract text anchors from text field. - const getText = textAnchor => { - const startIndex = textAnchor.textSegments[0].startIndex || 0; - const endIndex = textAnchor.textSegments[0].endIndex; - - return `\t${text.substring(startIndex, endIndex)}`; - }; - - // Process the output - const [page1] = results.pages; - const formFields = page1.formFields; - - for (const field of formFields) { - const fieldName = getText(field.fieldName.textAnchor); - const fieldValue = getText(field.fieldValue.textAnchor); - - console.log('Extracted key value pair:'); - console.log(`\t(${fieldName}, ${fieldValue})`); - } - }); - } - // [END documentai_batch_parse_form] - - parseFormGCS(gcsInputUri, gcsOutputUri, gcsOutputUriPrefix); -} -main(...process.argv.slice(2)); diff --git a/document-ai/batch-parse-table.v1beta2.js b/document-ai/batch-parse-table.v1beta2.js deleted file mode 100644 index 6038182122..0000000000 --- a/document-ai/batch-parse-table.v1beta2.js +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright 2020 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const uuid = require('uuid'); - -async function main( - projectId = 'YOUR_PROJECT_ID', - location = 'YOUR_PROJECT_LOCATION', - gcsOutputUri = 'output-bucket', - gcsOutputUriPrefix = uuid.v4(), - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_batch_parse_table] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const gcsOutputUri = 'YOUR_STORAGE_BUCKET'; - // const gcsOutputUriPrefix = 'YOUR_STORAGE_PREFIX'; - // const gcsInputUri = 'YOUR_SOURCE_PDF'; - - // Imports the Google Cloud client library - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - const {Storage} = require('@google-cloud/storage'); - - const client = new DocumentUnderstandingServiceClient(); - const storage = new Storage(); - - async function parseTableGCS(inputUri, outputUri, outputUriPrefix) { - const parent = `projects/${projectId}/locations/${location}`; - - // Configure the batch process request. - const request = { - //parent, - inputConfig: { - gcsSource: { - uri: inputUri, - }, - mimeType: 'application/pdf', - }, - outputConfig: { - gcsDestination: { - uri: `${outputUri}/${outputUriPrefix}/`, - }, - pagesPerShard: 1, - }, - tableExtractionParams: { - enabled: true, - tableBoundHints: [ - { - boundingBox: { - normalizedVertices: [ - {x: 0, y: 0}, - {x: 1, y: 0}, - {x: 1, y: 1}, - {x: 0, y: 1}, - ], - }, - }, - ], - }, - }; - - // Configure the request for batch process - const requests = { - parent, - requests: [request], - }; - - // Batch process document using a long-running operation. - // You can wait for now, or get results later. - // Note: first request to the service takes longer than subsequent - // requests. - const [operation] = await client.batchProcessDocuments(requests); - - // Wait for operation to complete. - await operation.promise(); - - console.log('Document processing complete.'); - - // Query Storage bucket for the results file(s). - const query = { - prefix: outputUriPrefix, - }; - - console.log('Fetching results ...'); - - // List all of the files in the Storage bucket - const [files] = await storage.bucket(gcsOutputUri).getFiles(query); - - files.forEach(async (fileInfo, index) => { - // Get the file as a buffer - const [file] = await fileInfo.download(); - - console.log(`Fetched file #${index + 1}:`); - - // Read the results - const results = JSON.parse(file.toString()); - - // Get all of the document text as one big string - const text = results.text; - - // Get the first table in the document - const [page1] = results.pages; - const [table] = page1.tables; - const [headerRow] = table.headerRows; - - console.log('Results from first table processed:'); - - console.log('Header row:'); - for (const tableCell of headerRow.cells) { - if (tableCell.layout.textAnchor.textSegments) { - // Extract shards from the text field - // First shard in document doesn't have startIndex property - const startIndex = - tableCell.layout.textAnchor.textSegments[0].startIndex || 0; - const endIndex = tableCell.layout.textAnchor.textSegments[0].endIndex; - - console.log(`\t${text.substring(startIndex, endIndex)}`); - } - } - }); - } - // [END documentai_batch_parse_table] - - parseTableGCS(gcsInputUri, gcsOutputUri, gcsOutputUriPrefix); -} -main(...process.argv.slice(2)); diff --git a/document-ai/parse-form.v1beta2.js b/document-ai/parse-form.v1beta2.js deleted file mode 100644 index 8885c789e2..0000000000 --- a/document-ai/parse-form.v1beta2.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright 2020, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -async function main( - projectId, - location, - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_parse_form] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const gcsInputUri = 'YOUR_SOURCE_PDF'; - - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - const client = new DocumentUnderstandingServiceClient(); - - async function parseForm() { - // Configure the request for processing the PDF - const parent = `projects/${projectId}/locations/${location}`; - const request = { - parent, - inputConfig: { - gcsSource: { - uri: gcsInputUri, - }, - mimeType: 'application/pdf', - }, - formExtractionParams: { - enabled: true, - keyValuePairHints: [ - { - key: 'Phone', - valueTypes: ['PHONE_NUMBER'], - }, - { - key: 'Contact', - valueTypes: ['EMAIL', 'NAME'], - }, - ], - }, - }; - - // Recognizes text entities in the PDF document - const [result] = await client.processDocument(request); - - // Get all of the document text as one big string - const {text} = result; - - // Extract shards from the text field - const getText = textAnchor => { - // First shard in document doesn't have startIndex property - const startIndex = textAnchor.textSegments[0].startIndex || 0; - const endIndex = textAnchor.textSegments[0].endIndex; - - return text.substring(startIndex, endIndex); - }; - - // Process the output - const [page1] = result.pages; - const {formFields} = page1; - - for (const field of formFields) { - const fieldName = getText(field.fieldName.textAnchor); - const fieldValue = getText(field.fieldValue.textAnchor); - - console.log('Extracted key value pair:'); - console.log(`\t(${fieldName}, ${fieldValue})`); - } - } - // [END documentai_parse_form] - await parseForm(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); diff --git a/document-ai/parse-table.v1beta2.js b/document-ai/parse-table.v1beta2.js deleted file mode 100644 index 24ddf7a2ab..0000000000 --- a/document-ai/parse-table.v1beta2.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright 2020, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -async function main( - projectId, - location, - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_parse_table] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const gcsInputUri = 'YOUR_SOURCE_PDF'; - - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - const client = new DocumentUnderstandingServiceClient(); - - async function parseTable() { - // Configure the request for processing the PDF - const parent = `projects/${projectId}/locations/${location}`; - const request = { - parent, - inputConfig: { - gcsSource: { - uri: gcsInputUri, - }, - mimeType: 'application/pdf', - }, - tableExtractionParams: { - enabled: true, - tableBoundHints: [ - { - boundingBox: { - normalizedVertices: [ - {x: 0, y: 0}, - {x: 1, y: 0}, - {x: 1, y: 1}, - {x: 0, y: 1}, - ], - }, - }, - ], - }, - }; - - // Recognizes text entities in the PDF document - const [result] = await client.processDocument(request); - - // Get all of the document text as one big string - const {text} = result; - - // Extract shards from the text field - function getText(textAnchor) { - // Text anchor has no text segments if cell is empty - if (textAnchor.textSegments.length > 0) { - // First shard in document doesn't have startIndex property - const startIndex = textAnchor.textSegments[0].startIndex || 0; - const endIndex = textAnchor.textSegments[0].endIndex; - - return text.substring(startIndex, endIndex); - } - return '[NO TEXT]'; - } - - // Get the first table in the document - const [page1] = result.pages; - const [table] = page1.tables; - const [headerRow] = table.headerRows; - - console.log('Header row:'); - for (const tableCell of headerRow.cells) { - if (tableCell.layout.textAnchor.textSegments) { - // Extract shards from the text field - // First shard in document doesn't have startIndex property - const textAnchor = tableCell.layout.textAnchor; - - console.log(`\t${getText(textAnchor)}`); - } - } - } - // [END documentai_parse_table] - await parseTable(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); diff --git a/document-ai/parse-with-model.v1beta2.js b/document-ai/parse-with-model.v1beta2.js deleted file mode 100644 index 23dc3ae32e..0000000000 --- a/document-ai/parse-with-model.v1beta2.js +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2020, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -async function main( - projectId, - location, - autoMLModel, - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_parse_with_model] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const autoMLModel = 'Full resource name of AutoML Natural Language model'; - // const gcsInputUri = 'YOUR_SOURCE_PDF'; - - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - const client = new DocumentUnderstandingServiceClient(); - - async function parseWithModel() { - // Configure the request for processing the PDF - const parent = `projects/${projectId}/locations/${location}`; - const request = { - parent, - inputConfig: { - gcsSource: { - uri: gcsInputUri, - }, - mimeType: 'application/pdf', - }, - automlParams: { - model: autoMLModel, - }, - }; - - // Recognizes text entities in the PDF document - const [result] = await client.processDocument(request); - - for (const label of result.labels) { - console.log(`Label detected: ${label.name}`); - console.log(`Confidence: ${label.confidence}`); - } - } - // [END documentai_parse_with_model] - await parseWithModel(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); diff --git a/document-ai/set-endpoint.v1beta2.js b/document-ai/set-endpoint.v1beta2.js deleted file mode 100644 index 81642bb00f..0000000000 --- a/document-ai/set-endpoint.v1beta2.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright 2020, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -async function main( - projectId, - location = 'eu', - gcsInputUri = 'gs://cloud-samples-data/documentai/invoice.pdf' -) { - // [START documentai_set_endpoint] - /** - * TODO(developer): Uncomment these variables before running the sample. - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' - // const gcsInputUri = 'YOUR_SOURCE_PDF'; - - const {DocumentUnderstandingServiceClient} = - require('@google-cloud/documentai').v1beta2; - - // Specifies the location of the api endpoint - const clientOptions = {apiEndpoint: 'eu-documentai.googleapis.com'}; - const client = new DocumentUnderstandingServiceClient(clientOptions); - - async function setEndpoint() { - // Configure the request for processing the PDF - const parent = `projects/${projectId}/locations/${location}`; - const request = { - parent, - inputConfig: { - gcsSource: { - uri: gcsInputUri, - }, - mimeType: 'application/pdf', - }, - }; - - // Recognizes text entities in the PDF document - const [result] = await client.processDocument(request); - - // Get all of the document text as one big string - const {text} = result; - - // Extract shards from the text field - function extractText(textAnchor) { - // First shard in document doesn't have startIndex property - const startIndex = textAnchor.textSegments[0].startIndex || 0; - const endIndex = textAnchor.textSegments[0].endIndex; - - return text.substring(startIndex, endIndex); - } - - for (const entity of result.entities) { - console.log(`\nEntity text: ${extractText(entity.textAnchor)}`); - console.log(`Entity type: ${entity.type}`); - console.log(`Entity mention text: ${entity.mentionText}`); - } - } - // [END documentai_set_endpoint] - await setEndpoint(); -} - -main(...process.argv.slice(2)).catch(err => { - console.error(err); - process.exitCode = 1; -}); diff --git a/document-ai/test/batch-parse-form.v1beta2.test.js b/document-ai/test/batch-parse-form.v1beta2.test.js deleted file mode 100644 index b4be2db82d..0000000000 --- a/document-ai/test/batch-parse-form.v1beta2.test.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const storage = new Storage(); -const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; -const cmd = 'node batch-parse-form.v1beta2.js'; - -const testParseForm = { - projectId: process.env.GCLOUD_PROJECT, - location: 'us', - gcsOutputUriPrefix: uuid.v4(), -}; - -describe('Document AI batch parse form (v1beta2)', () => { - before(async () => { - await storage.createBucket(bucketName); - }); - - after(async () => { - const bucket = storage.bucket(bucketName); - await bucket.deleteFiles({force: true}); - await bucket.delete(); - }); - - it('should parse the GCS invoice example as a form', async () => { - const output = execSync( - `${cmd} ${testParseForm.projectId} ${testParseForm.location} gs://${bucketName}` - ); - assert.match(output, /Extracted key value pair:/); - }); -}); diff --git a/document-ai/test/batch-parse-table.v1beta2.test.js b/document-ai/test/batch-parse-table.v1beta2.test.js deleted file mode 100644 index f0c12fb1ec..0000000000 --- a/document-ai/test/batch-parse-table.v1beta2.test.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -'use strict'; - -const {Storage} = require('@google-cloud/storage'); -const cp = require('child_process'); -const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const storage = new Storage(); -const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; -const cmd = 'node batch-parse-table.v1beta2.js'; - -const testParseTable = { - projectId: process.env.GCLOUD_PROJECT, - location: 'us', - gcsOutputUriPrefix: uuid.v4(), -}; - -describe('Document AI batch parse table (v1beta2)', () => { - before(async () => { - await storage.createBucket(bucketName); - }); - - after(async () => { - const bucket = storage.bucket(bucketName); - await bucket.deleteFiles({force: true}); - await bucket.delete(); - }); - - it('should parse the GCS invoice example as as table', async () => { - const output = execSync( - `${cmd} ${testParseTable.projectId} ${testParseTable.location} gs://${bucketName}` - ); - assert.match(output, /Document processing complete./); - }); -}); diff --git a/document-ai/test/parse-form.v1beta2.test.js b/document-ai/test/parse-form.v1beta2.test.js deleted file mode 100644 index 1aaf3126b6..0000000000 --- a/document-ai/test/parse-form.v1beta2.test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2019, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cwd = path.join(__dirname, '..'); -const projectId = process.env.GCLOUD_PROJECT; -const LOCATION = 'us'; - -describe('Document AI parse form', () => { - it('should parse the GCS invoice example as a form (v1beta2)', async () => { - const stdout = execSync( - `node ./parse-form.v1beta2.js ${projectId} ${LOCATION}`, - { - cwd, - } - ); - assert.match(stdout, /Extracted key value pair:/); - }); -}); diff --git a/document-ai/test/parse-table.v1beta2.test.js b/document-ai/test/parse-table.v1beta2.test.js deleted file mode 100644 index 94b11e0cf3..0000000000 --- a/document-ai/test/parse-table.v1beta2.test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2019, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cwd = path.join(__dirname, '..'); -const projectId = process.env.GCLOUD_PROJECT; -const LOCATION = 'us'; - -describe('Document AI parse table', () => { - it('should parse the GCS invoice example as as table (v1beta2)', async () => { - const stdout = execSync( - `node ./parse-table.v1beta2.js ${projectId} ${LOCATION}`, - { - cwd, - } - ); - assert.match(stdout, /Header row/); - }); -}); diff --git a/document-ai/test/parse-with-model.v1beta2.test.js b/document-ai/test/parse-with-model.v1beta2.test.js deleted file mode 100644 index 63abbfcf34..0000000000 --- a/document-ai/test/parse-with-model.v1beta2.test.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2019, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cwd = path.join(__dirname, '..'); -const projectId = process.env.GCLOUD_PROJECT; -const LOCATION = 'us'; -const MODEL_NAME = - process.env.MODEL_NAME || - 'projects/1046198160504/locations/us-central1/models/TCN7483069430457434112'; - -describe('Document AI parse with AutoML model (v1beta2)', () => { - it('should run use an AutoML model to parse a PDF', async () => { - const stdout = execSync( - `node ./parse-with-model.v1beta2.js ${projectId} ${LOCATION} ${MODEL_NAME}`, - { - cwd, - } - ); - assert.match(stdout, /Label/); - }); -}); diff --git a/document-ai/test/set-endpoint.v1beta2.test.js b/document-ai/test/set-endpoint.v1beta2.test.js deleted file mode 100644 index 6341669e90..0000000000 --- a/document-ai/test/set-endpoint.v1beta2.test.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2019, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const path = require('path'); -const {assert} = require('chai'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cwd = path.join(__dirname, '..'); -const projectId = process.env.GCLOUD_PROJECT; -const LOCATION = 'eu'; - -describe('Document AI set endpoint (v1beta2)', () => { - it('should process a PDF in another region', async () => { - const stdout = execSync( - `node ./set-endpoint.v1beta2.js ${projectId} ${LOCATION}`, - { - cwd, - } - ); - assert.match(stdout, /Entity/); - }); -});