textra

package module
v0.0.0-...-3e16094 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 8 Imported by: 1

README

go-textra

Go Reference

This is a library that translates with みんなの自動翻訳(minnano-jidou-honyaku)@textra's API clinet.

You need a textra account.

package main

import (
	"fmt"
	"log"

	"github.com/noborus/go-textra"
)

var config = textra.Config{
	ClientID:     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // API key
	ClientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",  // API secret
	Name:         "UserID", // UserID
}

func main() {
	cli,err := textra.New(config)
	if err != nil {
		log.Fatal(err)
	}

	ja, err := cli.Translate(textra.GENERAL_EN_JA, "This is a pen.")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ja) // これはペンです。
}

Documentation

Index

Constants

View Source
const (
	APIKeyError                     = 500 // API key error
	NameError                       = 501 // Name error
	MaximumRequestDayError          = 502 // Maximum request error(day)
	MaximumRequestMinError          = 504 // Maximum request error(min)
	MaximumRequestSimultaneousError = 505 // Maximum request error (simultaneous requests)
	OAuthAuthenticationError        = 510 // OAuth authentication error
	OAuthHeaderError                = 511 // OAuth header error
	AccessURLError                  = 520 // Access URL error
	AccessURL2Error                 = 521 // Access URL error
	RequestKeyError                 = 522 // Request key error
	RequestNameError                = 523 // Request name error
	RequestParameterError           = 524 // Request parameter error
	RequestParameterSizeError       = 525 // Request parameter error (for data size limit)
	AuthorizationError              = 530 // Authorization error
	ExecutionError                  = 531 // Execution error
	Nodata                          = 532 // No data
)

API Process error code.

View Source
const (
	// General - NT 【English - Japanese】 汎用NT 【英語 - 日本語】
	GENERAL_EN_JA = "generalNT_en_ja"
	// Patents - NT 特許NT 【英語 - 日本語】
	PATENTNT_EN_JA = "patentNT_en_ja"
	// 対話NT(音声翻訳エンジン専用) 【英語 - 日本語】
	VOICETRANT_EN_JA = "voicetraNT_en_ja"
	// Finance - NT 金融NT 【英語 - 日本語】
	FSANT_EN_JA = "fsaNT_ja_en"
	// 法令契約NT 【英語 - 日本語】
	LAWSNT_EN_JA = "lawsNT_ja_en"
	// General - NT+ (For Experimental Use Only / Technology Transfer Not Allowed) 【English - Japanese】
	// 汎用NT+(実験用・技術移転不可) 【英語 - 日本語】
	MINNSNONT_EN_JA = "minnaNT_en_ja"

	// General - NT 【Japanese - English】
	GENERAL_JA_EN = "generalNT_ja_en"
	// Patents - NT 特許NT 【英語 - 日本語】
	PATENTNT_JA_EN = "patentNT_ja_en"
	// 対話NT(音声翻訳エンジン専用) 【英語 - 日本語】
	VOICETRANT_JA_EN = "voicetraNT_ja_en"
	// Finance - NT 金融NT 【英語 - 日本語】
	FSANT_JA_EN = "fsaNT_ja_en"
	// 法令契約NT 【英語 - 日本語】
	LAWSNT_JA_EN = "lawsNT_ja_en"
	// General - NT+ (For Experimental Use Only / Technology Transfer Not Allowed)
	// 汎用NT+(実験用・技術移転不可) 【英語 - 日本語】
	MINNSNONT_JA_EN = "minnaNT_ja_en"
)

Machine translation engine.

View Source
const APIURL = "https://mt-auto-minhon-mlt.ucri.jgn-x.jp/"
View Source
const BILINGUAL = "bilingual"

Bilingual entries.

View Source
const BILINGUALROOT = "bilingual_root"

List of bilingual entries.

View Source
const LOOKUP = "lookup"

Machine translation request.

View Source
const MT = "mt"

Machine translation request entries.

View Source
const TERM = "term"

Glossary entries.

View Source
const TERMROOT = "term_root"

List of glossaries entries.

Variables

This section is empty.

Functions

This section is empty.

Types

type BilingualRooListResult

type BilingualRooListResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Total   int    `json:"total"`
		Request struct {
			URL    string `json:"url"`
			Limit  int    `json:"limit"`
			Offset int    `json:"offset"`
		} `json:"request"`
		Result struct {
			List []BilingualRootList `json:"list"`
		} `json:"result"`
	} `json:"resultset"`
}

type BilingualRootList

