Class: SportDb::Lang
- Inherits:
-
Object
- Object
- SportDb::Lang
- Includes:
- LogUtils::Logging
- Defined in:
- lib/sportdb/lang.rb
Instance Attribute Summary collapse
-
#lang ⇒ Object
Returns the value of attribute lang.
Instance Method Summary collapse
- #classify(text) ⇒ Object
- #classify_file(path) ⇒ Object
- #group ⇒ Object
-
#initialize ⇒ Lang
constructor
A new instance of Lang.
- #knockout_round ⇒ Object
- #leg1 ⇒ Object
- #leg2 ⇒ Object
- #load_builtin_words ⇒ Object
- #load_words(h, include_path) ⇒ Object
- #regex_group ⇒ Object
- #regex_knockout_round ⇒ Object
- #regex_leg1 ⇒ Object
- #regex_leg2 ⇒ Object
- #regex_round ⇒ Object
- #round ⇒ Object
Constructor Details
#initialize ⇒ Lang
Returns a new instance of Lang.
11 12 13 14 |
# File 'lib/sportdb/lang.rb', line 11 def initialize # fix/todo: load on demand; only if no fixtures loaded/configured use builtin load_builtin_words end |
Instance Attribute Details
#lang ⇒ Object
Returns the value of attribute lang.
9 10 11 |
# File 'lib/sportdb/lang.rb', line 9 def lang @lang end |
Instance Method Details
#classify(text) ⇒ Object
53 54 55 |
# File 'lib/sportdb/lang.rb', line 53 def classify( text ) @classifier.classify( text ) end |
#classify_file(path) ⇒ Object
57 58 59 |
# File 'lib/sportdb/lang.rb', line 57 def classify_file( path ) @classifier.classify_file( path ) end |
#group ⇒ Object
78 79 80 |
# File 'lib/sportdb/lang.rb', line 78 def group @cache[ :group ] ||= group_getter end |
#knockout_round ⇒ Object
86 87 88 |
# File 'lib/sportdb/lang.rb', line 86 def knockout_round @cache[ :knockout_round ] ||= knockout_round_getter end |
#leg1 ⇒ Object
90 91 92 |
# File 'lib/sportdb/lang.rb', line 90 def leg1 @cache[ :leg1 ] ||= leg1_getter end |
#leg2 ⇒ Object
94 95 96 |
# File 'lib/sportdb/lang.rb', line 94 def leg2 @cache[ :leg2 ] ||= leg2_getter end |
#load_builtin_words ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sportdb/lang.rb', line 17 def load_builtin_words builtin_words = { 'en' => 'fixtures/en', 'de' => 'fixtures/de', 'es' => 'fixtures/es', 'fr' => 'fixtures/fr', 'it' => 'fixtures/it', 'pt' => 'fixtures/pt', 'ro' => 'fixtures/ro' } load_words( builtin_words, SportDb.config_path ) end |
#load_words(h, include_path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sportdb/lang.rb', line 32 def load_words( h, include_path ) @lang = 'en' # make default lang english/en @words = {} # resets fixtures @cache = {} # reset cached values h.each_with_index do |(key,value),i| name = value path = "#{include_path}/#{name}.yml" logger.debug( "loading words #{key} (#{i+1}/#{h.size}) in '#{name}' (#{path})..." ) @words[ key ] = YAML.load( File.read_utf8( path )) end @classifier = TextUtils::Classifier.new @words.each_with_index do |(key,value),i| logger.debug "train classifier for #{key} (#{i+1}/#{@words.size})" @classifier.train( key, value ) end @classifier.dump # for debugging dump all words end |
#regex_group ⇒ Object
100 101 102 |
# File 'lib/sportdb/lang.rb', line 100 def regex_group @cache [ :regex_group ] ||= regex_group_getter end |
#regex_knockout_round ⇒ Object
108 109 110 |
# File 'lib/sportdb/lang.rb', line 108 def regex_knockout_round @cache[ :regex_knockout_round ] ||= regex_knockout_round_getter end |
#regex_leg1 ⇒ Object
112 113 114 |
# File 'lib/sportdb/lang.rb', line 112 def regex_leg1 @cache[ :regex_leg1 ] ||= regex_leg1_getter end |
#regex_leg2 ⇒ Object
116 117 118 |
# File 'lib/sportdb/lang.rb', line 116 def regex_leg2 @cache[ :regex_leg2 ] ||= regex_leg2_getter end |
#regex_round ⇒ Object
104 105 106 |
# File 'lib/sportdb/lang.rb', line 104 def regex_round @cache[ :regex_round ] ||= regex_round_getter end |
#round ⇒ Object
82 83 84 |
# File 'lib/sportdb/lang.rb', line 82 def round @cache[ :round ] ||= round_getter end |