<commit_before>/**
 * 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 dataset
 * with the Google AutoML Translation API.
 *
 * For more information, see the documentation at
 * https://cloud.google.com/translate/automl/docs
 */

`use strict`;

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

  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" `;

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

  // Specify the source and target language.
  const datasetSpec = {
    sourceLanguageCode: source,
    targetLanguageCode: target,
  };

  // Set dataset name and dataset specification.
  const dataset = {
    displayName: datasetName,
    translationDatasetMetadata: datasetSpec,
  };

  // Create a dataset with the dataset specification in the region.
  client
    .createDataset({parent: projectLocation, dataset: dataset})
    .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(`Translation dataset specification:`);
      console.log(
        `\tSource language code: ${
          dataset.translationDatasetMetadata.sourceLanguageCode
        }`
      );
      console.log(
        `\tTarget language code: ${
          dataset.translationDatasetMetadata.targetLanguageCode
        }`
      );
      console.log(`Dataset create time:`);
      console.log(`\tseconds: ${dataset.createTime.seconds}`);
      console.log(`\tnanos: ${dataset.createTime.nanos}`);
    })
    .catch(err => {
      console.error(err);
    });
  // [END automl_translation_create_dataset]
}

function listDatasets(projectId, computeRegion, filter) {
  // [START automl_translation_list_datasets]
  const automl = require(`@google-cloud/automl`);

  const client = new automl.v1beta1.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 filter = `filter expressions, must specify field e.g. “imageClassificationModelMetadata:*”`;

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

  // List all the datasets available in the region by applying filter.
  client
    .listDatasets({parent: projectLocation, filter: filter})
    .then(responses => {
      const datasets = responses[0];

      // Display the dataset information.
      console.log(`List of datasets:`);
      datasets.forEach(dataset => {
        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(`Translation dataset specification:`);
        console.log(
          `\tSource language code: ${
            dataset.translationDatasetMetadata.sourceLanguageCode
          }`
        );
        console.log(
          `\tTarget language code: ${
            dataset.translationDatasetMetadata.targetLanguageCode
          }`
        );
        console.log(`Dataset create time:`);
        console.log(`\tseconds: ${dataset.createTime.seconds}`);
        console.log(`\tnanos: ${dataset.createTime.nanos}`);
      });
    })
    .catch(err => {
      console.error(err);
    });
  // [START automl_translation_list_datasets]
}

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

  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 datasetId = `Id of the dataset`;

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

  // Get complete detail of the dataset.
  client
    .getDataset({name: datasetFullId})
    .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(`Translation dataset specification:`);<commit_msg>samples: fixed incorrect end tag (#134)<commit_after>/**
 * 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 dataset
 * with the Google AutoML Translation API.
 *
 * For more information, see the documentation at
 * https://cloud.google.com/translate/automl/docs
 */

`use strict`;

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

  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" `;

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

  // Specify the source and target language.
  const datasetSpec = {
    sourceLanguageCode: source,
    targetLanguageCode: target,
  };

  // Set dataset name and dataset specification.
  const dataset = {
    displayName: datasetName,
    translationDatasetMetadata: datasetSpec,
  };

  // Create a dataset with the dataset specification in the region.
  client
    .createDataset({parent: projectLocation, dataset: dataset})
    .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(`Translation dataset specification:`);
      console.log(
        `\tSource language code: ${
          dataset.translationDatasetMetadata.sourceLanguageCode
        }`
      );
      console.log(
        `\tTarget language code: ${
          dataset.translationDatasetMetadata.targetLanguageCode
        }`
      );
      console.log(`Dataset create time:`);
      console.log(`\tseconds: ${dataset.createTime.seconds}`);
      console.log(`\tnanos: ${dataset.createTime.nanos}`);
    })
    .catch(err => {
      console.error(err);
    });
  // [END automl_translation_create_dataset]
}

function listDatasets(projectId, computeRegion, filter) {
  // [START automl_translation_list_datasets]
  const automl = require(`@google-cloud/automl`);

  const client = new automl.v1beta1.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 filter = `filter expressions, must specify field e.g. “imageClassificationModelMetadata:*”`;

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

  // List all the datasets available in the region by applying filter.
  client
    .listDatasets({parent: projectLocation, filter: filter})
    .then(responses => {
      const datasets = responses[0];

      // Display the dataset information.
      console.log(`List of datasets:`);
      datasets.forEach(dataset => {
        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(`Translation dataset specification:`);
        console.log(
          `\tSource language code: ${
            dataset.translationDatasetMetadata.sourceLanguageCode
          }`
        );
        console.log(
          `\tTarget language code: ${
            dataset.translationDatasetMetadata.targetLanguageCode
          }`
        );
        console.log(`Dataset create time:`);
        console.log(`\tseconds: ${dataset.createTime.seconds}`);
        console.log(`\tnanos: ${dataset.createTime.nanos}`);
      });
    })
    .catch(err => {
      console.error(err);
    });
  // [END automl_translation_list_datasets]
}

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

  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 datasetId = `Id of the dataset`;

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

  // Get complete detail of the dataset.
  client
    .getDataset({name: datasetFullId})
    .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(`Translation dataset specification:`);
{'fraction_non_alphanumeric': 0.12738017071569271, 'fraction_numerical': 0.00402166776099803, 'mean_word_length': 3.2965444287729198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5553986', 'n_tokens_mistral': 3414, 'n_tokens_neox': 3437, 'n_words': 950}