class Lingo::Language::Word

Attributes

lexicals[RW]
pattern[RW]

Public Class Methods

new(form, attr = WA_UNSET, token = nil) click to toggle source
Calls superclass method
# File lib/lingo/language/word.rb, line 74
def initialize(form, attr = WA_UNSET, token = nil)
  @token, @lexicals = token, []
  super
end
new_compound_head(lex, attr = WA_UNSET) click to toggle source
# File lib/lingo/language/word.rb, line 43
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) click to toggle source
# File lib/lingo/language/word.rb, line 39
def new_lexicals(form, attr, lex)
  new(form, attr) << lex
end

Public Instance Methods

<<(*lex) click to toggle source
# File lib/lingo/language/word.rb, line 131
def <<(*lex)
  lex.flatten!
  lexicals.concat(lex)
  self
end
<=>(other) click to toggle source
# File lib/lingo/language/word.rb, line 137
def <=>(other)
  other.nil? ? 1 : to_a.push(lexicals) <=> other.to_a.push(other.lexicals)
end
add_lexicals(lex) click to toggle source
# File lib/lingo/language/word.rb, line 81
def add_lexicals(lex)
  lexicals.concat(lex - lexicals)
end
attr?(*attr) click to toggle source
# File lib/lingo/language/word.rb, line 85
def attr?(*attr)
  !(attrs & attr).empty?
end
attrs() click to toggle source
# File lib/lingo/language/word.rb, line 89
def attrs
  lexicals.map(&:attr)
end
compound_attrs() click to toggle source
# File lib/lingo/language/word.rb, line 93
def compound_attrs
  attr == WA_COMPOUND ? attrs.grep(LA_COMPOUND) : attrs
end
each_lex(wc_re = //) { |self| ... } click to toggle source
# File lib/lingo/language/word.rb, line 111
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
genders() click to toggle source
# File lib/lingo/language/word.rb, line 97
def genders
  lexicals.map(&:gender)
end
identify(lex, wc = nil, seq = nil) click to toggle source
# File lib/lingo/language/word.rb, line 101
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 = //) { |form| ... } click to toggle source
# File lib/lingo/language/word.rb, line 122
def lex_form(wc_re = //)
  each_lex(wc_re) { |lex|
    break block_given? ? yield(lex.form) : lex.form }
end
position_and_offset() click to toggle source
# File lib/lingo/language/word.rb, line 127
def position_and_offset
  token.position_and_offset if token
end
to_s() click to toggle source
# File lib/lingo/language/word.rb, line 141
def to_s
  s =  "<#{form}"
  s << "|#{attr}" unless identified?
  s << " = #{lexicals.inspect}" unless lexicals.empty?
  s << '>'
end