Documentation ¶
Index ¶
- Constants
- Variables
- func GetLanguage(filename string, content []byte) (language string)
- func GetLanguageByAlias(alias string) (lang string, ok bool)
- func GetLanguageByClassifier(content []byte, candidates []string) (language string, safe bool)
- func GetLanguageByContent(content []byte) (language string, safe bool)
- func GetLanguageByEmacsModeline(content []byte) (language string, safe bool)
- func GetLanguageByExtension(filename string) (language string, safe bool)
- func GetLanguageByFilename(filename string) (language string, safe bool)
- func GetLanguageByModeline(content []byte) (language string, safe bool)
- func GetLanguageByShebang(content []byte) (language string, safe bool)
- func GetLanguageBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (language string, safe bool)
- func GetLanguageByVimModeline(content []byte) (language string, safe bool)
- func GetLanguageExtensions(language string) []string
- func GetLanguages(filename string, content []byte) []string
- func GetLanguagesByClassifier(filename string, content []byte, candidates []string) (languages []string)
- func GetLanguagesByContent(filename string, content []byte, candidates []string) []string
- func GetLanguagesByEmacsModeline(filename string, content []byte, candidates []string) []string
- func GetLanguagesByExtension(filename string, content []byte, candidates []string) []string
- func GetLanguagesByFilename(filename string, content []byte, candidates []string) []string
- func GetLanguagesByModeline(filename string, content []byte, candidates []string) []string
- func GetLanguagesByShebang(filename string, content []byte, candidates []string) (languages []string)
- func GetLanguagesBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (languages []string)
- func GetLanguagesByVimModeline(filename string, content []byte, candidates []string) []string
- func IsAuxiliaryLanguage(lang string) bool
- func IsBinary(data []byte) bool
- func IsConfiguration(path string) bool
- func IsDocumentation(path string) bool
- func IsDotFile(path string) bool
- func IsVendor(path string) bool
- type Classifier
- type Strategy
- type Type
Constants ¶
const OtherLanguage = ""
OtherLanguage is used as a zero value when a function can not return a specific language.
Variables ¶
var DefaultStrategies = []Strategy{ GetLanguagesByModeline, GetLanguagesByFilename, GetLanguagesByShebang, GetLanguagesByExtension, GetLanguagesByContent, GetLanguagesByClassifier, }
DefaultStrategies is the strategies' sequence GetLanguage uses to detect languages.
Functions ¶
func GetLanguage ¶
GetLanguage applies a sequence of strategies based on the given filename and content to find out the most probably language to return.
func GetLanguageByAlias ¶
GetLanguageByAlias returns either the language related to the given alias and ok set to true or Otherlanguage and ok set to false if the alias is not recognized.
func GetLanguageByClassifier ¶ added in v1.2.1
GetLanguageByClassifier returns the most probably language detected for the given content. It uses DefaultClassifier, if no candidates are provided it returns OtherLanguage.
func GetLanguageByContent ¶
GetLanguageByContent returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageByEmacsModeline ¶
GetLanguageByEmacsModeline returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageByExtension ¶
GetLanguageByExtension returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageByFilename ¶
GetLanguageByFilename returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageByModeline ¶
GetLanguageByModeline returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageByShebang ¶
GetLanguageByShebang returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageBySpecificClassifier ¶ added in v1.2.1
func GetLanguageBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (language string, safe bool)
GetLanguageBySpecificClassifier returns the most probably language for the given content using classifier to detect language.
func GetLanguageByVimModeline ¶
GetLanguageByVimModeline returns detected language. If there are more than one possibles languages it returns the first language by alphabetically order and safe to false.
func GetLanguageExtensions ¶
GetLanguageExtensions returns the different extensions being used by the language.
func GetLanguages ¶ added in v1.2.1
GetLanguages applies a sequence of strategies based on the given filename and content to find out the most probably languages to return.
func GetLanguagesByClassifier ¶ added in v1.2.1
func GetLanguagesByClassifier(filename string, content []byte, candidates []string) (languages []string)
GetLanguagesByClassifier uses DefaultClassifier as a Classifier and returns a sorted slice of possible languages ordered by decreasing language's probability. If there are not candidates it returns nil. It complies with the signature to be a Strategy type.
func GetLanguagesByContent ¶ added in v1.2.1
GetLanguagesByContent returns a slice of possible languages for the given content, filename and candidates will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesByEmacsModeline ¶ added in v1.2.1
GetLanguagesByEmacsModeline returns a slice of possible languages for the given content, filename and candidates will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesByExtension ¶ added in v1.2.1
GetLanguagesByExtension returns a slice of possible languages for the given filename, content and candidates will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesByFilename ¶ added in v1.2.1
GetLanguagesByFilename returns a slice of possible languages for the given filename, content and candidates will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesByModeline ¶ added in v1.2.1
GetLanguagesByModeline returns a slice of possible languages for the given content, filename will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesByShebang ¶ added in v1.2.1
func GetLanguagesByShebang(filename string, content []byte, candidates []string) (languages []string)
GetLanguagesByShebang returns a slice of possible languages for the given content, filename and candidates will be ignored. It complies with the signature to be a Strategy type.
func GetLanguagesBySpecificClassifier ¶ added in v1.2.1
func GetLanguagesBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (languages []string)
GetLanguagesBySpecificClassifier returns a slice of possible languages. It takes in a Classifier to be used.
func GetLanguagesByVimModeline ¶ added in v1.2.1
GetLanguagesByVimModeline returns a slice of possible languages for the given content, filename and candidates will be ignored. It complies with the signature to be a Strategy type.
func IsAuxiliaryLanguage ¶
IsAuxiliaryLanguage returns whether or not lang is an auxiliary language.
func IsBinary ¶
IsBinary detects if data is a binary value based on: http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198
func IsConfiguration ¶
IsConfiguration returns whether or not path is using a configuration language.
func IsDocumentation ¶
IsDocumentation returns whether or not path is a documentation path.
Types ¶
type Classifier ¶ added in v1.2.1
type Classifier interface {
Classify(content []byte, candidates map[string]float64) (languages []string)
}
Classifier is the interface in charge to detect the possible languages of the given content based on a set of candidates. Candidates is a map which can be used to assign weights to languages dynamically.
var DefaultClassifier Classifier = &classifier{ languagesLogProbabilities: data.LanguagesLogProbabilities, tokensLogProbabilities: data.TokensLogProbabilities, tokensTotal: data.TokensTotal, }
type Strategy ¶ added in v1.2.1
Strategy type fix the signature for the functions that can be used as a strategy.
type Type ¶
type Type int
Type represent language's type. Either data, programming, markup, prose, or unknown.
func GetLanguageType ¶
GetLanguageType returns the type of the given language.