Documentation ¶
Index ¶
- Variables
- func CreateOccurenceMap(text string, gramDepth int) map[string]int
- func CreateRankLookupMap(input map[string]int) map[string]int
- func GetDistance(mapA, mapB map[string]int, maxDist int) int
- func InitWithDefault(filePath string)
- func InitWithDefaultFromReader(reader io.Reader)
- type ByOccurrence
- type DetectionResult
- type Detector
- type Language
- type ResByConf
- type Token
Constants ¶
This section is empty.
Variables ¶
var DefaultDetector = Detector{&defaultLanguages, DefaultMinimumConfidence}
var DefaultMinimumConfidence float32 = 0.7
DefaultMinimumConfidence is the minimum confidence that a language-match must have to be returned as detected language
Functions ¶
func CreateOccurenceMap ¶
CreateOccurenceMap creates a map[token]occurrence from a given text and up to a given gram depth gramDepth=1 means only 1-letter tokens are created, gramDepth=2 means 1- and 2-letters token are created, etc.
func CreateRankLookupMap ¶
creates the map [token] rank from a map [token] occurrence
func GetDistance ¶
getDistance calculates the out-of-place distance between two Profiles, taking into account only items of mapA, that have a value bigger then 300
func InitWithDefault ¶
func InitWithDefault(filePath string)
InitWithDefault initializes the default languages with a provided file containing Marshalled array of Languages
func InitWithDefaultFromReader ¶
InitWithDefault initializes the default languages with a provided Reader containing Marshalled array of Languages
Types ¶
type ByOccurrence ¶
type ByOccurrence []Token
ByOccurrence represents an array of tokens which can be sorted by occurrences of the tokens.
func (ByOccurrence) Len ¶
func (a ByOccurrence) Len() int
func (ByOccurrence) Less ¶
func (a ByOccurrence) Less(i, j int) bool
func (ByOccurrence) Swap ¶
func (a ByOccurrence) Swap(i, j int)
type DetectionResult ¶
DetectionResult represents the result from comparing 2 Profiles. It includes the confidence which is basically the the relative distance between the two profiles.
type Detector ¶
Detector has an array of detectable Languages and methods to determine the closest Language to a text.
func NewDefaultLanguages ¶
func NewDefaultLanguages() Detector
NewDetectorDefault returns a new Detector with the default languages, if loaded: currently: Arabic, English, French, German, Hebrew, Russian, Turkish
func NewDetector ¶
func NewDetector() Detector
NewDetector returns a new Detector without any language. It can be used to add languages selectively.
func NewWithLanguagesFromReader ¶
NewWithLanguagesFromReader returns a new Detector with existing language parsed from a reader
func (*Detector) AddLanguage ¶
Add language adds a language to the list of detectable languages by this Detector instance.
func (*Detector) AddLanguageFromText ¶
Add language analyzes a text and creates a new Language with given name. The new language will be detectable afterwards by this Detector instance.
func (*Detector) GetClosestLanguage ¶
GetClosestLanguage returns the name of the language which is closest to the given text if it is confident enough. It returns undefined otherwise. Set detector's MinimumConfidence for customization.
func (*Detector) GetLanguages ¶
func (d *Detector) GetLanguages(text string) []DetectionResult
GetLanguages analyzes a text and returns the DetectionResult of all languages of this detector.
type Language ¶
Language represents a language by its name and the profile ( map[token]OccurrenceRank )
type ResByConf ¶
type ResByConf []DetectionResult
ResByConf represents an array of DetectionResult and can be sorted by Confidence.