Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Apr 17, 2020
1 parent 3f5d2b1 commit 28179f0
Show file tree
Hide file tree
Showing 12 changed files with 5,853 additions and 4,414 deletions.
650 changes: 325 additions & 325 deletions samples/automl/automlTranslationDataset.js

Large diffs are not rendered by default.

804 changes: 402 additions & 402 deletions samples/automl/automlTranslationModel.js

Large diffs are not rendered by default.

282 changes: 141 additions & 141 deletions samples/automl/automlTranslationPredict.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,141 @@
// Copyright 2018 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.

/**
* This application demonstrates how to perform basic operations on prediction
* with the Google AutoML Translation API.
*
* For more information, see the documentation at
* https://cloud.google.com/translate/automl/docs
*/

`use strict`;

async function predict(
projectId,
computeRegion,
modelId,
filePath,
translationAllowFallback
) {
// [START automl_translation_predict]
const automl = require('@google-cloud/automl');
const fs = require('fs');

// Create client for prediction service.
const client = new automl.PredictionServiceClient();

/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`;
// const computeRegion = `region-name, e.g. "us-central1"`;
// const modelId = `id of the model, e.g. “ICN12345”`;
// const filePath = `local text file path of content to be classified, e.g. "./resources/test.txt"`;
// const translationAllowFallback = `use Google translation model as fallback, e.g. "False" or "True"`;

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Read the file content for translation.
const content = fs.readFileSync(filePath, 'utf8');

// Set the payload by giving the content of the file.
const payload = {
textSnippet: {
content: content,
},
};

// Params is additional domain-specific parameters.
// TranslationAllowFallback allows to use Google translation model.
let params = {};
if (translationAllowFallback) {
params = {
translationAllowFallback: true,
};
}

const responses = await client.predict({
name: modelFullId,
payload: payload,
params: params,
});

const response = responses[0];
console.log(
'Translated Content: ',
response.payload[0].translation.translatedContent.content
);

// [END automl_translation_predict]
}

require('yargs')
.demand(1)
.options({
computeRegion: {
alias: 'c',
type: 'string',
default: 'us-central1',
requiresArg: true,
description: 'region name e.g. "us-central1"',
},
filePath: {
alias: 'f',
default: './resources/testInput.txt',
type: 'string',
requiresArg: true,
description: 'local text file path of the content to be classified',
},
modelId: {
alias: 'i',
type: 'string',
requiresArg: true,
description: 'Id of the model which will be used for text classification',
},
projectId: {
alias: 'z',
type: 'number',
default: process.env.GCLOUD_PROJECT,
requiresArg: true,
description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"',
},
translationAllowFallback: {
alias: 't',
type: 'string',
default: 'False',
requiresArg: true,
description:
'Use true if AutoML will fallback to use a Google translation model for' +
'translation requests if the specified AutoML translation model cannot' +
'serve the request. Use false to not use Google translation model.',
},
})
.command('predict', 'classify the content', {}, opts =>
predict(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.filePath,
opts.translationAllowFallback
)
)
.example(
'node $0 predict -i "modelId" -f "./resources/testInput.txt" -t "False"'
)
.wrap(120)
.recommendCommands()
.help()
.strict().argv;
// Copyright 2018 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.

/**
* This application demonstrates how to perform basic operations on prediction
* with the Google AutoML Translation API.
*
* For more information, see the documentation at
* https://cloud.google.com/translate/automl/docs
*/

`use strict`;

async function predict(
projectId,
computeRegion,
modelId,
filePath,
translationAllowFallback
) {
// [START automl_translation_predict]
const automl = require('@google-cloud/automl');
const fs = require('fs');

// Create client for prediction service.
const client = new automl.PredictionServiceClient();

/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`;
// const computeRegion = `region-name, e.g. "us-central1"`;
// const modelId = `id of the model, e.g. “ICN12345”`;
// const filePath = `local text file path of content to be classified, e.g. "./resources/test.txt"`;
// const translationAllowFallback = `use Google translation model as fallback, e.g. "False" or "True"`;

// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);

// Read the file content for translation.
const content = fs.readFileSync(filePath, 'utf8');

// Set the payload by giving the content of the file.
const payload = {
textSnippet: {
content: content,
},
};

// Params is additional domain-specific parameters.
// TranslationAllowFallback allows to use Google translation model.
let params = {};
if (translationAllowFallback) {
params = {
translationAllowFallback: true,
};
}

const responses = await client.predict({
name: modelFullId,
payload: payload,
params: params,
});

const response = responses[0];
console.log(
'Translated Content: ',
response.payload[0].translation.translatedContent.content
);

// [END automl_translation_predict]
}

require('yargs')
.demand(1)
.options({
computeRegion: {
alias: 'c',
type: 'string',
default: 'us-central1',
requiresArg: true,
description: 'region name e.g. "us-central1"',
},
filePath: {
alias: 'f',
default: './resources/testInput.txt',
type: 'string',
requiresArg: true,
description: 'local text file path of the content to be classified',
},
modelId: {
alias: 'i',
type: 'string',
requiresArg: true,
description: 'Id of the model which will be used for text classification',
},
projectId: {
alias: 'z',
type: 'number',
default: process.env.GCLOUD_PROJECT,
requiresArg: true,
description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"',
},
translationAllowFallback: {
alias: 't',
type: 'string',
default: 'False',
requiresArg: true,
description:
'Use true if AutoML will fallback to use a Google translation model for' +
'translation requests if the specified AutoML translation model cannot' +
'serve the request. Use false to not use Google translation model.',
},
})
.command('predict', 'classify the content', {}, opts =>
predict(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.filePath,
opts.translationAllowFallback
)
)
.example(
'node $0 predict -i "modelId" -f "./resources/testInput.txt" -t "False"'
)
.wrap(120)
.recommendCommands()
.help()
.strict().argv;
15 changes: 3 additions & 12 deletions samples/test/automlTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ describe.skip('automl sample tests', () => {

// Create dataset
output = execSync(`${cmdDataset} create-dataset -n "${testDataSetName}"`);
const dataSetId = output
.split('\n')[1]
.split(':')[1]
.trim();
const dataSetId = output.split('\n')[1].split(':')[1].trim();
assert.match(
output,
new RegExp(`Dataset display name: ${testDataSetName}`)
Expand All @@ -60,10 +57,7 @@ describe.skip('automl sample tests', () => {

// Create dataset
output = execSync(`${cmdDataset} create-dataset -n "${dummyDataSet}"`);
const dataSetId = output
.split('\n')[1]
.split(':')[1]
.trim();
const dataSetId = output.split('\n')[1].split(':')[1].trim();
assert.match(output, new RegExp(`Dataset display name: ${dummyDataSet}`));

// Import Data
Expand All @@ -80,10 +74,7 @@ describe.skip('automl sample tests', () => {
output = execSync(
`${cmdModel} create-model -i "${dataSetId}" -m "${testModelName}" -t "2"`
);
const operationName = output
.split('\n')[0]
.split(':')[1]
.trim();
const operationName = output.split('\n')[0].split(':')[1].trim();
assert.match(output, 'Training started...');

// Poll operation status, here confirming that operation is not complete yet
Expand Down
Loading

0 comments on commit 28179f0

Please sign in to comment.