Class: SportDb::Lang

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/sportdb/lang.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLang

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

#langObject

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



48
49
50
# File 'lib/sportdb/lang.rb', line 48

def classify( text )
  @classifier.classify( text )
end

#classify_file(path) ⇒ Object



52
53
54
# File 'lib/sportdb/lang.rb', line 52

def classify_file( path )
  @classifier.classify_file( path )
end

#groupObject



73
74
75
# File 'lib/sportdb/lang.rb', line 73

def group
  @cache[ :group ] ||= group_getter
end

#knockout_roundObject



81
82
83
# File 'lib/sportdb/lang.rb', line 81

def knockout_round
  @cache[ :knockout_round ] ||= knockout_round_getter
end

#leg1Object



85
86
87
# File 'lib/sportdb/lang.rb', line 85

def leg1
  @cache[ :leg1 ] ||= leg1_getter
end

#leg2Object



89
90
91
# File 'lib/sportdb/lang.rb', line 89

def leg2
  @cache[ :leg2 ] ||= leg2_getter
end

#load_builtin_wordsObject



17
18
19
20
21
22
23
24
25
# File 'lib/sportdb/lang.rb', line 17

def load_builtin_words
  builtin_words = {
    'en' => 'fixtures/en',
    'de' => 'fixtures/de',
    'es' => 'fixtures/es'
  }

  load_words( builtin_words, SportDb.config_path )
end

#load_words(h, include_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sportdb/lang.rb', line 27

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_groupObject



95
96
97
# File 'lib/sportdb/lang.rb', line 95

def regex_group
  @cache [ :regex_group ] ||= regex_group_getter
end

#regex_knockout_roundObject



103
104
105
# File 'lib/sportdb/lang.rb', line 103

def regex_knockout_round
  @cache[ :regex_knockout_round ] ||= regex_knockout_round_getter
end

#regex_leg1Object



107
108
109
# File 'lib/sportdb/lang.rb', line 107

def regex_leg1
  @cache[ :regex_leg1 ] ||= regex_leg1_getter
end

#regex_leg2Object



111
112
113
# File 'lib/sportdb/lang.rb', line 111

def regex_leg2
  @cache[ :regex_leg2 ] ||= regex_leg2_getter
end

#regex_roundObject



99
100
101
# File 'lib/sportdb/lang.rb', line 99

def regex_round
  @cache[ :regex_round ] ||= regex_round_getter
end

#roundObject



77
78
79
# File 'lib/sportdb/lang.rb', line 77

def round
  @cache[ :round ] ||= round_getter
end