Class: JLDrill::VocabularyUsage

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/model/VocabularyUsage.rb

Overview

Describes how a piece of vocabulary has been used in a sentence. It includes the kanji, reading, the sense that the vocabulary was used, the grammatical form that was used and whether the usage has been checked as being accurate. This class also includes input and output routines for the Tanaka “B” lines.

Defined Under Namespace

Classes: Map

Constant Summary collapse

B_LINE_RE =
/^([^(\[{~]*)(\(([^)]*)\))?(\[([^\]]*)\])?(\{([^}]*)\})?(~)?/u
HASH_RE =
/([^{(\[~]*(\([^)]*\))?)/u

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVocabularyUsage

Returns a new instance of VocabularyUsage.



82
83
84
85
86
87
88
# File 'lib/jldrill/model/VocabularyUsage.rb', line 82

def initialize()
    @kanji = ""
    @reading = ""
    @sense = 0
    @usedForm = ""
    @checked = false
end

Instance Attribute Details

#checkedObject

Returns the value of attribute checked.



12
13
14
# File 'lib/jldrill/model/VocabularyUsage.rb', line 12

def checked
  @checked
end

#kanjiObject

Returns the value of attribute kanji.



12
13
14
# File 'lib/jldrill/model/VocabularyUsage.rb', line 12

def kanji
  @kanji
end

#readingObject

Returns the value of attribute reading.



12
13
14
# File 'lib/jldrill/model/VocabularyUsage.rb', line 12

def reading
  @reading
end

#senseObject

Returns the value of attribute sense.



12
13
14
# File 'lib/jldrill/model/VocabularyUsage.rb', line 12

def sense
  @sense
end

#usedFormObject

Returns the value of attribute usedForm.



12
13
14
# File 'lib/jldrill/model/VocabularyUsage.rb', line 12

def usedForm
  @usedForm
end

Class Method Details

.from_B_line(data) ⇒ Object

Create a VocabularyUsage from data taken from a Tanaka “B” line Note: This is not the whole line. Just the data for a single vocabulary.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/jldrill/model/VocabularyUsage.rb', line 93

def VocabularyUsage::from_B_line(data)
    retVal = VocabularyUsage.new()
    if B_LINE_RE.match(data)
        retVal.kanji = $1
        retVal.reading = $3
        if !$5.nil?
            retVal.sense = $5.to_i
        else
            retVal.sense = 0
        end
        retVal.usedForm = $7
        retVal.checked = $8.eql?("~")
    end
    return retVal
end

.hashFrom_B_line(data) ⇒ Object

Create a hash that can be used in a hash table for searching for vocabulary usages. This has is generated from a Tanaka “B” line. It is composed of the kanji followed by the reading, enclosed in parentheses, if the reading is ambiguous from the kanji.



114
115
116
117
118
119
120
# File 'lib/jldrill/model/VocabularyUsage.rb', line 114

def VocabularyUsage::hashFrom_B_line(data)
    retVal = ""
    if HASH_RE.match(data)
        retVal = $1
    end
    return retVal
end

.hashFromStrings(kanji, reading) ⇒ Object

Create a hash that can be used in a hash table for searching for vocabulary usages. This is generated from kanji and reading strings. Either can be nil. If the kanji is nil, then the reading is used for the kanji (for vocabulary without kanji). The reading should normally be nil, unless the reading from the kanji is ambiguous.



128
129
130
131
132
133
134
135
136
# File 'lib/jldrill/model/VocabularyUsage.rb', line 128

def VocabularyUsage::hashFromStrings(kanji, reading)
    if reading.nil?
        return kanji
    elsif kanji.nil?
        return reading
    else
        return "#{kanji}(#{reading})"
    end
end

Instance Method Details

#to_B_lineObject

Output the Vocabulary usage in the same form as used by the B lines in the Tanaka Corpus



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/jldrill/model/VocabularyUsage.rb', line 140

def to_B_line
    retVal = @kanji.to_s
    if !@reading.nil?
        retVal += "(#{@reading})"
    end
    if @sense != 0
        retVal += "[#{@sense.to_s}]"
    end
    if !@actual.nil?
        retVal += "{#{@actual.to_s}}"
    end
    if @checked
        retVal += "~"
    end
    return retVal
end

#to_sObject

Output a string form of the VocabularyUsage. Currently this is just the Tanaka “B” line data for the Vocabulary Usage.



160
161
162
# File 'lib/jldrill/model/VocabularyUsage.rb', line 160

def to_s
    return to_B_line
end