Module: JLDrill::Behaviour::SearchDictionary
- Included in:
- DisplayProblemContext, ShowExamplesContext
- Defined in:
- lib/jldrill/contexts/behaviour/SearchDictionary.rb
Overview
Provides the ability to search the kanji and JEDictionary.
Instance Method Summary collapse
-
#dictionaryLoaded? ⇒ Boolean
Returns true if the dictionary is loaded.
- #findKanjiInDictionary(character) ⇒ Object
-
#kanjiInfo(character) ⇒ Object
Returns the information for a given kanji character.
-
#kanjiLoaded? ⇒ Boolean
Returns true if the Kanji dictionary is loaded.
-
#search(string) ⇒ Object
Searches the dictionary for possible words in the string.
Instance Method Details
#dictionaryLoaded? ⇒ Boolean
Returns true if the dictionary is loaded
52 53 54 |
# File 'lib/jldrill/contexts/behaviour/SearchDictionary.rb', line 52 def dictionaryLoaded? @parent.reference.loaded? end |
#findKanjiInDictionary(character) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/jldrill/contexts/behaviour/SearchDictionary.rb', line 11 def findKanjiInDictionary(character) retVal = [] if dictionaryLoaded? retVal = @parent.reference.findKanji(character) end return retVal end |
#kanjiInfo(character) ⇒ Object
Returns the information for a given kanji character
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jldrill/contexts/behaviour/SearchDictionary.rb', line 20 def kanjiInfo(character) retVal = "" entries = findKanjiInDictionary(character) kanji = @parent.kanji.kanjiList.findChar(character) # If the kanji isn't found, it might be a simplified # character. If the character was a word in the dictionary, # we can use the kanji entry for one of dictionary entries # and search the kanji information again. if kanji.nil? && !entries.empty? kanji = @parent.kanji.kanjiList.findChar(entries[0].kanji) end if !kanji.nil? if @parent.quiz..language == "Chinese" retVal += kanji.withPinYinRadical_to_s(@parent.kanji.kanjiList, @parent.radicals.radicalList) else retVal += kanji.withRadical_to_s(@parent.radicals.radicalList) end if !entries.empty? retVal += "\n\nDictionary Lookup:\n" retVal += entries.join("\n") retVal += "\n" end else kana = @parent.kana.kanaList.findChar(character) if !kana.nil? retVal += kana.to_s end end retVal end |
#kanjiLoaded? ⇒ Boolean
Returns true if the Kanji dictionary is loaded
7 8 9 |
# File 'lib/jldrill/contexts/behaviour/SearchDictionary.rb', line 7 def kanjiLoaded? !@parent.kanji.nil? end |
#search(string) ⇒ Object
Searches the dictionary for possible words in the string. Attempts to deinflect the word and provide matches. Returns an array of DictionaryEntry.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jldrill/contexts/behaviour/SearchDictionary.rb', line 59 def search(string) matches = @parent.deinflect.match(string) retVal = matches.collect do |match| @parent.reference.findWord(match.last.dictionary) end.flatten retVal += @parent.reference.findWordsThatStart(string) return retVal.sort do |x,y| y.relevance <=> x.relevance end end |