Class: Zenlish::Lex::Lexicon

Inherits:
Object
  • Object
show all
Defined in:
lib/zenlish/lex/lexicon.rb

Overview

A lexicon is a collection of lexical entries. Every entry is associated with one one more lexemes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLexicon

Returns a new instance of Lexicon.



15
16
17
18
19
20
# File 'lib/zenlish/lex/lexicon.rb', line 15

def initialize
  @entries = []
  @lemma2entry = {}
  @terminals = []
  @name2terminal = {}
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



6
7
8
# File 'lib/zenlish/lex/lexicon.rb', line 6

def entries
  @entries
end

#lemma2entryObject (readonly)

Returns the value of attribute lemma2entry.



7
8
9
# File 'lib/zenlish/lex/lexicon.rb', line 7

def lemma2entry
  @lemma2entry
end

#name2terminalObject (readonly)

Returns the value of attribute name2terminal.



13
14
15
# File 'lib/zenlish/lex/lexicon.rb', line 13

def name2terminal
  @name2terminal
end

#terminalsObject (readonly)

The list of terminal symbols. Examples of terminal symbols:

  • word classes,
  • punctuation signs,...


12
13
14
# File 'lib/zenlish/lex/lexicon.rb', line 12

def terminals
  @terminals
end

Instance Method Details

#add_entry(anEntry) ⇒ Object



50
51
52
53
54
55
# File 'lib/zenlish/lex/lexicon.rb', line 50

def add_entry(anEntry)
  entries << anEntry
  lemma = anEntry.lemma

  update_mapping(lemma2entry, lemma, anEntry)
end

#add_terminal(aTerminal) ⇒ Object



45
46
47
48
# File 'lib/zenlish/lex/lexicon.rb', line 45

def add_terminal(aTerminal)
  terminals << aTerminal
  name2terminal[aTerminal.name] = aTerminal
end

#get_lexeme(aLemma, aWordClass = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zenlish/lex/lexicon.rb', line 22

def get_lexeme(aLemma, aWordClass = nil)
  if aWordClass
    lexeme = nil
    candidate = nil

    entries = lemma2entry.fetch(aLemma)
    if entries.kind_of?(Array)
      entries.each do |e|
        candidate = e.lexemes.first
        break if candidate.wclass.kind_of?(aWordClass)
      end
      lexeme = candidate
    else
      candidate = entries.lexemes.first
      lexeme = candidate if candidate.wclass.kind_of?(aWordClass)
    end

    lexeme
  else
    lemma2entry.fetch(aLemma).lexemes.first
  end
end