Skip to content

Commit ecd192d

Browse files
nirupa-kumarAce Nassri
authored and
Ace Nassri
committed
docs(samples): add language automl beta samples (#154)
* Language automl beta samples * Fixing errors
1 parent ddf0e53 commit ecd192d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3175
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetName = 'YOUR_DATASET_NAME'
21+
) {
22+
// [START automl_natural_language_entity_create_dataset]
23+
const automl = require(`@google-cloud/automl`);
24+
const util = require(`util`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to create a dataset
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const datasetName = '[DATASET_NAME]' e.g., "myDataset";
34+
35+
// A resource that represents Google Cloud Platform location.
36+
const projectLocation = client.locationPath(projectId, computeRegion);
37+
38+
// Set dataset name and metadata.
39+
const myDataset = {
40+
displayName: datasetName,
41+
textExtractionDatasetMetadata: {},
42+
};
43+
44+
// Create a dataset with the dataset metadata in the region.
45+
client
46+
.createDataset({parent: projectLocation, dataset: myDataset})
47+
.then(responses => {
48+
const dataset = responses[0];
49+
50+
// Display the dataset information.
51+
console.log(`Dataset name: ${dataset.name}`);
52+
console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
53+
console.log(`Dataset display name: ${dataset.displayName}`);
54+
console.log(`Dataset example count: ${dataset.exampleCount}`);
55+
console.log(
56+
`Text extraction dataset metadata: ${util.inspect(
57+
dataset.textExtractionDatasetMetadata,
58+
false,
59+
null
60+
)}`
61+
);
62+
})
63+
.catch(err => {
64+
console.error(err);
65+
});
66+
// [END automl_natural_language_entity_create_dataset]
67+
}
68+
main(...process.argv.slice(2)).catch(console.error());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetId = 'YOUR_DATASET_NAME',
21+
modelName = 'YOUR_MODEL_NAME'
22+
) {
23+
// [START automl_natural_language_entity_create_model]
24+
const automl = require(`@google-cloud/automl`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to create a model.
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952";
34+
// const modelName = '[MODEL_NAME]' e.g., "myModel";
35+
36+
// A resource that represents Google Cloud Platform location.
37+
const projectLocation = client.locationPath(projectId, computeRegion);
38+
39+
// Set datasetId, model name and model metadata for the dataset.
40+
const myModel = {
41+
displayName: modelName,
42+
datasetId: datasetId,
43+
textExtractionModelMetadata: {},
44+
};
45+
46+
// Create a model with the model metadata in the region.
47+
client
48+
.createModel({parent: projectLocation, model: myModel})
49+
.then(responses => {
50+
const initialApiResponse = responses[1];
51+
console.log(`Training operation name: ${initialApiResponse.name}`);
52+
console.log(`Training started...`);
53+
})
54+
.catch(err => {
55+
console.error(err);
56+
});
57+
// [END automl_natural_language_entity_create_model]
58+
}
59+
main(...process.argv.slice(2)).catch(console.error);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetId = 'YOUR_DATASET_ID'
21+
) {
22+
// [START automl_natural_language_entity_delete_dataset]
23+
const automl = require(`@google-cloud/automl`);
24+
const client = new automl.v1beta1.AutoMlClient();
25+
26+
/**
27+
* Demonstrates using the AutoML client to delete a dataset.
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
31+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
32+
// const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952";
33+
34+
// Get the full path of the dataset.
35+
const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId);
36+
37+
// Delete a dataset.
38+
client
39+
.deleteDataset({name: datasetFullId})
40+
.then(responses => {
41+
const operation = responses[0];
42+
return operation.promise();
43+
})
44+
.then(responses => {
45+
// The final result of the operation.
46+
const operationDetails = responses[2];
47+
48+
// Get the Dataset delete details.
49+
console.log('Dataset delete details:');
50+
console.log(`\tOperation details:`);
51+
console.log(`\t\tName: ${operationDetails.name}`);
52+
console.log(`\t\tDone: ${operationDetails.done}`);
53+
})
54+
.catch(err => {
55+
console.error(err);
56+
});
57+
// [END automl_natural_language_entity_delete_dataset]
58+
}
59+
main(...process.argv.slice(2)).catch(console.error());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
`use strict`;
18+
async function main(
19+
projectId = 'YOUR_PROJECT_ID',
20+
computeRegion = 'YOUR_REGION_NAME',
21+
modelId = 'YOUR_MODEL_ID'
22+
) {
23+
// [START automl_natural_language_entity_delete_model]
24+
const automl = require(`@google-cloud/automl`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to delete a model.
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";
34+
35+
// Get the full path of the model.
36+
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
37+
38+
// Delete a model.
39+
client
40+
.deleteModel({name: modelFullId})
41+
.then(responses => {
42+
const operation = responses[0];
43+
return operation.promise();
44+
})
45+
.then(responses => {
46+
// The final result of the operation.
47+
const operationDetails = responses[2];
48+
49+
// Get the Model delete details.
50+
console.log('Model delete details:');
51+
console.log(`\tOperation details:`);
52+
console.log(`\t\tName: ${operationDetails.name}`);
53+
console.log(`\tDone: ${operationDetails.done}`);
54+
})
55+
.catch(err => {
56+
console.error(err);
57+
});
58+
// [END automl_natural_language_entity_delete_model]
59+
}
60+
main(...process.argv.slice(2)).catch(console.error());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright 2019, Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
`use strict`;
17+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
modelId = 'YOUR_MODEL_ID'
21+
) {
22+
// [START automl_natural_language_entity_deploy_model]
23+
const automl = require(`@google-cloud/automl`);
24+
const client = new automl.v1beta1.AutoMlClient();
25+
26+
/**
27+
* Demonstrates using the AutoML client to deploy model.
28+
* TODO(developer): Uncomment the following lines before running the sample.
29+
*/
30+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
31+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
32+
// const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";
33+
34+
// Get the full path of the model.
35+
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
36+
37+
// Deploy a model with the deploy model request.
38+
client
39+
.deployModel({name: modelFullId})
40+
.then(responses => {
41+
const response = responses[0];
42+
console.log(`Deployment Details:`);
43+
console.log(`\tName: ${response.name}`);
44+
console.log(`\tMetadata:`);
45+
console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
46+
console.log(`\tDone: ${response.done}`);
47+
})
48+
.catch(err => {
49+
console.error(err);
50+
});
51+
// [END automl_natural_language_entity_deploy_model]
52+
}
53+
main(...process.argv.slice(2)).catch(console.error());

0 commit comments

Comments
 (0)