Skip to content

Commit

Permalink
docs(samples): add language automl beta samples (#154)
Browse files Browse the repository at this point in the history
* Language automl beta samples

* Fixing errors
  • Loading branch information
nirupa-kumar authored Apr 5, 2019
1 parent dfd296c commit 624398a
Show file tree
Hide file tree
Showing 42 changed files with 3,175 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetName = 'YOUR_DATASET_NAME'
) {
// [START automl_natural_language_entity_create_dataset]
const automl = require(`@google-cloud/automl`);
const util = require(`util`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to create a dataset
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetName = '[DATASET_NAME]' e.g., "myDataset";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// Set dataset name and metadata.
const myDataset = {
displayName: datasetName,
textExtractionDatasetMetadata: {},
};

// Create a dataset with the dataset metadata in the region.
client
.createDataset({parent: projectLocation, dataset: myDataset})
.then(responses => {
const dataset = responses[0];

// Display the dataset information.
console.log(`Dataset name: ${dataset.name}`);
console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
console.log(`Dataset display name: ${dataset.displayName}`);
console.log(`Dataset example count: ${dataset.exampleCount}`);
console.log(
`Text extraction dataset metadata: ${util.inspect(
dataset.textExtractionDatasetMetadata,
false,
null
)}`
);
})
.catch(err => {
console.error(err);
});
// [END automl_natural_language_entity_create_dataset]
}
main(...process.argv.slice(2)).catch(console.error());
59 changes: 59 additions & 0 deletions automl/snippets/language/entity-extraction/create-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetId = 'YOUR_DATASET_NAME',
modelName = 'YOUR_MODEL_NAME'
) {
// [START automl_natural_language_entity_create_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to create a model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952";
// const modelName = '[MODEL_NAME]' e.g., "myModel";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// Set datasetId, model name and model metadata for the dataset.
const myModel = {
displayName: modelName,
datasetId: datasetId,
textExtractionModelMetadata: {},
};

// Create a model with the model metadata in the region.
client
.createModel({parent: projectLocation, model: myModel})
.then(responses => {
const initialApiResponse = responses[1];
console.log(`Training operation name: ${initialApiResponse.name}`);
console.log(`Training started...`);
})
.catch(err => {
console.error(err);
});
// [END automl_natural_language_entity_create_model]
}
main(...process.argv.slice(2)).catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
datasetId = 'YOUR_DATASET_ID'
) {
// [START automl_natural_language_entity_delete_dataset]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to delete a dataset.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952";

// Get the full path of the dataset.
const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId);

// Delete a dataset.
client
.deleteDataset({name: datasetFullId})
.then(responses => {
const operation = responses[0];
return operation.promise();
})
.then(responses => {
// The final result of the operation.
const operationDetails = responses[2];

// Get the Dataset delete details.
console.log('Dataset delete details:');
console.log(`\tOperation details:`);
console.log(`\t\tName: ${operationDetails.name}`);
console.log(`\t\tDone: ${operationDetails.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_natural_language_entity_delete_dataset]
}
main(...process.argv.slice(2)).catch(console.error());
60 changes: 60 additions & 0 deletions automl/snippets/language/entity-extraction/delete-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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`;
`use strict`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
modelId = 'YOUR_MODEL_ID'
) {
// [START automl_natural_language_entity_delete_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to delete a model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";

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

// Delete a model.
client
.deleteModel({name: modelFullId})
.then(responses => {
const operation = responses[0];
return operation.promise();
})
.then(responses => {
// The final result of the operation.
const operationDetails = responses[2];

// Get the Model delete details.
console.log('Model delete details:');
console.log(`\tOperation details:`);
console.log(`\t\tName: ${operationDetails.name}`);
console.log(`\tDone: ${operationDetails.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_natural_language_entity_delete_model]
}
main(...process.argv.slice(2)).catch(console.error());
53 changes: 53 additions & 0 deletions automl/snippets/language/entity-extraction/deploy-model.v1beta1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
modelId = 'YOUR_MODEL_ID'
) {
// [START automl_natural_language_entity_deploy_model]
const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
* Demonstrates using the AutoML client to deploy model.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";

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

// Deploy a model with the deploy model request.
client
.deployModel({name: modelFullId})
.then(responses => {
const response = responses[0];
console.log(`Deployment Details:`);
console.log(`\tName: ${response.name}`);
console.log(`\tMetadata:`);
console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
console.log(`\tDone: ${response.done}`);
})
.catch(err => {
console.error(err);
});
// [END automl_natural_language_entity_deploy_model]
}
main(...process.argv.slice(2)).catch(console.error());
Loading

0 comments on commit 624398a

Please sign in to comment.