Class: Langusta::DetectorFactory
- Inherits:
-
Object
- Object
- Langusta::DetectorFactory
- Includes:
- Inspector
- Defined in:
- lib/langusta/detector_factory.rb
Instance Attribute Summary collapse
-
#lang_list ⇒ Object
readonly
Returns the value of attribute lang_list.
-
#word_lang_prob_map ⇒ Object
readonly
Returns the value of attribute word_lang_prob_map.
Instance Method Summary collapse
-
#add_profile(profile) ⇒ Object
Adds a new language profile to this factory.
-
#create(alpha = nil) ⇒ Detector
Creates a new detector object, based on a preconfigured set of language profiles.
-
#initialize ⇒ DetectorFactory
constructor
A new instance of DetectorFactory.
- #inspect ⇒ Object
Methods included from Inspector
Constructor Details
#initialize ⇒ DetectorFactory
Returns a new instance of DetectorFactory.
7 8 9 10 |
# File 'lib/langusta/detector_factory.rb', line 7 def initialize @word_lang_prob_map = {} @lang_list = [] end |
Instance Attribute Details
#lang_list ⇒ Object (readonly)
Returns the value of attribute lang_list.
5 6 7 |
# File 'lib/langusta/detector_factory.rb', line 5 def lang_list @lang_list end |
#word_lang_prob_map ⇒ Object (readonly)
Returns the value of attribute word_lang_prob_map.
5 6 7 |
# File 'lib/langusta/detector_factory.rb', line 5 def word_lang_prob_map @word_lang_prob_map end |
Instance Method Details
#add_profile(profile) ⇒ Object
Adds a new language profile to this factory.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/langusta/detector_factory.rb', line 16 def add_profile(profile) raise DuplicateProfilesError.new(profile.name) if @lang_list.include?(profile.name) @lang_list << profile.name last_lang_index = @lang_list.size - 1 profile.freq.keys.each do |word| @word_lang_prob_map[word] ||= [] prob = 1.0 * profile.freq[word] / profile.n_words[word.length - 1] @word_lang_prob_map[word][last_lang_index] = prob end end |
#create(alpha = nil) ⇒ Detector
Creates a new detector object, based on a preconfigured set of language profiles.
30 31 32 33 34 35 36 37 38 |
# File 'lib/langusta/detector_factory.rb', line 30 def create(alpha=nil) if alpha detector = create_detector() detector.alpha = alpha detector else create_detector() end end |
#inspect ⇒ Object
40 41 42 |
# File 'lib/langusta/detector_factory.rb', line 40 def inspect "#<#{self.class.name}:0x#{object_ptr} (#{@lang_list.size} profile(s))" end |