type BilingualRootList struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	SourceLanguage string `json:"source_language"`
	TargetLanguage string `json:"target_language"`
	Provide        int    `json:"provide"`
	ProvideTarget  string `json:"provide_target"`
}

type BilingualRootRequest

type BilingualRootRequest struct {
	LangS  string `json:"lang_s"`
	LangT  string `json:"lang_t"`
	Order  string `json:"order"`
	Limit  string `json:"limit"`
	Offset string `json:"offset"`
}

type BilingualSearchItem

type BilingualSearchItem struct {
	Pid    int    `json:"pid"`
	Cid    int    `json:"cid"`
	Source string `json:"source"`
	Target string `json:"target"`
}

type BilingualSearchRequest

type BilingualSearchRequest struct {
	Text      string `json:"text"`
	MatchType string `json:"match_type"`
	Pid       string `json:"pid"`
	Order     string `json:"order"`
	Limit     string `json:"limit"`
	Offset    string `json:"offset"`
}

type BilingualSearchResult

type BilingualSearchResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL    string `json:"url"`
			Limit  int    `json:"limit"`
			Offset int    `json:"offset"`
		} `json:"request"`
		Result struct {
			Bilingual []BilingualSearchItem `json:"bilingual"`
		} `json:"result"`
	} `json:"resultset"`
}

type BilingualSetResult

type BilingualSetResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL string `json:"url"`
		} `json:"request"`
		Result struct {
			Pid int `json:"pid"`
			Cid int `json:"cid"`
		} `json:"result"`
	} `json:"resultset"`
}

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	Name         string
}

type LookUpResult

type LookUpResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL   string `json:"url"`
			Text  string `json:"text"`
			Split int    `json:"split"`
			Data  string `json:"data"`
		} `json:"request"`
		Result struct {
			Lookup []LookupItem `json:"lookup"`
		} `json:"result"`
	} `json:"resultset"`
}

type LookupItem

type LookupItem struct {
	Position string `json:"position"`
	Length   int    `json:"length"`
	Hit      string `json:"hit"`
	Term     []struct {
		ID     interface{} `json:"id"`
		Pid    string      `json:"pid"`
		Source string      `json:"source"`
		Target string      `json:"target"`
	} `json:"term"`
}

type MTInformation

type MTInformation struct {
	TextS    string `json:"text-s"`
	TextT    string `json:"text-t"`
	Sentence []struct {
		TextS string `json:"text-s"`
		TextT string `json:"text-t"`
		Split []struct {
			TextS   string `json:"text-s"`
			TextT   string `json:"text-t"`
			Process struct {
				Regex []struct {
					Text    string `json:"text"`
					Result  string `json:"result"`
					Pattern string `json:"pattern"`
					Replace string `json:"replace"`
				} `json:"regex"`
				ReplaceBefore []struct {
					TextS string `json:"text-s"`
					TextT string `json:"text-t"`
					TermS string `json:"term-s"`
					TermT string `json:"term-t"`
				} `json:"replace-before"`
				Preprocess []interface{} `json:"preprocess"`
				Translate  struct {
					Reverse []struct {
						Selected int    `json:"selected"`
						IDN      int    `json:"id-n"`
						IDR      int    `json:"id-r"`
						NameN    string `json:"name-n"`
						NameR    string `json:"name-r"`
						TextS    string `json:"text-s"`
						TextT    string `json:"test-t"`
						TextR    string `json:"test-r"`
						Score    int    `json:"score"`
					} `json:"reverse"`
					Specification []interface{}     `json:"specification"`
					TextS         string            `json:"text-s"`
					TextT         string            `json:"text-t"`
					Associate     [][]interface{}   `json:"associate"`
					Oov           interface{}       `json:"oov"`
					Exception     string            `json:"exception"`
					Associates    [][][]interface{} `json:"associates"`
				} `json:"translate"`
				ReplaceAfter []struct {
					TextS string `json:"text-s"`
					TextT string `json:"text-t"`
					TermS string `json:"term-s"`
					TermT string `json:"term-t"`
				} `json:"replace-after"`
			} `json:"process"`
		} `json:"split"`
	} `json:"sentence"`
}

func MTInfoDecode

func MTInfoDecode(result *MTResult) (*MTInformation, error)

type MTResult

type MTResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL   string `json:"url"`
			Text  string `json:"text"`
			Split int    `json:"split"`
			Data  string `json:"data"`
		} `json:"request"`
		Result struct {
			Text        string `json:"text"`
			Information json.RawMessage
		} `json:"result"`
	} `json:"resultset"`
}

type TermRootList

