mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Allow tokens to be passed directly to classify
This commit is contained in:
@@ -74,7 +74,7 @@ module Linguist
|
||||
|
||||
# Public: Guess language of data.
|
||||
#
|
||||
# data - String data to analyze.
|
||||
# data - Array of tokens or String data to analyze.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
@@ -83,8 +83,8 @@ module Linguist
|
||||
#
|
||||
# Returns sorted Array of result pairs. Each pair contains the
|
||||
# Language and a Float score.
|
||||
def classify(data)
|
||||
tokens = Tokenizer.new(data).tokens
|
||||
def classify(tokens)
|
||||
tokens = Tokenizer.new(tokens).tokens if tokens.is_a?(String)
|
||||
|
||||
scores = {}
|
||||
@languages.keys.each do |language|
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require 'linguist/classifier'
|
||||
require 'linguist/language'
|
||||
require 'linguist/sample'
|
||||
require 'linguist/tokenizer'
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
@@ -23,6 +24,10 @@ class TestClassifier < Test::Unit::TestCase
|
||||
|
||||
results = classifier.classify(fixture("objective-c/hello.m"))
|
||||
assert_equal Language["Objective-C"], results.first[0]
|
||||
|
||||
tokens = Tokenizer.new(fixture("objective-c/hello.m")).tokens
|
||||
results = classifier.classify(tokens)
|
||||
assert_equal Language["Objective-C"], results.first[0]
|
||||
end
|
||||
|
||||
def test_instance_classify_empty
|
||||
|
||||
Reference in New Issue
Block a user