lib/linguist/classifier.rb
# Internal: Guess language of data
#
# data      - Array of tokens or String data to analyze.
# languages - Array of language name Strings to restrict to.
#
# Returns sorted Array of result pairs. Each pair contains the
# String language name and a Float score.
Guess language of data
data      - Array of tokens or String data to analyze.
languages - Array of language name Strings to restrict to.

Returns sorted Array of result pairs. Each pair contains the
String language name and a Float score.
Guess language of data data - Array of tokens or String data to analyze . languages - Array of language name Strings to restrict to . Returns sorted Array of result pairs . Each pair contains the String language name and a Float score .
def classify(tokens, languages)
      return [] if tokens.nil?
      tokens = Tokenizer.tokenize(tokens) if tokens.is_a?(String)
      scores = {}
      debug_dump_all_tokens(tokens, languages) if verbosity >= 2
      languages.each do |language|
        scores[language] = tokens_probability(tokens, language) + language_probability(language)
        debug_dump_probabilities(tokens, language, scores[language]) if verbosity >= 1
      end
      scores.sort { |a, b| b[1] <=> a[1] }.map { |score| [score[0], score[1]] }
    end
def classify ( tokens , languages ) return [ ] if tokens . nil? tokens = Tokenizer . tokenize ( tokens ) if tokens . is_a? ( String ) scores = { } debug_dump_all_tokens ( tokens , languages ) if verbosity >= 2 languages . each do | language | scores [ language ] = tokens_probability ( tokens , language ) + language_probability ( language ) debug_dump_probabilities ( tokens , language , scores [ language ] ) if verbosity >= 1 end scores . sort { | a , b | b [ 1 ] <=> a [ 1 ] } . map { | score | [ score [ 0 ] , score [ 1 ] ] } end
Internal: Guess language of data
data      - Array of tokens or String data to analyze.
Internal : Guess language of data data - Array of tokens or String data to analyze .
tokens
<not_specific>
languages
<not_specific>