Module: WenlinDbScanner::SpeechParts

Defined in:
lib/wenlin_db_scanner/speech_parts.rb

Overview

Parses the databases that describe the parts of speech.

Class Method Summary collapse

Class Method Details

.en(db_root) ⇒ Enumerator<SpeechPart>

The English parts of speech used in the en->zh dictionary.

Parameters:

  • db_root (String)

    the directory containing the .db files

Returns:



11
12
13
# File 'lib/wenlin_db_scanner/speech_parts.rb', line 11

def self.en(db_root)
  parts File.join(db_root, 'ab_ec.db')
end

.parts(db_file) ⇒ Enumerator<SpeechPart>

Generic decoder for a database of parts of speech.

Parameters:

  • db_file (String)

    path to the .db file containing part-of-speech data

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wenlin_db_scanner/speech_parts.rb', line 27

def self.parts(db_file)
  Enumerator.new do |yielder|
    db = Db.new db_file
    db.records.each do |record|
      next if record.binary?
      lines = record.text.split("\n").map(&:strip).reject(&:empty?)

      part = SpeechPart.new
      part.abbrev, part.en, part.pinyin, part.zh =
          *lines[0].split('=').map(&:strip)
      part.description = lines[1]
      yielder << part
    end
    db.close
  end
end

.zh(db_root) ⇒ Enumerator<SpeechPart>

The Chinese parts of speech used in the zh->en dictionary.

Parameters:

  • db_root (String)

    the directory containing the .db files

Returns:



19
20
21
# File 'lib/wenlin_db_scanner/speech_parts.rb', line 19

def self.zh(db_root)
  parts File.join(db_root, 'ab_ce.db')
end