Class: Iev::TermAttrsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/iev/term_attrs_parser.rb

Overview

Parses information from the spreadsheet’s TERMATTRIBUTE column and alike.

Examples:

parser = TermAttrsParser.new(cell_data_string)
parser.gender # returns grammatical gender
parser.plurality # returns grammatical plurality
parser.part_of_speech # returns part of speech

Constant Summary collapse

PARTS_OF_SPEECH =
{
  "adj" => "adj",
  "noun" => "noun",
  "verb" => "verb",
  "名詞" => "noun",
  "動詞" => "verb",
  "形容詞" => "adj",
  "형용사" => "adj",
  "Adjektiv" => "adj",
}.freeze
PREFIX_KEYWORDS =
%w[
  Präfix prefix préfixe 接尾語 접두사 przedrostek prefixo 词头
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_str) ⇒ TermAttrsParser

Returns a new instance of TermAttrsParser.



36
37
38
39
40
# File 'lib/iev/term_attrs_parser.rb', line 36

def initialize(attr_str)
  @raw_str = attr_str.dup.freeze
  @src_str = decode_attrs_string(raw_str).freeze
  parse
end

Instance Attribute Details

#genderObject (readonly)

Returns the value of attribute gender.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def gender
  @gender
end

#geographical_areaObject (readonly)

Returns the value of attribute geographical_area.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def geographical_area
  @geographical_area
end

#part_of_speechObject (readonly)

Returns the value of attribute part_of_speech.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def part_of_speech
  @part_of_speech
end

#pluralityObject (readonly)

Returns the value of attribute plurality.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def plurality
  @plurality
end

#prefixObject (readonly)

Returns the value of attribute prefix.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def prefix
  @prefix
end

#raw_strObject (readonly)

Returns the value of attribute raw_str.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def raw_str
  @raw_str
end

#src_strObject (readonly)

Returns the value of attribute src_str.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def src_str
  @src_str
end

#usage_infoObject (readonly)

Returns the value of attribute usage_info.



18
19
20
# File 'lib/iev/term_attrs_parser.rb', line 18

def usage_info
  @usage_info
end

Instance Method Details

#inspectObject



42
43
44
# File 'lib/iev/term_attrs_parser.rb', line 42

def inspect
  "<ATTRIBUTES: #{src_str}>".freeze
end

#to_grammar_infoObject

Constructs a Glossarist::Designation::GrammarInfo from the parsed gender, plurality, and part_of_speech attributes. Returns nil if none of these attributes were parsed.



49
50
51
52
53
54
55
56
57
# File 'lib/iev/term_attrs_parser.rb', line 49

def to_grammar_info
  return nil unless gender || plurality || part_of_speech

  Glossarist::Designation::GrammarInfo.new(
    gender: gender ? [gender] : nil,
    number: plurality ? [plurality] : nil,
    part_of_speech: part_of_speech,
  )
end