Title: | Interface to 'TexTra' from R |
---|---|
Description: | A wrapper for the 'TexTra' API <https://mt-auto-minhon-mlt.ucri.jgn-x.jp/>, a web service for translating texts between different languages. 'TexTra' API account is required to use the service. |
Authors: | Toshikazu Matsumura [aut, cre]
|
Maintainer: | Toshikazu Matsumura <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.8.0 |
Built: | 2025-01-22 03:55:49 UTC |
Source: | https://github.com/matutosi/textrar |
Return the base URL for the API
base_url()
base_url()
A string containing the base URL.
base_url()
base_url()
This function extracts the translated text from the response.
returned by the post_request()
function.
extract_result(res)
extract_result(res)
res |
The response object returned by the |
A character string containing the translated text.
## Not run: res <- post_request(paramas, "Hello world!") translated <- extract_result(res) ## End(Not run)
## Not run: res <- post_request(paramas, "Hello world!") translated <- extract_result(res) ## End(Not run)
This function generates a list of parameters that can be used to make an API call.
gen_params(key, secret, name, api_name = "mt")
gen_params(key, secret, name, api_name = "mt")
key |
The API key. |
secret |
The API secret. |
name |
The name of the API. |
api_name |
The name of the API to use. Defaults to "mt". |
A list of parameters.
## Not run: key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret name <- "login_ID" # login_ID params <- gen_params(key = key, secret = secret, name = name) ## End(Not run)
## Not run: key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret name <- "login_ID" # login_ID params <- gen_params(key = key, secret = secret, name = name) ## End(Not run)
This function retrieves an access token from the API using the provided key and secret.
get_token(key, secret)
get_token(key, secret)
key |
The API key. |
secret |
The API secret. |
A character string containing the access token.
## Not run: key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret token <- get_token(key = key, secret = secret) ## End(Not run)
## Not run: key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret token <- get_token(key = key, secret = secret) ## End(Not run)
This function sends a POST request to the API with the specified parameters and text.
post_request(params, text)
post_request(params, text)
params |
A list of parameters to be passed to the API. |
text |
The text to be translated. |
The response from the API.
## Not run: post_request(params = , text = "Hello, world!") ## End(Not run)
## Not run: post_request(params = , text = "Hello, world!") ## End(Not run)
This function translates text using a transliteration model.
textra(text, params, model = "transLM", from = "en", to = "ja")
textra(text, params, model = "transLM", from = "en", to = "ja")
text |
The text to be translated. |
params |
A list of parameters to be passed to the API. |
model |
The model to be used for translation. |
from |
The source language. |
to |
The target language. |
The translated text.
## Not run: text <- "Hello world" key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret name <- "login_ID" # login_ID params <- gen_params(key = key, secret = secret, name = name) translated <- textra(text, params, model = "transLM", from = "en", to = "ja") translated ## End(Not run)
## Not run: text <- "Hello world" key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret name <- "login_ID" # login_ID params <- gen_params(key = key, secret = secret, name = name) translated <- textra(text, params, model = "transLM", from = "en", to = "ja") translated ## End(Not run)