Documentation ¶
Index ¶
- Constants
- Variables
- func Contains[T comparable](s []T, e T) bool
- func CountSyllables(word string) int
- func GetType(i interface{}) string
- func GetVowels(word string) []rune
- func HasFrontness(vowel, candidate string) bool
- func HasRoundness(vowel, candidate string) bool
- func HasVowelHarmony(word string) bool
- func IsTurkishWord(word string) bool
- func LoadWords(path string) []string
- func LoadWordsFromSliceBytes(data []byte) []string
- func ReplaceStringAtIndex(text string, r rune, i int) string
- func ValidateOptionalLetter(word string, candidate *rune) bool
- func VowelHarmony(vowel, candidate string) bool
- type BaseState
- type DerivationalState
- type NominalVerbState
- type NounState
- type State
- type Stemmer
- type Stems
- type Suffix
- type Transition
- type Transitions
Constants ¶
View Source
const ( AverageStemmerCount = 4 MinSyllableCount = 2 // Alphabet Turkish alphabet. They are used for skipping not turkish words. Alphabet = "abcçdefgğhıijklmnoöprsştuüvyz" // Vowels Turkish vowels. Vowels = "üiıueöao" // Consonants Turkish consonants. Consonants = "bcçdfgğhjklmnprsştvyz" // RoundedVowels Rounded vowels which are used for checking roundness harmony. RoundedVowels = "oöuü" // FollowingRoundedVowels Vowels that follow rounded vowels. // They are combined with ROUNDED_VOWELS to check roundness harmony. FollowingRoundedVowels = "aeuü" // UnroundedVowels The unrounded vowels which are used for checking roundness harmony. UnroundedVowels = "iıea" // FrontVowels Front vowels which are used for checking frontness harmony. FrontVowels = "eiöü" // BackVowels Front vowels which are used for checking frontness harmony. BackVowels = "ıuao" )
Variables ¶
View Source
var ( //go:embed data/protected_words.txt // DefaultProtectedWordsFile The path of the file that contains the default set of protected words. DefaultProtectedWordsFile []byte //go:embed data/vowel_harmony_exceptions.txt // DefaultVowelHarmonyExceptionsFile The path of the file that contains the default set of vowel harmony exceptions. DefaultVowelHarmonyExceptionsFile []byte //go:embed data/last_consonant_exceptions.txt // DefaultLastConsonantExceptionsFile The path of the file that contains the default set of last consonant exceptions. DefaultLastConsonantExceptionsFile []byte //go:embed data/average_stem_size_exceptions.txt // DefaultAverageStemSizeExceptionsFile The path of the file that contains // the default set of average stem size exceptions. DefaultAverageStemSizeExceptionsFile []byte // LastConsonantRules Last consonant rules LastConsonantRules = map[string]string{"b": "p", "c": "ç", "d": "t", "ğ": "k"} )
View Source
var ( DerivationalStateA = NewDerivationalState(true, false, DerivationalSuffixValues) DerivationalStateB = NewDerivationalState(false, true, nil) )
View Source
var ( NominalVerbStateA = NewNominalVerbState(true, false, NominalVerbSuffixValues) NominalVerbStateB = NewNominalVerbState(false, true, []Suffix{NominalVerbSuffix14}) NominalVerbStateC = NewNominalVerbState(false, true, []Suffix{NominalVerbSuffix10, NominalVerbSuffix12, NominalVerbSuffix13, NominalVerbSuffix14}) //nolint:lll NominalVerbStateD = NewNominalVerbState(false, false, []Suffix{NominalVerbSuffix12, NominalVerbSuffix13}) NominalVerbStateE = NewNominalVerbState(false, true, []Suffix{NominalVerbSuffix1, NominalVerbSuffix2, NominalVerbSuffix3, NominalVerbSuffix4, NominalVerbSuffix5, NominalVerbSuffix14}) //nolint:lll NominalVerbStateF = NewNominalVerbState(false, true, nil) NominalVerbStateG = NewNominalVerbState(false, false, []Suffix{NominalVerbSuffix14}) NominalVerbStateH = NewNominalVerbState(false, false, []Suffix{NominalVerbSuffix1, NominalVerbSuffix2, NominalVerbSuffix3, NominalVerbSuffix4, NominalVerbSuffix5, NominalVerbSuffix14}) //nolint:lll NominalVerbTFValues = map[string]NominalVerbState{ NominalVerbSuffix1.Name: NominalVerbStateB, NominalVerbSuffix2.Name: NominalVerbStateB, NominalVerbSuffix3.Name: NominalVerbStateB, NominalVerbSuffix4.Name: NominalVerbStateB, NominalVerbSuffix5.Name: NominalVerbStateC, NominalVerbSuffix6.Name: NominalVerbStateD, NominalVerbSuffix7.Name: NominalVerbStateD, NominalVerbSuffix8.Name: NominalVerbStateD, NominalVerbSuffix9.Name: NominalVerbStateD, NominalVerbSuffix10.Name: NominalVerbStateE, NominalVerbSuffix11.Name: NominalVerbStateH, NominalVerbSuffix12.Name: NominalVerbStateF, NominalVerbSuffix13.Name: NominalVerbStateF, NominalVerbSuffix14.Name: NominalVerbStateF, NominalVerbSuffix15.Name: NominalVerbStateF, } NominalVerbFTValues = map[string]NominalVerbState{ NominalVerbSuffix1.Name: NominalVerbStateG, NominalVerbSuffix2.Name: NominalVerbStateG, NominalVerbSuffix3.Name: NominalVerbStateG, NominalVerbSuffix4.Name: NominalVerbStateG, NominalVerbSuffix5.Name: NominalVerbStateG, NominalVerbSuffix10.Name: NominalVerbStateF, NominalVerbSuffix13.Name: NominalVerbStateF, NominalVerbSuffix14.Name: NominalVerbStateF, } NominalVerbFFValues = map[string]NominalVerbState{ NominalVerbSuffix1.Name: NominalVerbStateG, NominalVerbSuffix2.Name: NominalVerbStateG, NominalVerbSuffix3.Name: NominalVerbStateG, NominalVerbSuffix4.Name: NominalVerbStateG, NominalVerbSuffix5.Name: NominalVerbStateG, NominalVerbSuffix12.Name: NominalVerbStateF, NominalVerbSuffix14.Name: NominalVerbStateF, } )
View Source
var ( NounStateA = NewNounState(true, true, NounSuffixValues) NounStateB = NewNounState(false, true, []Suffix{NounSuffix1, NounSuffix2, NounSuffix3, NounSuffix4, NounSuffix5}) NounStateC = NewNounState(false, false, []Suffix{NounSuffix6, NounSuffix7}) NounStateD = NewNounState(false, false, []Suffix{NounSuffix10, NounSuffix13, NounSuffix14}) NounStateE = NewNounState(false, true, []Suffix{NounSuffix1, NounSuffix2, NounSuffix3, NounSuffix4, NounSuffix5, NounSuffix6, NounSuffix7, NounSuffix18}) //nolint:lll NounStateF = NewNounState(false, false, []Suffix{NounSuffix6, NounSuffix7, NounSuffix18}) NounStateG = NewNounState(false, true, []Suffix{NounSuffix1, NounSuffix2, NounSuffix3, NounSuffix4, NounSuffix5, NounSuffix18}) //nolint:lll NounStateH = NewNounState(false, true, []Suffix{NounSuffix1}) NounStateK = NewNounState(false, true, nil) NounStateL = NewNounState(false, true, []Suffix{NounSuffix18}) NounStateM = NewNounState(false, true, []Suffix{NounSuffix1, NounSuffix2, NounSuffix3, NounSuffix4, NounSuffix5, NounSuffix6, NounSuffix6, NounSuffix7}) //nolint:lll // TTValues InitialState = true, FinalState = true TTValues = map[string]NounState{ NounSuffix1.Name: NounStateL, NounSuffix2.Name: NounStateH, NounSuffix3.Name: NounStateH, NounSuffix4.Name: NounStateH, NounSuffix5.Name: NounStateH, NounSuffix6.Name: NounStateH, NounSuffix7.Name: NounStateK, NounSuffix8.Name: NounStateB, NounSuffix9.Name: NounStateC, NounSuffix10.Name: NounStateE, NounSuffix11.Name: NounStateB, NounSuffix12.Name: NounStateF, NounSuffix13.Name: NounStateB, NounSuffix14.Name: NounStateF, NounSuffix15.Name: NounStateG, NounSuffix16.Name: NounStateC, NounSuffix17.Name: NounStateE, NounSuffix18.Name: NounStateD, } // InitialState = false, FinalState = true FTValues = map[string]NounState{ NounSuffix1.Name: NounStateL, NounSuffix2.Name: NounStateH, NounSuffix3.Name: NounStateH, NounSuffix4.Name: NounStateH, NounSuffix5.Name: NounStateH, NounSuffix6.Name: NounStateH, NounSuffix7.Name: NounStateK, NounSuffix18.Name: NounStateD, } // InitialState = false, FinalState = false FFValues = map[string]NounState{ NounSuffix6.Name: NounStateH, NounSuffix7.Name: NounStateL, NounSuffix10.Name: NounStateE, NounSuffix13.Name: NounStateB, NounSuffix14.Name: NounStateF, NounSuffix18.Name: NounStateD, } )
View Source
var ( DerivationalSuffix1 = NewSuffix("-lU", "lı|li|lu|lü", "", true) NominalVerbSuffix1 = NewSuffix("-(y)Um", "ım|im|um|üm", "y", true) NominalVerbSuffix2 = NewSuffix("-sUn", "sın|sin|sun|sün", "", true) NominalVerbSuffix3 = NewSuffix("-(y)Uz", "ız|iz|uz|üz", "y", true) NominalVerbSuffix4 = NewSuffix("-sUnUz", "sınız|siniz|sunuz|sünüz", "", true) NominalVerbSuffix5 = NewSuffix("-lAr", "lar|ler", "", true) NominalVerbSuffix6 = NewSuffix("-m", "m", "", true) NominalVerbSuffix7 = NewSuffix("-n", "n", "", true) NominalVerbSuffix8 = NewSuffix("-k", "k", "", true) NominalVerbSuffix9 = NewSuffix("-nUz", "nız|niz|nuz|nüz", "", true) NominalVerbSuffix10 = NewSuffix("-DUr", "tır|tir|tur|tür|dır|dir|dur|dür", "", true) NominalVerbSuffix11 = NewSuffix("-cAsInA", "casına|çasına|cesine|çesine", "", true) NominalVerbSuffix12 = NewSuffix("-(y)DU", "dı|di|du|dü|tı|ti|tu|tü", "y", true) NominalVerbSuffix13 = NewSuffix("-(y)sA", "sa|se", "y", true) NominalVerbSuffix14 = NewSuffix("-(y)mUş", "muş|miş|müş|mış", "y", true) NominalVerbSuffix15 = NewSuffix("-(y)ken", "ken", "y", true) NounSuffix1 = NewSuffix("-lAr", "lar|ler", "", true) NounSuffix2 = NewSuffix("-(U)m", "m", "ı|i|u|ü", true) NounSuffix3 = NewSuffix("-(U)mUz", "mız|miz|muz|müz", "ı|i|u|ü", true) NounSuffix4 = NewSuffix("-Un", "ın|in|un|ün", "", true) NounSuffix5 = NewSuffix("-(U)nUz", "nız|niz|nuz|nüz", "ı|i|u|ü", true) NounSuffix6 = NewSuffix("-(s)U", "ı|i|u|ü", "s", true) NounSuffix7 = NewSuffix("-lArI", "ları|leri", "", true) NounSuffix8 = NewSuffix("-(y)U", "ı|i|u|ü", "y", true) NounSuffix9 = NewSuffix("-nU", "nı|ni|nu|nü", "", true) NounSuffix10 = NewSuffix("-(n)Un", "ın|in|un|ün", "n", true) NounSuffix11 = NewSuffix("-(y)A", "a|e", "y", true) NounSuffix12 = NewSuffix("-nA", "na|ne", "", true) NounSuffix13 = NewSuffix("-DA", "da|de|ta|te", "", true) NounSuffix14 = NewSuffix("-nDA", "nta|nte|nda|nde", "", true) NounSuffix15 = NewSuffix("-DAn", "dan|tan|den|ten", "", true) NounSuffix16 = NewSuffix("-nDAn", "ndan|ntan|nden|nten", "", true) NounSuffix17 = NewSuffix("-(y)lA", "la|le", "y", true) NounSuffix18 = NewSuffix("-ki", "ki", "", false) NounSuffix19 = NewSuffix("-(n)cA", "ca|ce", "n", true) // The order of this slice definition determines the priority of the suffix. DerivationalSuffixValues = []Suffix{DerivationalSuffix1} NominalVerbSuffixValues = []Suffix{NominalVerbSuffix11, NominalVerbSuffix4, NominalVerbSuffix14, NominalVerbSuffix15, NominalVerbSuffix2, NominalVerbSuffix5, NominalVerbSuffix9, NominalVerbSuffix10, NominalVerbSuffix3, NominalVerbSuffix1, NominalVerbSuffix12, NominalVerbSuffix13, NominalVerbSuffix6, NominalVerbSuffix7, NominalVerbSuffix8} //nolint:lll NounSuffixValues = []Suffix{NounSuffix16, NounSuffix7, NounSuffix3, NounSuffix5, NounSuffix1, NounSuffix14, NounSuffix15, NounSuffix17, NounSuffix10, NounSuffix19, NounSuffix4, NounSuffix9, NounSuffix12, NounSuffix13, NounSuffix18, NounSuffix2, NounSuffix6, NounSuffix8, NounSuffix11} //nolint:lll )
Functions ¶
func Contains ¶
func Contains[T comparable](s []T, e T) bool
Contains Returns whether e is within s.
func CountSyllables ¶
CountSyllables Returns the number/count of syllables of a word.
func HasFrontness ¶
HasFrontness Checks the frontness harmony of two characters.
func HasRoundness ¶
HasRoundness Checks the roundness harmony of two characters.
func HasVowelHarmony ¶
HasVowelHarmony Checks the vowel harmony of a word.
func IsTurkishWord ¶
IsTurkishWord Checks whether a word is written in Turkish alphabet or not.
func LoadWordsFromSliceBytes ¶
LoadWordsFromSliceBytes Reads data from slide of bytes and split as newline ('\n')
func ReplaceStringAtIndex ¶
ReplaceStringAtIndex Find exact index number in text then replaces with r and returns new text.
func ValidateOptionalLetter ¶
ValidateOptionalLetter Checks whether an optional letter is valid or not.
func VowelHarmony ¶
VowelHarmony Checks the vowel harmony of two characters.
Types ¶
type BaseState ¶
type BaseState struct {
// contains filtered or unexported fields
}
func (BaseState) AddTransitions ¶
func (s BaseState) AddTransitions(word string, transitions *Transitions, startState State)
func (BaseState) FinalState ¶
func (BaseState) InitialState ¶
type DerivationalState ¶
type DerivationalState struct {
BaseState
}
func NewDerivationalState ¶
func NewDerivationalState(initialState, finalState bool, suffixes []Suffix) DerivationalState
func (DerivationalState) NextState ¶
func (s DerivationalState) NextState(suffix string) State
type NominalVerbState ¶
type NominalVerbState struct {
BaseState
}
func NewNominalVerbState ¶
func NewNominalVerbState(initialState, finalState bool, suffixes []Suffix) NominalVerbState
func (NominalVerbState) GetValues ¶
func (s NominalVerbState) GetValues() map[string]NominalVerbState
func (NominalVerbState) NextState ¶
func (s NominalVerbState) NextState(suffix string) State
type State ¶
type State interface { AddTransitions(word string, transitions *Transitions, startState State) NextState(suffix string) State InitialState() bool FinalState() bool Suffixes() []Suffix }
func GetInitialNominalVerbState ¶
func GetInitialNominalVerbState() State
type Stemmer ¶
type Suffix ¶
type Suffix struct { Name string Pattern *regexp.Regexp OptionalLetterPattern *regexp.Regexp OptionalLetterCheck bool CheckHarmony bool OptionalLetter string }
func (Suffix) GetOptionalLetter ¶
func (Suffix) RemoveSuffix ¶
type Transition ¶
func NewTransition ¶
func NewTransition(startState, nextState State, word string, suffix Suffix) *Transition
func (Transition) SimilarTransitions ¶
func (t Transition) SimilarTransitions(transitions Transitions) *Transitions
func (Transition) String ¶
func (t Transition) String() string
type Transitions ¶
type Transitions []*Transition
Click to show internal directories.
Click to hide internal directories.