Class: Opener::LanguageIdentifier::Detector

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/opener/language_identifier/detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Detector

Returns a new instance of Detector.



12
13
14
15
16
# File 'lib/opener/language_identifier/detector.rb', line 12

def initialize(options={})
  @options = options
  @detector = CybozuDetector.new(profiles_path)
  @semaphore = Mutex.new
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/opener/language_identifier/detector.rb', line 8

def options
  @options
end

Instance Method Details

#detect(input) ⇒ Object



18
19
20
21
22
# File 'lib/opener/language_identifier/detector.rb', line 18

def detect(input)
  @semaphore.synchronize do
    @detector.detect(input)
  end
end

#probabilities(input) ⇒ Object



24
25
26
27
28
# File 'lib/opener/language_identifier/detector.rb', line 24

def probabilities(input)
  @semaphore.synchronize do
    result = @detector.detect_langs(input)
  end
end

#profiles_pathObject



30
31
32
33
# File 'lib/opener/language_identifier/detector.rb', line 30

def profiles_path
  default_path = File.expand_path("../../../../core/target/classes/profiles", __FILE__)
  options.fetch(:profiles_path, default_path)
end