Title: | Interface to 'TexTra' from R |
Version: | 0.8.0 |
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. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
URL: | https://github.com/matutosi/textrar |
Imports: | jsonlite, httr |
Suggests: | knitr, rmarkdown, spelling |
Language: | en-US |
Depends: | R (≥ 2.10) |
NeedsCompilation: | no |
Packaged: | 2024-04-23 05:25:07 UTC; matutosi |
Author: | Toshikazu Matsumura
|
Maintainer: | Toshikazu Matsumura <matutosi@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-04-23 11:50:03 UTC |
Return the base URL for the API
Description
Return the base URL for the API
Usage
base_url()
Value
A string containing the base URL.
Examples
base_url()
Extract Translated Text from Response
Description
This function extracts the translated text from the response.
returned by the post_request()
function.
Usage
extract_result(res)
Arguments
res |
The response object returned by the |
Value
A character string containing the translated text.
Examples
## Not run:
res <- post_request(paramas, "Hello world!")
translated <- extract_result(res)
## End(Not run)
Generate parameters for API call
Description
This function generates a list of parameters that can be used to make an API call.
Usage
gen_params(key, secret, name, api_name = "mt")
Arguments
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". |
Value
A list of parameters.
Examples
## 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)
Get Access Token
Description
This function retrieves an access token from the API using the provided key and secret.
Usage
get_token(key, secret)
Arguments
key |
The API key. |
secret |
The API secret. |
Value
A character string containing the access token.
Examples
## Not run:
key <- "abcdefghijklmnopqrstuvw01234567890abcdef1" # API key
secret <- "xyzabcdefghijklmnopqrstuvw012345" # API secret
token <- get_token(key = key, secret = secret)
## End(Not run)
Send a POST request to the API
Description
This function sends a POST request to the API with the specified parameters and text.
Usage
post_request(params, text)
Arguments
params |
A list of parameters to be passed to the API. |
text |
The text to be translated. |
Value
The response from the API.
Examples
## Not run:
post_request(params = , text = "Hello, world!")
## End(Not run)
Translate text using Transliteration Model
Description
This function translates text using a transliteration model.
Usage
textra(text, params, model = "transLM", from = "en", to = "ja")
Arguments
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. |
Value
The translated text.
Examples
## 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)