Class: Lingo::Language::Grammar
- Inherits:
-
Object
- Object
- Lingo::Language::Grammar
- Includes:
- ArrayUtils
- Defined in:
- lib/lingo/language/grammar.rb
Overview
– Die Klasse Grammar beinhaltet grammatikalische Spezialitäten einer Sprache. Derzeit findet die Kompositumerkennung hier ihren Platz, die mit der Methode find_compound aufgerufen werden kann. Die Klasse Grammar wird genau wie ein Dictionary initialisiert. Das bei der Initialisierung angegebene Wörterbuch ist Grundlage für die Erkennung der Kompositumteile. ++
Constant Summary collapse
- HYPHEN_RE =
%r{\A(.+)-([^-]+)\z}
- DEFAULTS =
{ min_word_size: 8, min_avg_part_size: 4, min_part_size: 1, max_parts: 4 }
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #find_compound(str, level = 1, tail = false) ⇒ Object
- #find_compound_head(str) ⇒ Object
-
#initialize(config, lingo) ⇒ Grammar
constructor
A new instance of Grammar.
Constructor Details
#initialize(config, lingo) ⇒ Grammar
Returns a new instance of Grammar.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lingo/language/grammar.rb', line 54 def initialize(config, lingo) @dic, @suggestions = Dictionary.new(config, lingo), [] cfg = lingo.dictionary_config['compound'] DEFAULTS.each { |k, v| instance_variable_set( "@#{k}", cfg.fetch(k.to_s.tr('_', '-'), v).to_i) } #-- # Die Wortklasse eines Kompositum-Wortteils kann separat gekennzeichnet # werden, um sie von Wortklassen normaler Wörter unterscheiden zu # können z.B. Hausmeister => ['haus/s', 'meister/s'] oder Hausmeister # => ['haus/s+', 'meister/s+'] mit append-wordclass = '+' #++ @append_wc = cfg.fetch('append-wordclass', '') #-- # Bestimmte Sequenzen können als ungültige Komposita erkannt werden, # z.B. ist ein Kompositum aus zwei Adjetiven kein Kompositum, also # skip-sequence = 'aa' #++ @sequences = cfg.fetch('skip-sequences', []).map! { |i| i.downcase } end |
Class Method Details
.open(*args) ⇒ Object
48 49 50 51 52 |
# File 'lib/lingo/language/grammar.rb', line 48 def self.open(*args) yield grammar = new(*args) ensure grammar.close if grammar end |
Instance Method Details
#close ⇒ Object
78 79 80 |
# File 'lib/lingo/language/grammar.rb', line 78 def close @dic.close end |
#find_compound(str, level = 1, tail = false) ⇒ Object
82 83 84 85 86 |
# File 'lib/lingo/language/grammar.rb', line 82 def find_compound(str, level = 1, tail = false) level == 1 ? (@_compound ||= {})[str] ||= permute_compound(Word.new(str, WA_UNKNOWN), str, level, tail) : permute_compound([[], [], ''], str, level, tail) end |
#find_compound_head(str) ⇒ Object
88 89 90 91 |
# File 'lib/lingo/language/grammar.rb', line 88 def find_compound_head(str) compound = find_compound(str) compound.head || compound if compound && !compound.unknown? end |