Last active
May 18, 2023 23:45
-
-
Save snippet-java/ec654cf14e8b221f7b84e4fc9ff84960 to your computer and use it in GitHub Desktop.
language translation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
//username: Your Username | |
//password: Your Password | |
version: 'v2' | |
}); | |
language_translation.translate({ | |
text: 'hello', | |
source: 'en', | |
target: 'es' | |
}, function(err, translation) { | |
if (err) | |
console.log(err) | |
else | |
console.log(translation); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation | |
language_translation = LanguageTranslation( | |
username='{username}', | |
password='{password}') | |
model_details = language_translation.get_model('{model_id}') | |
print(json.dumps(model_details, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
//username: Your Username | |
//password: Your Password | |
version: 'v2' | |
}); | |
language_translation.getIdentifiableLanguages(null, | |
function(err, languages) { | |
if (err) | |
console.log(err) | |
else | |
console.log(languages); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
username: '{username}', | |
password: '{password}', | |
version: 'v2' | |
}); | |
language_translation.identify({ text: 'this is a test'}, | |
function(err, identifiedLanguages) { | |
if (err) | |
console.log(err) | |
else | |
console.log(identifiedLanguages); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
username: '{username}', | |
password: '{password}', | |
version: 'v2' | |
}); | |
language_translation.getModels({}, function(err, models) { | |
if (err) | |
console.log(err) | |
else | |
console.log(models); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var fs = require('fs'); | |
var language_translation = watson.language_translation({ | |
username: '{username}', | |
password: '{password}', | |
version: 'v2' | |
}); | |
var params = { | |
name: 'custom-english-to-spanish', | |
base_model_id: 'en-es', | |
forced_glossary: fs.createReadStream('glossary.tmx') | |
}; | |
language_translation.createModel(params, | |
function(err, model) { | |
if (err) | |
console.log('error:', err); | |
else | |
console.log(JSON.stringify(model, null, 2)); | |
} | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation | |
language_translation = LanguageTranslation( | |
username='{username}', | |
password='{password}') | |
with open('glossary.tmx', 'rb') as training_data: | |
custom_model = language_translation.create_model( | |
base_model_id = 'en-es', | |
name = 'custom-english-to-spanish', | |
forced_glossary = training_data) | |
print(json.dumps(custom_model, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
username: '{username}', | |
password: '{password}', | |
version: 'v2' | |
}); | |
language_translation.deleteModel({ model_id:'{model_id}'}, | |
function(err) { | |
if (err) | |
console.log('error:', err); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation | |
language_translation = LanguageTranslation( | |
username='{username}', | |
password='{password}') | |
model = language_translation.delete_model('{model_id}') | |
print(json.dumps(model, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var watson = require('watson-developer-cloud'); | |
var language_translation = watson.language_translation({ | |
username: '{username}', | |
password: '{password}', | |
version: 'v2' | |
}); | |
language_translation.getModel({ model_id:'{model_id}'}, | |
function(err) { | |
if (err) | |
console.log('error:', err); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment