add instrumentation to detection and classification

This commit is contained in:
Charlie Somerville
2015-02-25 12:34:07 +11:00
parent 04252c28f2
commit fd7633518f
3 changed files with 32 additions and 16 deletions

View File

@@ -6,3 +6,15 @@ require 'linguist/repository'
require 'linguist/samples'
require 'linguist/shebang'
require 'linguist/version'
class << Linguist
attr_accessor :instrumenter
def instrument(*args, &bk)
if instrumenter
instrumenter.instrument(*args, &bk)
else
yield
end
end
end

View File

@@ -16,11 +16,13 @@ module Linguist
#
# Returns an Array of Language objects, most probable first.
def self.call(blob, possible_languages)
Linguist.instrument("linguist.bayesian_classification") do
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
end
# Public: Train classifier that data is a certain language.
#

View File

@@ -105,6 +105,7 @@ module Linguist
# Bail early if the blob is binary or empty.
return nil if blob.likely_binary? || blob.binary? || blob.empty?
Linguist.instrument("linguist.detection") do
# Call each strategy until one candidate is returned.
STRATEGIES.reduce([]) do |languages, strategy|
candidates = strategy.call(blob, languages)
@@ -119,6 +120,7 @@ module Linguist
end
end.first
end
end
# Public: Get all Languages
#