engine

package
v1.0.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2021 License: MIT Imports: 6 Imported by: 0

README

engine

import "github.com/Qithub-BOT/QiiTrans/src/engines/engine"

Package engine は、各翻訳エンジンの基本となる構造体とそのメソッドを定義しています.

Index

type AccountInfo

AccountInfo は、利用中の翻訳 API の必要最低限の情報を保持する構造体です.

type AccountInfo struct {
    CharacterLeft int // = 利用可能文字数 - 利用済み文字数
}

type Properties

Properties は各翻訳エンジンの基本となる構造体です. 翻訳エンジンが API を呼び出すのに必要な基本情報と、翻訳に使われるメソッド(クラス関数)を持った構造体です.

type Properties struct {
    // 翻訳済みのテキストをキャッシュするためのオブジェクトのポインタです
    Cache *cache.TCache

    // translate メソッドは、翻訳エンジンがインスタンス作成時に割り当てた関数です.
    // inputText を langFrom から langTo  翻訳した結果を返します。この値はキャッシュされません.
    translate func(properties *Properties, inputText string, langFrom string, langTo string) (string, error)

    // getInfoAPI メソッドは、翻訳エンジンがインスタンス作成時に割り当てた関数です.
    // アクセス・トークンのアカウント情報のうち、AccountInfo 型の情報だけ返します.
    getInfoAPI func(properties *Properties) (AccountInfo, error)

    // 環境変数からアクセス・トークンを取得する際の環境変数名
    NameVarEnvAPIKey string

    // 自動翻訳 API 用のアクセス・トークン(API キー)です。空の場合は環境変数から取得します。
    apiKey string

    // 1 リクエストごとに sleep させる秒数です(デフォルト: 1)
    TimeInterval int

    // アクセス・トークンが無料アカウントの場合は true、有料アカウントの場合は false にセットします。(デフォルト: true)
    IsAccountFree bool

    // true の場合はキャッシュを更新します。false の場合はなるべくキャッシュを使います(デフォルト: false)
    Update bool
}
func New
func New(cacheID ...string) *Properties

New は翻訳エンジンの基本構造体の新規オブジェクトのポインタを返します.

func (*Properties) GetAPIKey
func (p *Properties) GetAPIKey() string

GetAPIKey はコマンドのオプションで指定されたアクセス・トークンを返します. オプションで指定がされていない場合は、環境変数から読み取って返します.

func (*Properties) GetQuotaLeft
func (p *Properties) GetQuotaLeft() (int, error)

GetQuotaLeft は API のリクエスト残量(翻訳可能文字数)を返します。有料アカウントなど、制限がない場合は -1 を返します.

func (*Properties) SetAPIKey
func (p *Properties) SetAPIKey(apikey string) func()

SetAPIKey はコマンド引数から取得したアクセス・トークン "apikey" を翻訳エンジンが使えるようにセットします.

func (*Properties) SetDefault
func (p *Properties) SetDefault()

SetDefault はプロパティ(オブジェクトのフィールド)値を初期値に設定します.

func (*Properties) SetFuncGetInfoAPI
func (p *Properties) SetFuncGetInfoAPI(getInfoFunc func(properties *Properties) (AccountInfo, error))

SetFuncGetInfoAPI メソッドは翻訳用の関数を割り当てます.

func (*Properties) SetFuncTrans
func (p *Properties) SetFuncTrans(transFunc func(
    properties *Properties,
    inputText string,
    langFrom string,
    langTo string,
) (string, error))

SetFuncTrans メソッドは翻訳用の関数を割り当てます.

func (*Properties) Translate
func (p *Properties) Translate(inTxt string, langFrom string, langTo string) (outText string, isCache bool, err error)

Translate は翻訳エンジンから割り当てられた翻訳関数を実行し、inText を langFrom から langTo に翻訳した結果を返します. この値はキャッシュされます。キャッシュを更新したい場合は Update フィールド(プロパティ)を true にセットしてください.

func (*Properties) UniformLang
func (p *Properties) UniformLang(lang string) string

UniformLang は lang を API が検知可能な書式に変換します. もし lang が未対応の言語だった場合は、空の値を返します.


Generated by gomarkdoc

Documentation

Overview

Package engine は、各翻訳エンジンの基本となる構造体とそのメソッドを定義しています.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountInfo

type AccountInfo struct {
	CharacterLeft int // = 利用可能文字数 - 利用済み文字数
}

AccountInfo は、利用中の翻訳 API の必要最低限の情報を保持する構造体です.

type Properties

type Properties struct {
	// 翻訳済みのテキストをキャッシュするためのオブジェクトのポインタです
	Cache *cache.TCache

	// 環境変数からアクセス・トークンを取得する際の環境変数名
	NameVarEnvAPIKey string

	// 1 リクエストごとに sleep させる秒数です(デフォルト: 1)
	TimeInterval int

	// アクセス・トークンが無料アカウントの場合は true、有料アカウントの場合は false にセットします。(デフォルト: true)
	IsAccountFree bool

	// true の場合はキャッシュを更新します。false の場合はなるべくキャッシュを使います(デフォルト: false)
	Update bool
	// contains filtered or unexported fields
}

Properties は各翻訳エンジンの基本となる構造体です. 翻訳エンジンが API を呼び出すのに必要な基本情報と、翻訳に使われるメソッド(クラス関数)を持った構造体です.

func New

func New(cacheID ...string) *Properties

New は翻訳エンジンの基本構造体の新規オブジェクトのポインタを返します.

func (*Properties) GetAPIKey

func (p *Properties) GetAPIKey() string

GetAPIKey はコマンドのオプションで指定されたアクセス・トークンを返します. オプションで指定がされていない場合は、環境変数から読み取って返します.

func (*Properties) GetQuotaLeft

func (p *Properties) GetQuotaLeft() (int, error)

GetQuotaLeft は API のリクエスト残量(翻訳可能文字数)を返します。有料アカウントなど、制限がない場合は -1 を返します.

func (*Properties) SetAPIKey

func (p *Properties) SetAPIKey(apikey string) func()

SetAPIKey はコマンド引数から取得したアクセス・トークン "apikey" を翻訳エンジンが使えるようにセットします.

func (*Properties) SetDefault

func (p *Properties) SetDefault()

SetDefault はプロパティ(オブジェクトのフィールド)値を初期値に設定します.

func (*Properties) SetFuncGetInfoAPI

func (p *Properties) SetFuncGetInfoAPI(getInfoFunc func(properties *Properties) (AccountInfo, error))

SetFuncGetInfoAPI メソッドは翻訳用の関数を割り当てます.

func (*Properties) SetFuncTrans

func (p *Properties) SetFuncTrans(transFunc func(
	properties *Properties,
	inputText string,
	langFrom string,
	langTo string,
) (string, error))

SetFuncTrans メソッドは翻訳用の関数を割り当てます.

func (*Properties) Translate

func (p *Properties) Translate(inTxt string, langFrom string, langTo string) (outText string, isCache bool, err error)

Translate は翻訳エンジンから割り当てられた翻訳関数を実行し、inText を langFrom から langTo に翻訳した結果を返します. この値はキャッシュされます。キャッシュを更新したい場合は Update フィールド(プロパティ)を true にセットしてください.

func (*Properties) UniformLang

func (p *Properties) UniformLang(lang string) string

UniformLang は lang を API が検知可能な書式に変換します. もし lang が未対応の言語だった場合は、空の値を返します.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL