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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from WordForm

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

Constructor Details

- (Word) initialize(form, attr = WA_UNSET)

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)
  super
  @lexicals = []
end

Instance Attribute Details

- (Object) lexicals(compound_parts = true)



82
83
84
85
86
87
88
# File 'lib/lingo/language/word.rb', line 82

def lexicals(compound_parts = true)
  if !compound_parts && attr == WA_COMPOUND
    @lexicals.select { |lex| lex.attr == LA_COMPOUND }
  else
    @lexicals
  end
end

Class Method Details

+ (Object) new_compound_head(lex, attr = WA_UNSET)



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

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

+ (Object) new_lexical(form, attr, lex_attr)



42
43
44
# File 'lib/lingo/language/word.rb', line 42

def new_lexical(form, attr, lex_attr)
  new_lexicals(form, attr, Lexical.new(form, lex_attr))
end

+ (Object) new_lexicals(form, attr, lex)



38
39
40
# File 'lib/lingo/language/word.rb', line 38

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

Instance Method Details

- (Object) <<(*lex)



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

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

- (Object) <=>(other)



147
148
149
# File 'lib/lingo/language/word.rb', line 147

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

- (Object) add_lexicals(lex)



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

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

- (Boolean) attr?(*attr)



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

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

- (Object) attrs(compound_parts = true)



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

def attrs(compound_parts = true)
  lexicals(compound_parts).map { |i| i.attr }
end

- (Object) compo_form



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

def compo_form
  get_class(LA_COMPOUND).first if attr == WA_COMPOUND
end

- (Boolean) full_compound?



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

def full_compound?
  attr == WA_COMPOUND && get_class('x+').empty?
end

- (Object) genders(compound_parts = true)



102
103
104
# File 'lib/lingo/language/word.rb', line 102

def genders(compound_parts = true)
  lexicals(compound_parts).map { |i| i.gender }
end

- (Object) get_class(wc_re)

Gibt genau die Grundform der Wortklasse zurück, die der RegExp des Übergabe-Parameters entspricht, z.B. word.get_wc(/a/) = ['abgeschoben', '#a']



118
119
120
121
122
123
# File 'lib/lingo/language/word.rb', line 118

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

  lexicals.empty? ? attr =~ wc_re ? [self] : [] :
    lexicals.select { |lex| lex.attr =~ wc_re }
end

- (Object) identify(lex, wc = nil)



106
107
108
109
110
111
112
113
114
# File 'lib/lingo/language/word.rb', line 106

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

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

  self
end

- (Object) multiword_size(wc_re = LA_MULTIWORD)



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

def multiword_size(wc_re = LA_MULTIWORD)
  lex = get_class(wc_re).first and lex.form.count(' ') + 1
end

- (Object) norm



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

def norm
  identified? ? lexicals.first.form : form
end

- (Object) to_s



151
152
153
154
155
156
# File 'lib/lingo/language/word.rb', line 151

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