Class: Serienrenamer::Plugin::Umlauts

Inherits:
Serienrenamer::Pluginbase show all
Defined in:
lib/serienrenamer/plugin/umlauts.rb

Class Method Summary collapse

Methods inherited from Serienrenamer::Pluginbase

inherited, inspect, to_s

Class Method Details

.contains_eventual_broken_umlauts?(string) ⇒ Boolean

checks for eventual broken umlauts

returns true if broken umlaut if included

Returns:

  • (Boolean)


63
64
65
# File 'lib/serienrenamer/plugin/umlauts.rb', line 63

def self.contains_eventual_broken_umlauts?(string)
  ! string.match(/ae|ue|oe|Ae|Ue|Oe/).nil?
end

.filter(episode_name) ⇒ Object

This method is called from outside with the full episodename as parameter and it should return the manipulated episodename



16
17
18
# File 'lib/serienrenamer/plugin/umlauts.rb', line 16

def self.filter(episode_name)
  episode_name.split.map {|e| repair_umlauts(e) }.join(" ")
end

.plugin_nameObject



9
# File 'lib/serienrenamer/plugin/umlauts.rb', line 9

def self.plugin_name; "Umlauts" end

.priorityObject



11
# File 'lib/serienrenamer/plugin/umlauts.rb', line 11

def self.priority; 150 end

.repair_umlauts(word) ⇒ Object

This method tries to repair some german umlauts so that the following occurs

ae => ä ; ue => ü ; oe => ö ; Ae => Ä ; Ue => Ü ; Oe => Ö

This method uses a webservice at:

http://wortschatz.uni-leipzig.de/

which produces statistics about the german language and e.g. frequency of words occuring in the german language

this method convert all broken umlauts in the word and compares the frequency of both version and uses the version which is more common

returns a repaired version of the word if necessary



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/serienrenamer/plugin/umlauts.rb', line 36

def self.repair_umlauts(word)

  if contains_eventual_broken_umlauts?(word)
    @@client ||= WLAPI::API.new

    repaired = word.gsub(/ae/, 'ä').gsub(/ue/, 'ü').gsub(/oe/, 'ö')
    repaired.gsub!(/^Ae/, 'Ä')
    repaired.gsub!(/^Ue/, 'Ü')
    repaired.gsub!(/^Oe/, 'Ö')

    res_broken  = @@client.frequencies(word)
    freq_broken = res_broken.nil? ? -1 : res_broken[0].to_i

    res_repaired  = @@client.frequencies(repaired)
    freq_repaired = res_repaired.nil? ? -1 : res_repaired[0].to_i

    if freq_repaired > freq_broken
      return repaired
    end
  end

  word
end

.typeObject



12
# File 'lib/serienrenamer/plugin/umlauts.rb', line 12

def self.type; :filter end

.usableObject



10
# File 'lib/serienrenamer/plugin/umlauts.rb', line 10

def self.usable; true end