Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
package model
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Language string
|
|
type Source string
|
|
type PartOfSpeech string
|
|
|
|
const (
|
|
LangEN Language = "en"
|
|
LangIT Language = "it"
|
|
LangRU Language = "ru"
|
|
)
|
|
|
|
const (
|
|
Provider Source = "provider"
|
|
Cache Source = "cache"
|
|
)
|
|
|
|
func ParseLanguage(s string) (Language, bool) {
|
|
l := Language(strings.ToLower(strings.TrimSpace(s)))
|
|
if _, ok := languageCodes[l]; ok {
|
|
return l, true
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
var languageCodes = map[Language]struct{}{
|
|
LangEN: {},
|
|
LangIT: {},
|
|
LangRU: {},
|
|
}
|
|
|
|
type Form struct {
|
|
Word string `json:"word"`
|
|
Tags []string `json:"tags,omitempty"`
|
|
}
|
|
|
|
type Quote struct {
|
|
Text string `json:"text"`
|
|
Reference string `json:"reference"`
|
|
}
|
|
|
|
type Sense struct {
|
|
Definition string `json:"definition"`
|
|
Tags []string `json:"tags,omitempty"`
|
|
Examples []string `json:"examples,omitempty"`
|
|
Quotes []Quote `json:"quotes,omitempty"`
|
|
Synonyms []string `json:"synonyms,omitempty"`
|
|
Antonyms []string `json:"antonyms,omitempty"`
|
|
}
|
|
|
|
type Entry struct {
|
|
Language Language `json:"language"`
|
|
PartOfSpeech PartOfSpeech `json:"partOfSpeech"`
|
|
IPA string `json:"ipa,omitempty"`
|
|
Forms []Form `json:"forms,omitempty"`
|
|
Senses []Sense `json:"senses"`
|
|
Synonyms []string `json:"synonyms,omitempty"`
|
|
Antonyms []string `json:"antonyms,omitempty"`
|
|
}
|
|
|
|
type TranslationResult struct {
|
|
SourceText string `json:"source_text"`
|
|
SourceLang Language `json:"source_lang"`
|
|
TargetLang Language `json:"target_lang"`
|
|
Translations []string `json:"translations"`
|
|
Provider string `json:"provider"`
|
|
Model string `json:"model,omitempty"`
|
|
Source Source `json:"source"`
|
|
GeneratedAt *time.Time `json:"generated_at,omitempty"`
|
|
}
|
|
|
|
type DictionaryResult struct {
|
|
Word string `json:"word"`
|
|
Entries []Entry `json:"entries"`
|
|
Provider string `json:"provider"`
|
|
Model string `json:"model,omitempty"`
|
|
Source Source `json:"source"`
|
|
GeneratedAt *time.Time `json:"generated_at,omitempty"`
|
|
}
|
|
|
|
type CollocationsResult struct {
|
|
Word string `json:"word"`
|
|
Lang Language `json:"lang"`
|
|
Provider string `json:"provider"`
|
|
Model string `json:"model,omitempty"`
|
|
Source Source `json:"source"`
|
|
Collocations []string `json:"collocations"`
|
|
GeneratedAt *time.Time `json:"generated_at,omitempty"`
|
|
}
|
|
|
|
type ExamplesResult struct {
|
|
Word string `json:"word"`
|
|
Lang Language `json:"lang"`
|
|
Provider string `json:"provider"`
|
|
Model string `json:"model,omitempty"`
|
|
Source Source `json:"source"`
|
|
Examples []string `json:"examples"`
|
|
GeneratedAt *time.Time `json:"generated_at,omitempty"`
|
|
}
|
|
|
|
type DeepLUsage struct {
|
|
CharacterCount int64 `json:"character_count"`
|
|
CharacterLimit int64 `json:"character_limit"`
|
|
}
|
|
|
|
type AIUsage struct {
|
|
Requests int64 `json:"requests"`
|
|
Tokens int64 `json:"tokens"`
|
|
TokenLimit int64 `json:"token_limit"`
|
|
}
|
|
|
|
type UsageResult struct {
|
|
DeepL *DeepLUsage `json:"deepl,omitempty"`
|
|
AI *AIUsage `json:"ai"`
|
|
}
|