<commit_before>// 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';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const {AutoMlClient} = require('@google-cloud/automl').v1;

const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const CREATE_MODEL_REGION_TAG = 'language_entity_extraction_create_model';
const LOCATION = 'us-central1';
const DATASET_ID = 'TEN8374527069979148288';

describe('Automl Natural Language Entity Extraction Create Model Test', () => {
  const client = new AutoMlClient();
  // let operationId;

  // Natural language entity extraction models are non cancellable operations
  it.skip('should create a model', async () => {
    const projectId = await client.getProjectId();

    const create_output = execSync(
      `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} extraction_test_create_model`
    );

    assert.match(create_output, /Training started/);

    // operationId = create_output
    //   .split('Training operation name: ')[1]
    //   .split('\n')[0];
  });

  // after('cancel model training', async () => {
  //   await client.operationsClient.cancelOperation({name: operationId});
  // });
});
<commit_msg>docs: use a fake dataset to make create model testable (#306)<commit_after>// 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';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const {AutoMlClient} = require('@google-cloud/automl').v1;

const cp = require('child_process');

const CREATE_MODEL_REGION_TAG = 'language_entity_extraction_create_model.js';
const LOCATION = 'us-central1';
const DATASET_ID = 'TEN0000000000000000000';

describe('Automl Natural Language Entity Extraction Create Model Test', () => {
  const client = new AutoMlClient();
  // let operationId;

  // Natural language entity extraction models are non cancellable operations
  it('should create a model', async () => {
    // As entity extraction does not let you cancel model creation, instead try
    // to create a model from a nonexistent dataset, but other elements of the
    // request were valid.
    const projectId = await client.getProjectId();
    const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID];
    const output = cp.spawnSync('node', args, {encoding: 'utf8'});

    assert.match(output.stderr, /NOT_FOUND/);
    assert.match(output.stderr, /Dataset does not exist./);
  });
});

{'fraction_non_alphanumeric': 0.11957434892187062, 'fraction_numerical': 0.018202184262111454, 'mean_word_length': 4.01685393258427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '6959108', 'n_tokens_mistral': 1055, 'n_tokens_neox': 995, 'n_words': 367}