type TermRootList struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	SourceLanguage string `json:"source_language"`
	TargetLanguage string `json:"target_language"`
	Provide        int    `json:"provide"`
}

type TermRootRequest

type TermRootRequest struct {
	LangS  string `json:"lang_s"`
	LangT  string `json:"lang_t"`
	Order  string `json:"order"`
	Limit  string `json:"limit"`
	Offset string `json:"offset"`
}

type TermRootSetResult

type TermRootSetResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Total   int    `json:"total"`
		Request struct {
			URL    string `json:"url"`
			Limit  int    `json:"limit"`
			Offset int    `json:"offset"`
		} `json:"request"`
		Result struct {
			List []TermRootList `json:"list"`
		} `json:"result"`
	} `json:"resultset"`
}

type TermSearchRequest

type TermSearchRequest struct {
	Text      string `json:"text"`
	MatchType string `json:"match_type"`
	Pid       string `json:"pid"`
	Order     string `json:"order"`
	Limit     string `json:"limit"`
	Offset    string `json:"offset"`
}

type TermSearchResult

type TermSearchResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL    string `json:"url"`
			Limit  int    `json:"limit"`
			Offset int    `json:"offset"`
		} `json:"request"`
		Result struct {
			Term []TermSearchTerm `json:"term"`
		} `json:"result"`
	} `json:"resultset"`
}

type TermSearchTerm

type TermSearchTerm struct {
	Pid    int    `json:"pid"`
	Cid    int    `json:"cid"`
	Source string `json:"source"`
	Target string `json:"target"`
}

type TermSetResult

type TermSetResult struct {
	Resultset struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Request struct {
			URL string `json:"url"`
		} `json:"request"`
		Result struct {
			Pid int `json:"pid"`
			Cid int `json:"cid"`
		} `json:"result"`
	} `json:"resultset"`
}

func BilingualSetDecode

func BilingualSetDecode(jsonStr []byte) (*TermSetResult, error)

type TexTra

type TexTra struct {
	ClientID     string
	ClientSecret string
	Name         string
	APIName      string
	APIParam     string
	// contains filtered or unexported fields
}

func New

func New(c Config) (*TexTra, error)

func (*TexTra) BilingualDelete

func (tra *TexTra) BilingualDelete(pid string, cid string) (int, int, error)

func (*TexTra) BilingualRootDecode

func (tra *TexTra) BilingualRootDecode(ret []byte) (*BilingualRooListResult, error)

func (*TexTra) BilingualRootGet

func (tra *TexTra) BilingualRootGet(request *BilingualRootRequest) ([]BilingualRootList, error)

func (*TexTra) BilingualSearch

func (tra *TexTra) BilingualSearch(request *BilingualSearchRequest) ([]BilingualSearchItem, error)

func (*TexTra) BilingualSearchDecode

func (tra *TexTra) BilingualSearchDecode(ret []byte) (*BilingualSearchResult, error)

func (*TexTra) BilingualSet

func (tra *TexTra) BilingualSet(pid string, textS string, textT string) (int, int, error)

func (*TexTra) BilingualUpdate

func (tra *TexTra) BilingualUpdate(pid string, cid string, textS string, textT string) (int, int, error)

func (*TexTra) Lookup

func (tra *TexTra) Lookup(text string, pid string, langS string) ([]LookupItem, error)

func (*TexTra) TermDel

func (tra *TexTra) TermDel(pid string, cid string) (int, int, error)

func (*TexTra) TermRootDecode

func (tra *TexTra) TermRootDecode(ret []byte) (*TermRootSetResult, error)

func (*TexTra) TermRootGet

func (tra *TexTra) TermRootGet(request *TermRootRequest) ([]TermRootList, error)

func (*TexTra) TermSearch

func (tra *TexTra) TermSearch(request *TermSearchRequest) ([]TermSearchTerm, error)

func (*TexTra) TermSearchDecode

func (tra *TexTra) TermSearchDecode(ret []byte) (*TermSearchResult, error)

func (*TexTra) TermSet

func (tra *TexTra) TermSet(pid string, textS string, textT string) (int, int, error)

func (*TexTra) TermUpdate

func (tra *TexTra) TermUpdate(pid string, cid string, textS string, textT string) (int, int, error)

func (*TexTra) Translate

func (tra *TexTra) Translate(apiType string, source string) (string, error)

func (*TexTra) TranslateRaw

func (tra *TexTra) TranslateRaw(apiType string, source string) (*MTResult, error)

Jump to

Keyboard shortcuts

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