Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"types": "build/src/index.d.ts",
"files": [
"build/src",
"!build/src/**/*.map",
"AUTHORS",
"CONTRIBUTORS",
"LICENSE"
"!build/src/**/*.map"
],
"keywords": [
"google apis client",
Expand All @@ -30,18 +27,16 @@
"translate"
],
"scripts": {
"cover": "nyc --reporter=lcov mocha build/test && nyc report",
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "npm run check && eslint samples/",
"lint": "npm run check && eslint '**/*.js'",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha build/system-test --timeout 600000",
"test-no-cover": "mocha build/test",
"test": "npm run cover",
"test": "nyc mocha build/test",
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "gts fix && eslint --fix 'samples/**/*.js'",
"fix": "gts fix && eslint --fix '**/*.js'",
"prepare": "npm run compile",
"pretest": "npm run compile",
"presystem-test": "npm run compile"
Expand Down Expand Up @@ -70,7 +65,6 @@
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"gts": "^0.9.0",
"hard-rejection": "^1.0.0",
"ink-docstrap": "^1.3.2",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
Expand Down
108 changes: 31 additions & 77 deletions samples/automl/automlTranslationDataset.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,15 @@

`use strict`;

async function createDataset(
projectId,
computeRegion,
datasetName,
source,
target
) {
async function createDataset(projectId) {
// [START automl_translation_create_dataset]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

/**
* 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 datasetName = `name of the dataset to create, e.g. “myDataset”`;
// const source = `source language code, e.g. "en" `;
// const target = `target language code, e.g. "ja" `;
const computeRegion = 'us-central1';
const datasetName = 'myDataset';
const source = 'en';
const target = 'ja';

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);
Expand Down Expand Up @@ -90,8 +79,7 @@ async function createDataset(
async function listDatasets(projectId, computeRegion, filter) {
// [START automl_translation_list_datasets]
const automl = require(`@google-cloud/automl`);

const client = new automl.v1beta1.AutoMlClient();
const client = new automl.AutoMlClient();

/**
* TODO(developer): Uncomment the following line before running the sample.
Expand All @@ -110,6 +98,10 @@ async function listDatasets(projectId, computeRegion, filter) {
});

// Display the dataset information.
if (datasets.length === 0) {
console.log('No datasets found!');
return;
}
console.log(`List of datasets:`);
datasets.forEach(dataset => {
console.log(`Dataset name: ${dataset.name}`);
Expand All @@ -131,14 +123,12 @@ async function listDatasets(projectId, computeRegion, filter) {
console.log(`\tseconds: ${dataset.createTime.seconds}`);
console.log(`\tnanos: ${dataset.createTime.nanos}`);
});

// [END automl_translation_list_datasets]
}

async function getDataset(projectId, computeRegion, datasetId) {
// [START automl_translation_get_dataset]
const automl = require(`@google-cloud/automl`).v1beta1;

const automl = require(`@google-cloud/automl`);
const client = new automl.AutoMlClient();

/**
Expand Down Expand Up @@ -179,7 +169,7 @@ async function getDataset(projectId, computeRegion, datasetId) {

async function importData(projectId, computeRegion, datasetId, path) {
// [START automl_translation_import_data]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand Down Expand Up @@ -219,8 +209,7 @@ async function importData(projectId, computeRegion, datasetId, path) {

async function deleteDataset(projectId, computeRegion, datasetId) {
// [START automl_translation_delete_dataset]
const automl = require(`@google-cloud/automl`).v1beta1;

const automl = require(`@google-cloud/automl`);
const client = new automl.AutoMlClient();

/**
Expand Down Expand Up @@ -248,7 +237,7 @@ require(`yargs`)
computeRegion: {
alias: `c`,
type: `string`,
default: process.env.REGION_NAME,
default: 'us-central1',
requiresArg: true,
description: `region name e.g. "us-central1"`,
},
Expand Down Expand Up @@ -315,61 +304,26 @@ require(`yargs`)
description: `The target language to be translated to`,
},
})
.command(
`createDataset`,
`creates a new Dataset`,
{},
async opts =>
await createDataset(
opts.projectId,
opts.computeRegion,
opts.datasetName,
opts.source,
opts.target
).catch(console.error)
.command(`createDataset`, `creates a new Dataset`, {}, opts =>
createDataset(
opts.projectId,
opts.computeRegion,
opts.datasetName,
opts.source,
opts.target
)
)
.command(
`list-datasets`,
`list all Datasets`,
{},
async opts =>
await listDatasets(opts.projectId, opts.computeRegion, opts.filter).catch(
console.error
)
.command(`list-datasets`, `list all Datasets`, {}, opts =>
listDatasets(opts.projectId, opts.computeRegion, opts.filter)
)
.command(
`get-dataset`,
`Get a Dataset`,
{},
async opts =>
await getDataset(
opts.projectId,
opts.computeRegion,
opts.datasetId
).catch(console.error)
.command(`get-dataset`, `Get a Dataset`, {}, opts =>
getDataset(opts.projectId, opts.computeRegion, opts.datasetId)
)
.command(
`delete-dataset`,
`Delete a dataset`,
{},
async opts =>
await deleteDataset(
opts.projectId,
opts.computeRegion,
opts.datasetId
).catch(console.error)
.command(`delete-dataset`, `Delete a dataset`, {}, opts =>
deleteDataset(opts.projectId, opts.computeRegion, opts.datasetId)
)
.command(
`import-data`,
`Import labeled items into dataset`,
{},
async opts =>
await importData(
opts.projectId,
opts.computeRegion,
opts.datasetId,
opts.path
).catch(console.error)
.command(`import-data`, `Import labeled items into dataset`, {}, opts =>
importData(opts.projectId, opts.computeRegion, opts.datasetId, opts.path)
)
.example(`node $0 create-dataset -n "newDataSet" -s "en" -t "ja"`)
.example(`node $0 list-datasets -f "translationDatasetMetadata:*"`)
Expand Down
74 changes: 27 additions & 47 deletions samples/automl/automlTranslationModel.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

async function createModel(projectId, computeRegion, datasetId, modelName) {
// [START automl_translation_create_model]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand Down Expand Up @@ -80,7 +80,7 @@ async function createModel(projectId, computeRegion, datasetId, modelName) {

async function listModels(projectId, computeRegion, filter) {
// [START automl_translation_list_models]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand Down Expand Up @@ -122,7 +122,7 @@ async function listModels(projectId, computeRegion, filter) {

async function getModel(projectId, computeRegion, modelId) {
// [START automl_translation_get_model]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand Down Expand Up @@ -191,7 +191,7 @@ async function getModel(projectId, computeRegion, modelId) {

async function listModelEvaluations(projectId, computeRegion, modelId, filter) {
// [START automl_translation_list_model_evaluations]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand Down Expand Up @@ -227,8 +227,7 @@ async function getModelEvaluation(
) {
// [START automl_translation_get_model_evaluation]
const automl = require(`@google-cloud/automl`);

const client = new automl.v1beta1.AutoMlClient();
const client = new automl.AutoMlClient();

/**
* TODO(developer): Uncomment the following line before running the sample.
Expand Down Expand Up @@ -257,7 +256,7 @@ async function getModelEvaluation(

async function deleteModel(projectId, computeRegion, modelId) {
// [START automl_translation_delete_model]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand All @@ -282,7 +281,7 @@ async function deleteModel(projectId, computeRegion, modelId) {

async function getOperationStatus(operationFullId) {
// [START automl_translation_get_operation_status]
const automl = require(`@google-cloud/automl`).v1beta1;
const automl = require(`@google-cloud/automl`);

const client = new automl.AutoMlClient();

Expand All @@ -305,7 +304,7 @@ require(`yargs`)
computeRegion: {
alias: `c`,
type: `string`,
default: process.env.REGION_NAME,
default: 'us-central1',
requiresArg: true,
description: `region name e.g. "us-central1"`,
},
Expand Down Expand Up @@ -370,51 +369,32 @@ require(`yargs`)
`get-operation-status`,
`Gets status of current operation`,
{},
async opts =>
await getOperationStatus(opts.operationFullId).catch(console.error)
opts => getOperationStatus(opts.operationFullId)
)
.command(
`list-models`,
`list all Models`,
{},
async opts =>
await listModels(opts.projectId, opts.computeRegion, opts.filter).catch(
console.error
)
.command(`list-models`, `list all Models`, {}, opts =>
listModels(opts.projectId, opts.computeRegion, opts.filter)
)
.command(`get-model`, `Get a Model`, {}, opts =>
getModel(opts.projectId, opts.computeRegion, opts.modelId)
)
.command(
`list-model-evaluations`,
`List model evaluations`,
{},
async opts =>
await listModelEvaluations(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.filter
).catch(console.error)
.command(`list-model-evaluations`, `List model evaluations`, {}, opts =>
listModelEvaluations(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.filter
)
)
.command(
`get-model-evaluation`,
`Get model evaluation`,
{},
async opts =>
await getModelEvaluation(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.modelEvaluationId
)
.command(`get-model-evaluation`, `Get model evaluation`, {}, opts =>
getModelEvaluation(
opts.projectId,
opts.computeRegion,
opts.modelId,
opts.modelEvaluationId
)
)
.command(
`delete-model`,
`Delete a Model`,
{},
async opts =>
await deleteModel(opts.projectId, opts.computeRegion, opts.modelId)
.command(`delete-model`, `Delete a Model`, {}, opts =>
deleteModel(opts.projectId, opts.computeRegion, opts.modelId)
)
.example(`node $0 create-model -i "DatasetID" -m "myModelName"`)
.example(`node $0 get-operation-status -i "datasetId" -o "OperationFullID"`)
Expand Down
Loading