Class: JLDrill::JEDictionary
- Inherits:
-
Dictionary
- Object
- DataFile
- Dictionary
- JLDrill::JEDictionary
- Defined in:
- lib/jldrill/model/items/JEDictionary.rb
Overview
A JEDictionary is a Japanese to English Dictionary. It is composed of an array of entries from an EDict dictionary. These entries are parsed to create DictionaryEntry. The DictionaryEntry can then further parse the entries to create Meanings.
Constant Summary collapse
- LINE_RE_TEXT =
'^([^\[\s]*)\s+(\[(.*)\]\s+)?\/(([^\/]*\/)+)\s*$'
- LINE_RE =
Regexp.new(LINE_RE_TEXT, nil)
- GET_DE_RE =
Regexp.new('^([^\[\s]*)\s+(\[(.*)\]\s+)?', nil)
- KANA_RE =
/((.*))/
- FIRST_CHAR_RE =
Regexp.new("^(.)", nil)
Instance Attribute Summary
Attributes inherited from Dictionary
Attributes inherited from DataFile
#encoding, #file, #lines, #parsed, #publisher, #stepSize
Instance Method Summary collapse
- #getDictionaryEntry(index) ⇒ Object
- #getMeaning(position) ⇒ Object
-
#getVocab(position) ⇒ Object
Parse the line at the given position and return the a Vocabulary containing the information (this is deprecated).
-
#hackWord(word) ⇒ Object
Compensate for files that have missing kanji or JLPT files which have a strange format.
-
#hashSize ⇒ Object
Ruby 1.8 counts in bytes so Japanese characters are 3 characters long.
Methods inherited from Dictionary
#dataSize, #eachVocab, #findBinWithKanji, #findBinWithReading, #findBinWithSimplified, #findKanji, #findKanjiStartingWith, #findKanjiThatStart, #findReading, #findReadingsStartingWith, #findReadingsThatStart, #findWord, #findWordsThatStart, #finishParsing, #hashWord, #include?, #initialize, #length, #parseEntry, #parseLine, #readLines, #reset, #vocab
Methods inherited from DataFile
#createLines, #dataSize, #eof?, #findEncoding, #finishParsing, #fraction, #initialize, #load, #loaded?, #parse, #parseChunk, #parseEntry, #parser, #readLines, #reset, #setLoaded, #shortFilename
Constructor Details
This class inherits a constructor from JLDrill::Dictionary
Instance Method Details
#getDictionaryEntry(index) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jldrill/model/items/JEDictionary.rb', line 85 def getDictionaryEntry(index) retVal = nil if lines[index] =~ GET_DE_RE retVal = DictionaryEntry.new retVal.kanji = $1 retVal.reading = $3 retVal.dictionary = self retVal.position = index retVal = hackWord(retVal) end return retVal end |
#getMeaning(position) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/jldrill/model/items/JEDictionary.rb', line 33 def getMeaning(position) retVal = "" if lines[position] =~ LINE_RE retVal = $4 end return retVal end |
#getVocab(position) ⇒ Object
Parse the line at the given position and return the a Vocabulary containing the information (this is deprecated).
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jldrill/model/items/JEDictionary.rb', line 43 def getVocab(position) retVal = nil if lines[position] =~ LINE_RE kanji = $1 reading = $3 english = JLDrill::Meaning.create($4) # Hack for JLPT files if reading =~ KANA_RE reading = nil hint = $1 end if(reading == "" || reading == nil) reading = kanji kanji = nil end retVal = Vocabulary.new(kanji, reading, english.allDefinitions, english.allTypes, hint, position) else Context::Log::warning("JLDrill::JEDictionary", "Could not parse #{position}") end return retVal end |
#hackWord(word) ⇒ Object
Compensate for files that have missing kanji or JLPT files which have a strange format.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jldrill/model/items/JEDictionary.rb', line 72 def hackWord(word) # Hack for JLPT files if word.reading =~ KANA_RE || word.reading.nil? || word.reading.empty? word.reading = word.kanji word.kanji = "" end if word.kanji.nil? word.kanji = "" end return word end |
#hashSize ⇒ Object
Ruby 1.8 counts in bytes so Japanese characters are 3 characters long. Ruby 1.9 counts in characters, so Japanese characters are 1 character each. When we are hashing we need to use a Japanese character for a key. When creating the slices to search for the hash key we need to know how many characters to strip off. This function tells you what that is.
29 30 31 |
# File 'lib/jldrill/model/items/JEDictionary.rb', line 29 def hashSize return "あ".size end |