Class: Zenlish::Lex::Lexicon
- Inherits:
-
Object
- Object
- Zenlish::Lex::Lexicon
- 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
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#lemma2entry ⇒ Object
readonly
Returns the value of attribute lemma2entry.
-
#name2terminal ⇒ Object
readonly
Returns the value of attribute name2terminal.
-
#terminals ⇒ Object
readonly
The list of terminal symbols.
Instance Method Summary collapse
- #add_entry(anEntry) ⇒ Object
- #add_terminal(aTerminal) ⇒ Object
- #get_lexeme(aLemma, aWordClass = nil) ⇒ Object
-
#initialize ⇒ Lexicon
constructor
A new instance of Lexicon.
Constructor Details
#initialize ⇒ Lexicon
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
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
6 7 8 |
# File 'lib/zenlish/lex/lexicon.rb', line 6 def entries @entries end |
#lemma2entry ⇒ Object (readonly)
Returns the value of attribute lemma2entry.
7 8 9 |
# File 'lib/zenlish/lex/lexicon.rb', line 7 def lemma2entry @lemma2entry end |
#name2terminal ⇒ Object (readonly)
Returns the value of attribute name2terminal.
13 14 15 |
# File 'lib/zenlish/lex/lexicon.rb', line 13 def name2terminal @name2terminal end |
#terminals ⇒ Object (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 |