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 ⇒ Array<Lex::LexicalEntry>
readonly
Entries in the lexicon.
-
#lemma2entry ⇒ Hash{String => Lex::LexicalEntry}
readonly
The lexical entry for the given lemma.
-
#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) ⇒ Lex::Lexeme
-
#initialize ⇒ Lexicon
constructor
A new instance of Lexicon.
Constructor Details
#initialize ⇒ Lexicon
Returns a new instance of Lexicon.
18 19 20 21 22 23 |
# File 'lib/zenlish/lex/lexicon.rb', line 18 def initialize @entries = [] @lemma2entry = {} @terminals = [] @name2terminal = {} end |
Instance Attribute Details
#entries ⇒ Array<Lex::LexicalEntry> (readonly)
Returns entries in the lexicon.
7 8 9 |
# File 'lib/zenlish/lex/lexicon.rb', line 7 def entries @entries end |
#lemma2entry ⇒ Hash{String => Lex::LexicalEntry} (readonly)
Returns the lexical entry for the given lemma.
10 11 12 |
# File 'lib/zenlish/lex/lexicon.rb', line 10 def lemma2entry @lemma2entry end |
#name2terminal ⇒ Object (readonly)
Returns the value of attribute name2terminal.
16 17 18 |
# File 'lib/zenlish/lex/lexicon.rb', line 16 def name2terminal @name2terminal end |
#terminals ⇒ Object (readonly)
The list of terminal symbols. Examples of terminal symbols:
- word classes,
- punctuation signs,...
15 16 17 |
# File 'lib/zenlish/lex/lexicon.rb', line 15 def terminals @terminals end |
Instance Method Details
#add_entry(anEntry) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/zenlish/lex/lexicon.rb', line 65 def add_entry(anEntry) entries << anEntry lemma = anEntry.lemma update_mapping(lemma2entry, lemma, anEntry) end |
#add_terminal(aTerminal) ⇒ Object
59 60 61 62 |
# File 'lib/zenlish/lex/lexicon.rb', line 59 def add_terminal(aTerminal) terminals << aTerminal name2terminal[aTerminal.name] = aTerminal end |
#get_lexeme(aLemma, aWordClass = nil) ⇒ Lex::Lexeme
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zenlish/lex/lexicon.rb', line 29 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 entry = lemma2entry.fetch(aLemma) if entry.kind_of?(Array) err_msg = "Multiple lexemes for #{aLemma}" raise StandardError, err_msg else entry.lexemes.first end end end |