Move call method into existing Classifier class

This commit is contained in:
Brandon Keepers
2014-11-27 11:29:38 -05:00
parent c1a9737313
commit bf4baff363
3 changed files with 20 additions and 15 deletions

View File

@@ -3,6 +3,25 @@ require 'linguist/tokenizer'
module Linguist
# Language bayesian classifier.
class Classifier
# Public: Use the classifier to detect language of the blob.
#
# blob - An object that quacks like a blob.
# possible_languages - Array of
#
# Examples
#
# Classifier.call(FileBlob.new("path/to/file"), [
# Language["Ruby"], Language["Python"]
# ])
#
# Returns an Array of possible lanuages, most probable first.
def self.call(blob, possible_languages)
language_names = possible_languages.map(&:name)
classify(Samples.cache, blob.data, language_names).map do |name, _|
Language[name] # Return the actual Language objects
end
end
# Public: Train classifier that data is a certain language.
#
# db - Hash classifier database object

View File

@@ -12,7 +12,6 @@ require 'linguist/file_blob'
require 'linguist/blob_helper'
require 'linguist/strategy/filename'
require 'linguist/strategy/shebang'
require 'linguist/strategy/classifier'
module Linguist
# Language names that are recognizable by GitHub. Defined languages
@@ -98,7 +97,7 @@ module Linguist
Linguist::Strategy::Filename,
Linguist::Strategy::Shebang,
Linguist::Heuristics,
Linguist::Strategy::Classifier
Linguist::Classifier
]
# Public: Detects the Language of the blob.

View File

@@ -1,13 +0,0 @@
module Linguist
module Strategy
# Detect language using the bayesian classifier
class Classifier
def self.call(blob, languages)
Linguist::Classifier.classify(Samples.cache, blob.data, languages.map(&:name)).map do |name, _|
# Return the actual Language object based of the string language name (i.e., first element of `#classify`)
Language[name]
end
end
end
end
end