Sha256: 11256aa1813e449b94e2858ea73ae4540e83dddc27fbe2679262be7a233d4af5

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module JLDrill::Behaviour
    # Provides the ability to search the kanji and JEDictionary.
    module SearchDictionary

        # Returns true if the Kanji dictionary is loaded
        def kanjiLoaded?
            !@parent.kanji.nil?
        end
       
        # Returns the information for a given kanji character
        def kanjiInfo(character)
            retVal = ""
            kanji = @parent.kanji.kanjiList.findChar(character)
            if !kanji.nil?
                retVal = kanji.withRadical_to_s(@parent.radicals.radicalList)
            else
                kana = @parent.kana.kanaList.findChar(character)
                if !kana.nil?
                    retVal = kana.to_s
                end
            end
            retVal
        end

        # Returns true if the dictionary is loaded
        def dictionaryLoaded?
            @parent.reference.loaded?
        end

        # Searches the dictionary for possible words in the string.
        # Attempts to deinflect the word and provide matches.
        # Returns an array of JWords.
        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
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jldrill-0.5.1.7 lib/jldrill/contexts/behaviour/SearchDictionary.rb