Class: Lingo::Language::Word

Inherits:
WordForm show all
Defined in:
lib/lingo/language/word.rb

Overview

– Die Klasse Word bündelt spezifische Eigenschaften eines Wortes mit den dazu notwendigen Methoden. ++

Instance Attribute Summary collapse

Attributes inherited from WordForm

#attr, #form, #gender, #head, #src, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WordForm

#eql?, #hash, #identified?, #inspect, #to_a, #unknown?, #word_token?

Constructor Details

#initialize(form, attr = WA_UNSET, token = nil) ⇒ Word

– Exakte Representation der originären Zeichenkette, so wie sie im Satz gefunden wurde, z.B. form = "RubyLing"

Ergebnis der Wörterbuch-Suche. Sie stellt die Grundform des Wortes dar. Dabei kann es mehrere mögliche Grundformen geben, z.B. kann abgeschoben als Grundform das Adjektiv abgeschoben sein, oder aber das Verb abschieben.

lemma = [['abgeschoben', '#a'], ['abschieben', '#v']].

Achtung: Lemma wird nicht durch die Word-Klasse bestückt, sondern extern durch die Klasse Dictionary ++



75
76
77
78
# File 'lib/lingo/language/word.rb', line 75

def initialize(form, attr = WA_UNSET, token = nil)
  @token, @lexicals = token, []
  super
end

Instance Attribute Details

#lexicalsObject

Returns the value of attribute lexicals.



80
81
82
# File 'lib/lingo/language/word.rb', line 80

def lexicals
  @lexicals
end

#patternObject

Returns the value of attribute pattern.



80
81
82
# File 'lib/lingo/language/word.rb', line 80

def pattern
  @pattern
end

Class Method Details

.new_compound_head(lex, attr = WA_UNSET) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lingo/language/word.rb', line 44

def new_compound_head(lex, attr = WA_UNSET)
  form, head_lex = nil, []

  lex.reverse_each { |l|
    src =  l.src ||= l.form
    form ||= src
    form  != src ? break : head_lex.unshift(l.dup)
  }

  head_lex.each { |l| l.attr = l.attr[/\w+/] }.uniq!

  new_lexicals(form, attr, head_lex) if form
end

.new_lexicals(form, attr, lex) ⇒ Object



40
41
42
# File 'lib/lingo/language/word.rb', line 40

def new_lexicals(form, attr, lex)
  new(form, attr) << lex
end

Instance Method Details

#<<(*lex) ⇒ Object



132
133
134
135
136
# File 'lib/lingo/language/word.rb', line 132

def <<(*lex)
  lex.flatten!
  lexicals.concat(lex)
  self
end

#<=>(other) ⇒ Object



138
139
140
# File 'lib/lingo/language/word.rb', line 138

def <=>(other)
  other.nil? ? 1 : to_a.push(lexicals) <=> other.to_a.push(other.lexicals)
end

#add_lexicals(lex) ⇒ Object



82
83
84
# File 'lib/lingo/language/word.rb', line 82

def add_lexicals(lex)
  lexicals.concat(lex - lexicals)
end

#attr?(*attr) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/lingo/language/word.rb', line 86

def attr?(*attr)
  !(attrs & attr).empty?
end

#attrsObject



90
91
92
# File 'lib/lingo/language/word.rb', line 90

def attrs
  lexicals.map(&:attr)
end

#compound_attrsObject



94
95
96
# File 'lib/lingo/language/word.rb', line 94

def compound_attrs
  attr == WA_COMPOUND ? attrs.grep(LA_COMPOUND) : attrs
end

#each_lex(wc_re = //) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/lingo/language/word.rb', line 112

def each_lex(wc_re = //)
  return enum_for(__method__, wc_re) unless block_given?

  wc_re = Regexp.new(wc_re) unless wc_re.is_a?(Regexp)

  lexicals.empty? ? attr =~ wc_re ? yield(self) : nil :
    lexicals.each { |lex| yield lex if lex.attr =~ wc_re }

  nil
end

#gendersObject



98
99
100
# File 'lib/lingo/language/word.rb', line 98

def genders
  lexicals.map(&:gender)
end

#identify(lex, wc = nil, seq = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/lingo/language/word.rb', line 102

def identify(lex, wc = nil, seq = nil)
  return self if lex.empty?

  self.lexicals, self.pattern = lex, seq
  self.attr = wc ||= attr?(LA_COMPOUND) ? WA_COMPOUND : WA_IDENTIFIED
  self.head = self.class.new_compound_head(lex) if wc == WA_COMPOUND

  self
end

#lex_form(wc_re = //) ⇒ Object



123
124
125
126
# File 'lib/lingo/language/word.rb', line 123

def lex_form(wc_re = //)
  each_lex(wc_re) { |lex|
    break block_given? ? yield(lex.form) : lex.form }
end

#position_and_offsetObject



128
129
130
# File 'lib/lingo/language/word.rb', line 128

def position_and_offset
  token.position_and_offset if token
end

#to_sObject



142
143
144
145
146
147
# File 'lib/lingo/language/word.rb', line 142

def to_s
  s =  "<#{form}"
  s << "|#{attr}" unless identified?
  s << " = #{lexicals.inspect}" unless lexicals.empty?
  s << '>'
end