From 83d9232f1e65ecb245a59a9831edda0e12979d94 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Thu, 11 Oct 2018 12:18:36 -0500 Subject: [PATCH] chore(language-translator-v2): remove language translator v2 service and all associated code BREAKING CHANGE: The Language Translator V2 service will no longer be available To migrate your code, use the Language Translator V3 service. --- README.md | 46 -- examples/browserify/public/client.js | 2 +- examples/language_translator.v2.js | 41 -- examples/webpack/public/client.js | 2 +- index.ts | 2 - language-translator/v2-generated.ts | 557 ------------------ language-translator/v2.ts | 75 --- scripts/typedoc/generate_typedoc.sh | 2 +- test/integration/test.language_translator.js | 51 -- .../test.language_translator.v3.js | 4 +- test/unit/test.language_translator.v2.js | 233 -------- 11 files changed, 5 insertions(+), 1010 deletions(-) delete mode 100644 examples/language_translator.v2.js delete mode 100644 language-translator/v2-generated.ts delete mode 100644 language-translator/v2.ts delete mode 100644 test/integration/test.language_translator.js delete mode 100644 test/unit/test.language_translator.v2.js diff --git a/README.md b/README.md index 7096a4f1c0..1de29e755d 100755 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ Node.js client library to use the Watson APIs. * [Assistant v1](#assistant-v1) * [Discovery](#discovery) * [Language Translator v3](#language-translator-v3) - * [Language Translator v2](#language-translator-v2) * [Natural Language Classifier](#natural-language-classifier) * [Natural Language Understanding](#natural-language-understanding) * [Personality Insights](#personality-insights) @@ -421,51 +420,6 @@ languageTranslator.identify( ); ``` -### Language Translator v2 - -**Note:** Language Translator v3 is now available. The v2 Language Translator API will no longer be available after July 31, 2018. To take advantage of the latest service enhancements, migrate to the v3 API. View the [Migrating to Language Translator v3](https://console.bluemix.net/docs/services/language-translator/migrating.html) page for more information. - -Translate text from one language to another or idenfity a language using the [Language Translator][language_translator] service. - -```javascript -var LanguageTranslatorV2 = require('watson-developer-cloud/language-translator/v2'); - -var languageTranslator = new LanguageTranslatorV2({ - username: '', - password: '', - url: 'https://gateway.watsonplatform.net/language-translator/api/' -}); - -languageTranslator.translate( - { - text: 'A sentence must have a verb', - source: 'en', - target: 'es' - }, - function(err, translation) { - if (err) { - console.log('error:', err); - } else { - console.log(JSON.stringify(translation, null, 2)); - } -); - -languageTranslator.identify( - { - text: - 'The language translator service takes text input and identifies the language used.' - }, - function(err, language) { - if (err) { - console.log('error:', err); - } else { - console.log(JSON.stringify(language, null, 2)); - } - } -); -``` - - ### Natural Language Classifier Use [Natural Language Classifier](https://console.bluemix.net/docs/services/natural-language-classifier/getting-started.html) service to create a classifier instance by providing a set of representative strings and a set of one or more correct classes for each as training. Then use the trained classifier to classify your new question for best matching answers or to retrieve next actions for your application. diff --git a/examples/browserify/public/client.js b/examples/browserify/public/client.js index 968600e843..e645509ac4 100644 --- a/examples/browserify/public/client.js +++ b/examples/browserify/public/client.js @@ -3,7 +3,7 @@ // // * This file is bundled by exprss-browserify into bundle.js // -// * The require('watson-developer-cloud/language_translator/v2') could also be written as require('watson-developer-cloud').LanguageTranslatorV2, +// * The require('watson-developer-cloud/language_translator/v3') could also be written as require('watson-developer-cloud').LanguageTranslatorV3, // but that version results in a much larger bundle size. // // * Tokens expire after 1 hour. This demo simply fetches a new one for each translation rather than keeping a fresh one. diff --git a/examples/language_translator.v2.js b/examples/language_translator.v2.js deleted file mode 100644 index 3720f3fab9..0000000000 --- a/examples/language_translator.v2.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var LanguageTranslatorV2 = require('watson-developer-cloud/language-translator/v2'); -var fs = require('fs'); - -var languageTranslator = new LanguageTranslatorV2({ - username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE', - password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE', - url: 'https://gateway.watsonplatform.net/language-translator/api/' -}); - -languageTranslator.translate( - { - text: 'A sentence must have a verb', - source: 'en', - target: 'es' - }, - function(err, translation) { - if (err) { - console.log('error:', err); - } else { - console.log(JSON.stringify(translation, null, 2)); - } - } -); - -// Create a translation model using a tmx file -languageTranslator.createModel( - { - base_model_id: 'en-fr', - name: 'my-model', - forced_glossary: fs.createReadStream('resources/glossary.tmx') - }, - function(err, model) { - if (err) { - console.log('error:', err); - } else { - console.log(JSON.stringify(model, null, 2)); - } - } -); diff --git a/examples/webpack/public/client.js b/examples/webpack/public/client.js index 8f3f64e32a..1bc259c58a 100644 --- a/examples/webpack/public/client.js +++ b/examples/webpack/public/client.js @@ -3,7 +3,7 @@ // // * This file is bundled by webpack-dev-middleware into bundle.js // -// * The require('watson-developer-cloud/language_translator/v2') could also be written as require('watson-developer-cloud').LanguageTranslatorV2, +// * The require('watson-developer-cloud/language_translator/v3') could also be written as require('watson-developer-cloud').LanguageTranslatorV3, // but that version results in a much larger bundle size. // // * Tokens expire after 1 hour. This demo simply fetches a new one for each translation rather than keeping a fresh one. diff --git a/index.ts b/index.ts index 0f93788345..47bc412bf0 100644 --- a/index.ts +++ b/index.ts @@ -28,8 +28,6 @@ export import ConversationV1 = require('./conversation/v1'); export import DiscoveryV1 = require('./discovery/v1'); -export import LanguageTranslatorV2 = require('./language-translator/v2'); - export import LanguageTranslatorV3 = require('./language-translator/v3'); export import NaturalLanguageClassifierV1 = require('./natural-language-classifier/v1'); diff --git a/language-translator/v2-generated.ts b/language-translator/v2-generated.ts deleted file mode 100644 index 3a0a3c2e53..0000000000 --- a/language-translator/v2-generated.ts +++ /dev/null @@ -1,557 +0,0 @@ -/** - * Copyright 2018 IBM All Rights Reserved. - * - * 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. - */ - -import * as extend from 'extend'; -import { RequestResponse } from 'request'; -import { BaseService } from '../lib/base_service'; -import { getMissingParams } from '../lib/helper'; -import { FileObject } from '../lib/helper'; - -/** - * @deprecated Language Translator v3 is [available](https://www.ibm.com/watson/developercloud/language-translator/api/v3/). See the [migration guide](https://console.bluemix.net/docs/services/language-translator/migrating.html). --- IBM Watson™ Language Translator translates text from one language to another. The service offers multiple domain-specific models that you can customize based on your unique terminology and language. Use Language Translator to take news from across the globe and present it in your language, communicate with your customers in their own language, and more. - */ - -class LanguageTranslatorV2 extends BaseService { - - static URL: string = 'https://gateway.watsonplatform.net/language-translator/api'; - name: string; // set by prototype to 'language_translator' - serviceVersion: string; // set by prototype to 'v2' - - /** - * Construct a LanguageTranslatorV2 object. - * - * @param {Object} options - Options for the service. - * @param {string} [options.url] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net/language-translator/api'). The base url may differ between Bluemix regions. - * @param {string} [options.username] - The username used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable. - * @param {string} [options.password] - The password used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable. - * @param {string} [options.iam_access_token] - An IAM access token fully managed by the application. Responsibility falls on the application to refresh the token, either before it expires or reactively upon receiving a 401 from the service, as any requests made with an expired token will fail. - * @param {string} [options.iam_apikey] - An API key that can be used to request IAM tokens. If this API key is provided, the SDK will manage the token and handle the refreshing. - * @param {string} [options.iam_url] - An optional URL for the IAM service API. Defaults to 'https://iam.bluemix.net/identity/token'. - * @param {boolean} [options.use_unauthenticated] - Set to `true` to avoid including an authorization header. This option may be useful for requests that are proxied. - * @param {Object} [options.headers] - Default headers that shall be included with every request to the service. - * @param {boolean} [options.headers.X-Watson-Learning-Opt-Out] - Set to `true` to opt-out of data collection. By default, all IBM Watson services log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. If you are concerned with protecting the privacy of users' personal information or otherwise do not want your requests to be logged, you can opt out of logging. - * @constructor - * @returns {LanguageTranslatorV2} - */ - constructor(options: LanguageTranslatorV2.Options) { - super(options); - } - - /************************* - * translation - ************************/ - - /** - * Translate. - * - * Translates the input text from the source language to the target language. - * - * @param {Object} params - The parameters to send to the service. - * @param {string[]} params.text - Input text in UTF-8 encoding. Multiple entries will result in multiple translations - * in the response. - * @param {string} [params.model_id] - Model ID of the translation model to use. If this is specified, the **source** - * and **target** parameters will be ignored. The method requires either a model ID or both the **source** and - * **target** parameters. - * @param {string} [params.source] - Language code of the source text language. Use with `target` as an alternative - * way to select a translation model. When `source` and `target` are set, and a model ID is not set, the system - * chooses a default model for the language pair (usually the model based on the news domain). - * @param {string} [params.target] - Language code of the translation target language. Use with source as an - * alternative way to select a translation model. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public translate(params: LanguageTranslatorV2.TranslateParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = extend({}, params); - const _callback = (callback) ? callback : () => { /* noop */ }; - const requiredParams = ['text']; - const missingParams = getMissingParams(_params, requiredParams); - if (missingParams) { - return _callback(missingParams); - } - const body = { - 'text': _params.text, - 'model_id': _params.model_id, - 'source': _params.source, - 'target': _params.target - }; - const parameters = { - options: { - url: '/v2/translate', - method: 'POST', - json: true, - body, - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /************************* - * identification - ************************/ - - /** - * Identify language. - * - * Identifies the language of the input text. - * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.text - Input text in UTF-8 format. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public identify(params: LanguageTranslatorV2.IdentifyParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = extend({}, params); - const _callback = (callback) ? callback : () => { /* noop */ }; - const requiredParams = ['text']; - const missingParams = getMissingParams(_params, requiredParams); - if (missingParams) { - return _callback(missingParams); - } - const body = _params.text; - const parameters = { - options: { - url: '/v2/identify', - method: 'POST', - json: false, - body, - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - 'Content-Type': 'text/plain', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /** - * List identifiable languages. - * - * Lists the languages that the service can identify. Returns the language code (for example, `en` for English or `es` - * for Spanish) and name of each language. - * - * @param {Object} [params] - The parameters to send to the service. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public listIdentifiableLanguages(params?: LanguageTranslatorV2.ListIdentifiableLanguagesParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); - const _callback = (typeof params === 'function' && !callback) ? params : (callback) ? callback : () => {/* noop */}; - const parameters = { - options: { - url: '/v2/identifiable_languages', - method: 'GET', - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /************************* - * models - ************************/ - - /** - * Create model. - * - * Uploads a TMX glossary file on top of a domain to customize a translation model. - * - * Depending on the size of the file, training can range from minutes for a glossary to several hours for a large - * parallel corpus. Glossary files must be less than 10 MB. The cumulative file size of all uploaded glossary and - * corpus files is limited to 250 MB. - * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.base_model_id - The model ID of the model to use as the base for customization. To see - * available models, use the `List models` method. - * @param {string} [params.name] - An optional model name that you can use to identify the model. Valid characters are - * letters, numbers, dashes, underscores, spaces and apostrophes. The maximum length is 32 characters. - * @param {NodeJS.ReadableStream|FileObject|Buffer} [params.forced_glossary] - A TMX file with your customizations. - * The customizations in the file completely overwrite the domain translaton data, including high frequency or high - * confidence phrase translations. You can upload only one glossary with a file size less than 10 MB per call. - * @param {NodeJS.ReadableStream|FileObject|Buffer} [params.parallel_corpus] - A TMX file that contains entries that - * are treated as a parallel corpus instead of a glossary. - * @param {NodeJS.ReadableStream|FileObject|Buffer} [params.monolingual_corpus] - A UTF-8 encoded plain text file that - * is used to customize the target language model. - * @param {string} [params.forced_glossary_filename] - The filename for forced_glossary. - * @param {string} [params.parallel_corpus_filename] - The filename for parallel_corpus. - * @param {string} [params.monolingual_corpus_filename] - The filename for monolingual_corpus. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public createModel(params: LanguageTranslatorV2.CreateModelParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = extend({}, params); - const _callback = (callback) ? callback : () => { /* noop */ }; - const requiredParams = ['base_model_id']; - const missingParams = getMissingParams(_params, requiredParams); - if (missingParams) { - return _callback(missingParams); - } - const formData = { - 'forced_glossary': { - data: _params.forced_glossary, - filename: _params.forced_glossary_filename, - contentType: 'application/octet-stream' - }, - 'parallel_corpus': { - data: _params.parallel_corpus, - filename: _params.parallel_corpus_filename, - contentType: 'application/octet-stream' - }, - 'monolingual_corpus': { - data: _params.monolingual_corpus, - filename: _params.monolingual_corpus_filename, - contentType: 'text/plain' - } - }; - const query = { - 'base_model_id': _params.base_model_id, - 'name': _params.name - }; - const parameters = { - options: { - url: '/v2/models', - method: 'POST', - qs: query, - formData - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - 'Content-Type': 'multipart/form-data', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /** - * Delete model. - * - * Deletes a custom translation model. - * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.model_id - Model ID of the model to delete. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public deleteModel(params: LanguageTranslatorV2.DeleteModelParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = extend({}, params); - const _callback = (callback) ? callback : () => { /* noop */ }; - const requiredParams = ['model_id']; - const missingParams = getMissingParams(_params, requiredParams); - if (missingParams) { - return _callback(missingParams); - } - const path = { - 'model_id': _params.model_id - }; - const parameters = { - options: { - url: '/v2/models/{model_id}', - method: 'DELETE', - path, - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /** - * Get model details. - * - * Gets information about a translation model, including training status for custom models. - * - * @param {Object} params - The parameters to send to the service. - * @param {string} params.model_id - Model ID of the model to get. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public getModel(params: LanguageTranslatorV2.GetModelParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = extend({}, params); - const _callback = (callback) ? callback : () => { /* noop */ }; - const requiredParams = ['model_id']; - const missingParams = getMissingParams(_params, requiredParams); - if (missingParams) { - return _callback(missingParams); - } - const path = { - 'model_id': _params.model_id - }; - const parameters = { - options: { - url: '/v2/models/{model_id}', - method: 'GET', - path, - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - - /** - * List models. - * - * Lists available translation models. - * - * @param {Object} [params] - The parameters to send to the service. - * @param {string} [params.source] - Specify a language code to filter results by source language. - * @param {string} [params.target] - Specify a language code to filter results by target language. - * @param {boolean} [params.default_models] - If the default parameter isn't specified, the service will return all - * models (default and non-default) for each language pair. To return only default models, set this to `true`. To - * return only non-default models, set this to `false`. - * @param {Object} [params.headers] - Custom request headers - * @param {Function} [callback] - The callback that handles the response. - * @returns {NodeJS.ReadableStream|void} - */ - public listModels(params?: LanguageTranslatorV2.ListModelsParams, callback?: LanguageTranslatorV2.Callback): NodeJS.ReadableStream | void { - const _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); - const _callback = (typeof params === 'function' && !callback) ? params : (callback) ? callback : () => {/* noop */}; - const query = { - 'source': _params.source, - 'target': _params.target, - 'default': _params.default_models - }; - const parameters = { - options: { - url: '/v2/models', - method: 'GET', - qs: query, - }, - defaultOptions: extend(true, {}, this._options, { - headers: extend(true, { - 'Accept': 'application/json', - }, _params.headers), - }), - }; - return this.createRequest(parameters, _callback); - }; - -} - -LanguageTranslatorV2.prototype.name = 'language_translator'; -LanguageTranslatorV2.prototype.serviceVersion = 'v2'; - -/************************* - * interfaces - ************************/ - -namespace LanguageTranslatorV2 { - - /** Options for the `LanguageTranslatorV2` constructor. */ - export type Options = { - url?: string; - iam_access_token?: string; - iam_apikey?: string; - iam_url?: string; - username?: string; - password?: string; - use_unauthenticated?: boolean; - headers?: object; - } - - /** The callback for a service request. */ - export type Callback = (error: any, body?: T, response?: RequestResponse) => void; - - /** The body of a service request that returns no response data. */ - export interface Empty { } - - /************************* - * request interfaces - ************************/ - - /** Parameters for the `translate` operation. */ - export interface TranslateParams { - /** Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response. */ - text: string[]; - /** Model ID of the translation model to use. If this is specified, the **source** and **target** parameters will be ignored. The method requires either a model ID or both the **source** and **target** parameters. */ - model_id?: string; - /** Language code of the source text language. Use with `target` as an alternative way to select a translation model. When `source` and `target` are set, and a model ID is not set, the system chooses a default model for the language pair (usually the model based on the news domain). */ - source?: string; - /** Language code of the translation target language. Use with source as an alternative way to select a translation model. */ - target?: string; - headers?: Object; - } - - /** Parameters for the `identify` operation. */ - export interface IdentifyParams { - /** Input text in UTF-8 format. */ - text: string; - headers?: Object; - } - - /** Parameters for the `listIdentifiableLanguages` operation. */ - export interface ListIdentifiableLanguagesParams { - headers?: Object; - } - - /** Parameters for the `createModel` operation. */ - export interface CreateModelParams { - /** The model ID of the model to use as the base for customization. To see available models, use the `List models` method. */ - base_model_id: string; - /** An optional model name that you can use to identify the model. Valid characters are letters, numbers, dashes, underscores, spaces and apostrophes. The maximum length is 32 characters. */ - name?: string; - /** A TMX file with your customizations. The customizations in the file completely overwrite the domain translaton data, including high frequency or high confidence phrase translations. You can upload only one glossary with a file size less than 10 MB per call. */ - forced_glossary?: NodeJS.ReadableStream|FileObject|Buffer; - /** A TMX file that contains entries that are treated as a parallel corpus instead of a glossary. */ - parallel_corpus?: NodeJS.ReadableStream|FileObject|Buffer; - /** A UTF-8 encoded plain text file that is used to customize the target language model. */ - monolingual_corpus?: NodeJS.ReadableStream|FileObject|Buffer; - /** The filename for forced_glossary. */ - forced_glossary_filename?: string; - /** The filename for parallel_corpus. */ - parallel_corpus_filename?: string; - /** The filename for monolingual_corpus. */ - monolingual_corpus_filename?: string; - headers?: Object; - } - - /** Parameters for the `deleteModel` operation. */ - export interface DeleteModelParams { - /** Model ID of the model to delete. */ - model_id: string; - headers?: Object; - } - - /** Parameters for the `getModel` operation. */ - export interface GetModelParams { - /** Model ID of the model to get. */ - model_id: string; - headers?: Object; - } - - /** Parameters for the `listModels` operation. */ - export interface ListModelsParams { - /** Specify a language code to filter results by source language. */ - source?: string; - /** Specify a language code to filter results by target language. */ - target?: string; - /** If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to `true`. To return only non-default models, set this to `false`. */ - default_models?: boolean; - headers?: Object; - } - - /************************* - * model interfaces - ************************/ - - /** DeleteModelResult. */ - export interface DeleteModelResult { - /** "OK" indicates that the model was successfully deleted. */ - status: string; - } - - /** IdentifiableLanguage. */ - export interface IdentifiableLanguage { - /** The language code for an identifiable language. */ - language: string; - /** The name of the identifiable language. */ - name: string; - } - - /** IdentifiableLanguages. */ - export interface IdentifiableLanguages { - /** A list of all languages that the service can identify. */ - languages: IdentifiableLanguage[]; - } - - /** IdentifiedLanguage. */ - export interface IdentifiedLanguage { - /** The language code for an identified language. */ - language: string; - /** The confidence score for the identified language. */ - confidence: number; - } - - /** IdentifiedLanguages. */ - export interface IdentifiedLanguages { - /** A ranking of identified languages with confidence scores. */ - languages: IdentifiedLanguage[]; - } - - /** Translation. */ - export interface Translation { - /** Translation output in UTF-8. */ - translation_output: string; - } - - /** Response payload for models. */ - export interface TranslationModel { - /** A globally unique string that identifies the underlying model that is used for translation. */ - model_id: string; - /** Optional name that can be specified when the model is created. */ - name?: string; - /** Translation source language code. */ - source?: string; - /** Translation target language code. */ - target?: string; - /** Model ID of the base model that was used to customize the model. If the model is not a custom model, this will be an empty string. */ - base_model_id?: string; - /** The domain of the translation model. */ - domain?: string; - /** Whether this model can be used as a base for customization. Customized models are not further customizable, and some base models are not customizable. */ - customizable?: boolean; - /** Whether or not the model is a default model. A default model is the model for a given language pair that will be used when that language pair is specified in the source and target parameters. */ - default_model?: boolean; - /** Either an empty string, indicating the model is not a custom model, or the ID of the service instance that created the model. */ - owner?: string; - /** Availability of a model. */ - status?: string; - } - - /** The response type for listing existing translation models. */ - export interface TranslationModels { - /** An array of available models. */ - models: TranslationModel[]; - } - - /** TranslationResult. */ - export interface TranslationResult { - /** Number of words in the input text. */ - word_count: number; - /** Number of characters in the input text. */ - character_count: number; - /** List of translation output in UTF-8, corresponding to the input text entries. */ - translations: Translation[]; - } - -} - -export = LanguageTranslatorV2; diff --git a/language-translator/v2.ts b/language-translator/v2.ts deleted file mode 100644 index 6d56d4c0f8..0000000000 --- a/language-translator/v2.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2017 IBM All Rights Reserved. - * - * 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. - */ - -import isStream = require('isstream'); -import { getMissingParams } from '../lib/helper'; -import GeneratedLanguageTranslatorV2 = require('./v2-generated'); - -class LanguageTranslatorV2 extends GeneratedLanguageTranslatorV2 { - constructor(options) { - super(options); - if (!options['silent']) { - // eslint-disable-next-line no-console - console.warn( - 'WARNING: Language Translator V2 is deprecated and will be removed in the next major release of the SDK. Use Language Translator V3.' + - ' Set {silent: true} to disable this message.' - ); - } - } - - getModels(params, callback) { - console.warn("WARNING: getModels() was renamed to listModels(). Support for getModels() will be removed in the next major release"); - return super.listModels(params, callback); - } - - getModel(params, callback) { - return super.getModel(params, callback); - } - - createModel(params, callback) { - if (params) { - const inputTypes: string[] = [ - 'forced_glossary', - 'parallel_corpus', - 'monolingual_corpus' - ]; - inputTypes.forEach(type => { - if (params[type] && !isStream(params[type])) { - return callback( - new Error(`${type} is not a standard Node.js Stream`) - ); - } - }); - } - return super.createModel(params, callback); - } - - translate(params, callback) { - if (!params || !(params.model_id || (params.source && params.target))) { - return callback( - new Error('Missing required parameters: model_id or source and target') - ); - } - return super.translate(params, callback); - } - - getIdentifiableLanguages(params, callback) { - console.warn("WARNING: getIdentifiableLanguages() was renamed to listIdentifiableLanguages(). Support for getIdentifiableLanguages() will be removed in the next major release"); - return super.listIdentifiableLanguages(params, callback); - } -} - -export = LanguageTranslatorV2; diff --git a/scripts/typedoc/generate_typedoc.sh b/scripts/typedoc/generate_typedoc.sh index db9e301e7b..5e4a4d95be 100644 --- a/scripts/typedoc/generate_typedoc.sh +++ b/scripts/typedoc/generate_typedoc.sh @@ -1,6 +1,6 @@ ./node_modules/.bin/typedoc --mode file --theme ./scripts/typedoc/theme --excludeExternals \ --out ./doc ./authorization/v1.ts ./conversation/v1-generated.ts \ - ./discovery/v1-generated.ts ./language-translator/v2-generated.ts \ + ./discovery/v1-generated.ts ./language-translator/v3.ts \ ./natural-language-classifier/v1-generated.ts ./natural-language-understanding/v1.ts \ ./personality-insights/v3-generated.ts ./personality-insights/v2.ts \ ./speech-to-text/v1-generated.ts ./text-to-speech/v1-generated.ts \ diff --git a/test/integration/test.language_translator.js b/test/integration/test.language_translator.js deleted file mode 100644 index 11c2b3c2c4..0000000000 --- a/test/integration/test.language_translator.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -const nock = require('nock'); -const watson = require('../../index'); -const authHelper = require('./auth_helper.js'); -const auth = authHelper.auth; -const describe = authHelper.describe; // this runs describe.skip if there is no auth.js file :) -const TWENTY_SECONDS = 20000; -const TWO_SECONDS = 2000; - -// todo: figure out why these started all failing with Not Authorized -describe('language_translator_integration', function() { - this.timeout(TWENTY_SECONDS * 2); - this.slow(TWO_SECONDS); // this controls when the tests get a colored warning for taking too long - this.retries(1); - - let language_translator; - - before(function() { - language_translator = new watson.LanguageTranslatorV2(auth.language_translator.v2); - nock.enableNetConnect(); - }); - - after(function() { - nock.disableNetConnect(); - }); - - it('getModels()', function(done) { - language_translator.getModels(null, done); - }); - - it('translate()', function(done) { - const params = { - text: 'this is a test', - source: 'en', - target: 'es', - }; - language_translator.translate(params, done); - }); - - it('getIdentifiableLanguages()', function(done) { - language_translator.getIdentifiableLanguages(null, done); - }); - - it('identify()', function(done) { - const params = { - text: 'this is an important test that needs to work', - }; - language_translator.identify(params, done); - }); -}); diff --git a/test/integration/test.language_translator.v3.js b/test/integration/test.language_translator.v3.js index b4673d0963..4f0f0e028c 100644 --- a/test/integration/test.language_translator.v3.js +++ b/test/integration/test.language_translator.v3.js @@ -17,8 +17,8 @@ describe('language_translator_integration', function() { let language_translator; before(function() { - auth.language_translator.v3.version = '2018-05-01'; - language_translator = new watson.LanguageTranslatorV3(auth.language_translator.v3); + auth.language_translator.version = '2018-05-01'; + language_translator = new watson.LanguageTranslatorV3(auth.language_translator); nock.enableNetConnect(); }); diff --git a/test/unit/test.language_translator.v2.js b/test/unit/test.language_translator.v2.js deleted file mode 100644 index 4b0ecfe346..0000000000 --- a/test/unit/test.language_translator.v2.js +++ /dev/null @@ -1,233 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const watson = require('../../index'); -const nock = require('nock'); -const fs = require('fs'); - -describe('language_translator', function() { - const noop = function() {}; - - const service = { - username: 'batman', - password: 'bruce-wayne', - url: 'http://ibm.com:80', - }; - - before(function() { - nock.disableNetConnect(); - }); - - after(function() { - nock.cleanAll(); - }); - - const language_translator = new watson.LanguageTranslatorV2(service); - - const missingParameter = function(err) { - assert.ok(err instanceof Error && /required parameters/.test(err)); - }; - - describe('VCAP_SERVICES', function() { - let env; - before(function() { - env = process.env; - process.env = {}; - }); - after(function() { - process.env = env; - }); - - const details = [ - { - credentials: { - password: 'FAKE_PASSWORD', - url: 'https://gateway.watsonplatform.net/language-translator/api', - username: 'FAKE_USERNAME', - }, - label: 'language_translator', - name: 'Language Translator-4t', - plan: 'standard', - provider: null, - syslog_drain_url: null, - tags: ['watson', 'ibm_created', 'ibm_dedicated_public'], - }, - ]; - - it('should initialize with old-style VCAP_SERVICES credentials', function() { - process.env.VCAP_SERVICES = JSON.stringify({ - language_translator: details, - }); - const instance = new watson.LanguageTranslatorV2({ - version: '2016-07-01', - }); - assert(instance._options.headers.Authorization); - }); - - it('should initialize with new-style VCAP_SERVICES credentials', function() { - process.env.VCAP_SERVICES = JSON.stringify({ - language_translator: details, - }); - const instance = new watson.LanguageTranslatorV2({ - version: '2016-07-01', - }); - assert(instance._options.headers.Authorization); - }); - }); - - describe('getModels()', function() { - it('should generate a valid payload', function() { - const corpus = {}; - const path = '/v2/models'; - - nock(service.url) - .persist() - .get(path) - .reply(200, corpus); - - const req = language_translator.getModels(null, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'GET'); - }); - }); - - describe('translate()', function() { - it('should check no parameters provided', function() { - language_translator.translate({ source: '' }, missingParameter); - language_translator.translate({ target: '' }, missingParameter); - language_translator.translate({ text: '' }, missingParameter); - language_translator.translate({ model_id: '' }, missingParameter); - }); - - it('should generate a valid payload', function() { - const path = '/v2/translate'; - const service_request = { - text: 'bar', - model_id: 'foo', - }; - nock(service.url) - .persist() - .post(path, service_request) - .reply(200); - - const req = language_translator.translate(service_request, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'POST'); - const body = Buffer.from(req.body).toString('ascii'); - assert.equal(body, JSON.stringify(service_request)); - }); - }); - - describe('getIdentifiableLanguages()', function() { - it('should generate a valid payload', function() { - const path = '/v2/identifiable_languages'; - - nock(service.url) - .persist() - .get(path) - .reply(200); - - const req = language_translator.getIdentifiableLanguages(null, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'GET'); - }); - }); - - describe('identify()', function() { - it('should check no parameters provided', function() { - language_translator.identify({}, missingParameter); - language_translator.identify(null, missingParameter); - language_translator.identify(undefined, missingParameter); - }); - - it('should generate a valid payload', function() { - const path = '/v2/identify'; - const service_request = { text: 'foo' }; - nock(service.url) - .persist() - .post(path, service_request) - .reply(200); - - const req = language_translator.identify(service_request, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'POST'); - const body = Buffer.from(req.body).toString('ascii'); - assert.equal(body, service_request.text); - }); - }); - - describe('createModel()', function() { - it('should check no parameters provided', function() { - language_translator.createModel({}, missingParameter); - language_translator.createModel(null, missingParameter); - language_translator.createModel(undefined, missingParameter); - }); - - it('should generate a valid payload', function() { - const path = '/v2/models'; - const service_request = { - base_model_id: 'foo', - forced_glossary: fs.createReadStream(__dirname + '/../resources/glossary.tmx'), - parallel_corpus: fs.createReadStream(__dirname + '/../resources/glossary.tmx'), - monolingual_corpus: fs.createReadStream(__dirname + '/../resources/glossary.tmx'), - }; - - nock(service.url) - .persist() - .post(path, service_request) - .reply(200); - - const req = language_translator.createModel(service_request, noop); - assert.equal(req.uri.href, service.url + path + '?base_model_id=foo'); - assert.equal(req.method, 'POST'); - }); - }); - - describe('deleteModel()', function() { - it('should check no parameters provided', function() { - language_translator.deleteModel({}, missingParameter); - language_translator.deleteModel(null, missingParameter); - language_translator.deleteModel(undefined, missingParameter); - }); - - it('should generate a valid payload', function() { - const path = '/v2/models/foo'; - const service_request = { - model_id: 'foo', - }; - - nock(service.url) - .persist() - .delete(path, service_request) - .reply(200); - - const req = language_translator.deleteModel(service_request, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'DELETE'); - }); - }); - - describe('getModel()', function() { - it('should check no parameters provided', function() { - language_translator.getModel({}, missingParameter); - language_translator.getModel(null, missingParameter); - language_translator.getModel(undefined, missingParameter); - }); - - it('should generate a valid payload', function() { - const path = '/v2/models/foo'; - const service_request = { - model_id: 'foo', - }; - - nock(service.url) - .persist() - .get(path, service_request) - .reply(200); - - const req = language_translator.getModel(service_request, noop); - assert.equal(req.uri.href, service.url + path); - assert.equal(req.method, 'GET'); - }); - }); -});