Class: LLT::Morphologizer

Inherits:
Object
  • Object
show all
Includes:
Core::Serviceable, Helpers::Constantize, Helpers::Normalizer, Helpers::Pluralize, Helpers::PrimitiveCache
Defined in:
lib/llt/morphologizer.rb,
lib/llt/morphologizer/version.rb,
lib/llt/morphologizer/lookup_statement.rb,
lib/llt/morphologizer/stem_lookup_statement_builder.rb

Overview

Analyzes a token string morphologically.

Looks up stems in a given db-dictionary and builds LLT::Form objects with the help of the LLT::FormBuilder.

Defined Under Namespace

Classes: LookupStatement, StemLookupStatementBuilder

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Morphologizer

Returns a new instance of Morphologizer.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :cache (true)

    enables caching

  • :db (DbHandler)

    db-handling object used to obtain stem information

  • :logger (Logger)

    object used for logging



33
34
35
36
# File 'lib/llt/morphologizer.rb', line 33

def initialize(options = {})
  super
  enable_cache if options[:cache]
end

Instance Method Details

#morphologize(word, add_to: nil) ⇒ Array<LLT::Form>

Takes a string and analyzes it morphologically

Parameters:

  • word (String)

    token to be analyzed

  • add_to (#<<) (defaults to: nil)

    Keyword Argument: can optionally defer the returned forms to an object

Returns:

  • (Array<LLT::Form>)

    all valid Latin forms of the given string



45
46
47
48
49
# File 'lib/llt/morphologizer.rb', line 45

def morphologize(word, add_to: nil)
  forms = cached(word) { compute(word) }
  add_to << forms if add_to.respond_to?(:<<)
  forms
end