LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
deeplima::TokenSequenceAnalyzer< TaggingAuxScalar > Class Template Reference

#include <deeplima/token_sequence_analyzer.h>

Inheritance diagram for deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >:
deeplima::ITokenSequenceAnalyzer

Classes

class  TokenIterator
class  enriched_token_t
class  enriched_token_buffer_t
struct  lemm_cache_key_hash

Public Types

typedef TokenIterator output_iterator_t
Public Types inherited from deeplima::ITokenSequenceAnalyzer
typedef std::function< void(std::shared_ptr< StringIndex > stridx, const token_buffer_t<> &tokens, const std::vector< StringIndex::idx_t > &lemmata, std::shared_ptr< StdMatrix< uint8_t > > classes, size_t begin, size_t end) > output_callback_t

Public Member Functions

 TokenSequenceAnalyzer ()
 TokenSequenceAnalyzer (const std::string &model_fn, const std::string &lemm_model_fn, const std::string &lemm_dict_fn, const std::string &fixed_ini_fn, const std::string &lower_ini_fn, const std::string &fixed_lemm_fn, const std::string &lemm_rules_fn, const PathResolver &path_resolver, size_t buffer_size, size_t num_buffers)
void get_classes_from_fn (const std::string &fn, std::vector< std::string > &classes_names, std::vector< std::vector< std::string > > &classes)
virtual ~TokenSequenceAnalyzer ()
virtual void register_handler (const output_callback_t fn) override
virtual const std::vector< std::vector< std::string > > & get_classes () const override
virtual const std::vector< std::string > & get_class_names () const override
virtual std::shared_ptr< StringIndex > get_stridx () const override
virtual void finalize () override
virtual void operator() (const std::vector< deeplima::segmentation::token_pos > &tokens, uint32_t len) override

Protected Types

typedef std::pair< StringIndex::idx_t, morph_model::morph_feats_t > lemm_cache_key_t

Protected Member Functions

void acquire_buffer ()
void start_analysis (size_t buffer_idx, int count=-1)
void process_buffer (size_t buffer_idx)
void load_lemm_cache (const std::string &fn)
std::unordered_set< morph_model::morph_feats_t > load_pos_cache (const std::string &fn)
void load_lemm_rules (const std::string &fn)
 Loads the edit rules (deeplima-gen-lemm-dict –rules) used for the words missing from the lemma dictionary.
void lemmatize (const token_buffer_t<> &buffer, std::vector< StringIndex::idx_t > &lemm_buffer, std::shared_ptr< StdMatrix< uint8_t > > classes, size_t offset, size_t end)
 Lemmatizes buffer[0, end - offset).

Protected Attributes

size_t m_buffer_size
size_t m_current_buffer
size_t m_current_timepoint
std::shared_ptr< StringIndex > m_stridx_ptr
StringIndex & m_stridx
StringIndex::idx_t m_unk_idx
std::vector< token_buffer_t<> > m_buffers
std::vector< std::vector< StringIndex::idx_t > > m_lemm_buffers
tagging::impl::TaggingImpl< TaggingAuxScalar > m_cls
lemmatization::impl::LemmatizationImpl m_lemm
std::shared_ptr< StdMatrix< uint8_t > > m_classes
std::unordered_map< lemm_cache_key_t, StringIndex::idx_t, lemm_cache_key_hash > m_lemm_cache
std::unordered_set< morph_model::morph_feats_t > m_fixed_ini_cache
std::unordered_set< morph_model::morph_feats_t > m_lower_ini_cache
std::unordered_set< morph_model::morph_feats_t > m_fixed_lemm_cache
lemmatization::lemm_rules_t< morph_model::morph_feats_t > m_lemm_rules
output_callback_t m_output_callback

Detailed Description

template<typename TaggingAuxScalar = float>
class deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >

Definition at line 81 of file token_sequence_analyzer.h.

Member Typedef Documentation

◆ lemm_cache_key_t

template<typename TaggingAuxScalar = float>
typedef std::pair<StringIndex::idx_t, morph_model::morph_feats_t> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::lemm_cache_key_t
protected

Definition at line 561 of file token_sequence_analyzer.h.

◆ output_iterator_t

template<typename TaggingAuxScalar = float>
typedef TokenIterator deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::output_iterator_t

Definition at line 206 of file token_sequence_analyzer.h.

Constructor & Destructor Documentation

◆ TokenSequenceAnalyzer() [1/2]

template<typename TaggingAuxScalar = float>
deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::TokenSequenceAnalyzer ( )
inline

Definition at line 297 of file token_sequence_analyzer.h.

◆ TokenSequenceAnalyzer() [2/2]

template<typename TaggingAuxScalar = float>
deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::TokenSequenceAnalyzer ( const std::string & model_fn,
const std::string & lemm_model_fn,
const std::string & lemm_dict_fn,
const std::string & fixed_ini_fn,
const std::string & lower_ini_fn,
const std::string & fixed_lemm_fn,
const std::string & lemm_rules_fn,
const PathResolver & path_resolver,
size_t buffer_size,
size_t num_buffers )
inline

Definition at line 307 of file token_sequence_analyzer.h.

◆ ~TokenSequenceAnalyzer()

template<typename TaggingAuxScalar = float>
virtual deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::~TokenSequenceAnalyzer ( )
inlinevirtual

Definition at line 433 of file token_sequence_analyzer.h.

Member Function Documentation

◆ acquire_buffer()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::acquire_buffer ( )
inlineprotected

Definition at line 528 of file token_sequence_analyzer.h.

◆ finalize()

template<typename TaggingAuxScalar = float>
virtual void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::finalize ( )
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 465 of file token_sequence_analyzer.h.

◆ get_class_names()

template<typename TaggingAuxScalar = float>
virtual const std::vector< std::string > & deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::get_class_names ( ) const
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 448 of file token_sequence_analyzer.h.

◆ get_classes()

template<typename TaggingAuxScalar = float>
virtual const std::vector< std::vector< std::string > > & deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::get_classes ( ) const
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 443 of file token_sequence_analyzer.h.

◆ get_classes_from_fn()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::get_classes_from_fn ( const std::string & fn,
std::vector< std::string > & classes_names,
std::vector< std::vector< std::string > > & classes )
inline

Definition at line 426 of file token_sequence_analyzer.h.

◆ get_stridx()

template<typename TaggingAuxScalar = float>
virtual std::shared_ptr< StringIndex > deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::get_stridx ( ) const
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 453 of file token_sequence_analyzer.h.

◆ lemmatize()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::lemmatize ( const token_buffer_t<> & buffer,
std::vector< StringIndex::idx_t > & lemm_buffer,
std::shared_ptr< StdMatrix< uint8_t > > classes,
size_t offset,
size_t end )
inlineprotected

Lemmatizes buffer[0, end - offset).

Per word, the first that applies:

  1. a UPOS the lemmatization model learned is always lemmatized as is;
  2. the dictionary (form, UPOS+FEATS), which also caches 6 and 7 below;
  3. at sentence start, the fixed-ini / lower-ini UPOS lists;
  4. the fixed-lemm UPOS list (lemma = form);
  5. the edit rules (suffix, and prefix if the file has any);
  6. the seq2seq model. The dictionary comes before the UPOS lists: a list states what is usual for a part of speech, the dictionary what the training data says of this very word ("Deux" NUM is "deux", not "Deux"). Rules come before the model: they cannot scramble letters and cost a few lookups.

Definition at line 708 of file token_sequence_analyzer.h.

◆ load_lemm_cache()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::load_lemm_cache ( const std::string & fn)
inlineprotected

Definition at line 569 of file token_sequence_analyzer.h.

◆ load_lemm_rules()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::load_lemm_rules ( const std::string & fn)
inlineprotected

Loads the edit rules (deeplima-gen-lemm-dict –rules) used for the words missing from the lemma dictionary.

A rule whose UPOS or features the lemmatization model does not know could never match and is skipped.

Definition at line 657 of file token_sequence_analyzer.h.

◆ load_pos_cache()

template<typename TaggingAuxScalar = float>
std::unordered_set< morph_model::morph_feats_t > deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::load_pos_cache ( const std::string & fn)
inlineprotected

Definition at line 626 of file token_sequence_analyzer.h.

◆ operator()()

template<typename TaggingAuxScalar = float>
virtual void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::operator() ( const std::vector< deeplima::segmentation::token_pos > & tokens,
uint32_t len )
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 487 of file token_sequence_analyzer.h.

◆ process_buffer()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::process_buffer ( size_t buffer_idx)
inlineprotected

Definition at line 555 of file token_sequence_analyzer.h.

◆ register_handler()

template<typename TaggingAuxScalar = float>
virtual void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::register_handler ( const output_callback_t fn)
inlineoverridevirtual

Implements deeplima::ITokenSequenceAnalyzer.

Definition at line 437 of file token_sequence_analyzer.h.

◆ start_analysis()

template<typename TaggingAuxScalar = float>
void deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::start_analysis ( size_t buffer_idx,
int count = -1 )
inlineprotected

Definition at line 545 of file token_sequence_analyzer.h.

Member Data Documentation

◆ m_buffer_size

template<typename TaggingAuxScalar = float>
size_t deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_buffer_size
protected

Definition at line 764 of file token_sequence_analyzer.h.

◆ m_buffers

template<typename TaggingAuxScalar = float>
std::vector<token_buffer_t<> > deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_buffers
protected

Definition at line 771 of file token_sequence_analyzer.h.

◆ m_classes

template<typename TaggingAuxScalar = float>
std::shared_ptr< StdMatrix<uint8_t> > deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_classes
protected

Definition at line 776 of file token_sequence_analyzer.h.

◆ m_cls

template<typename TaggingAuxScalar = float>
tagging::impl::TaggingImpl<TaggingAuxScalar> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_cls
protected

Definition at line 774 of file token_sequence_analyzer.h.

◆ m_current_buffer

template<typename TaggingAuxScalar = float>
size_t deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_current_buffer
protected

Definition at line 765 of file token_sequence_analyzer.h.

◆ m_current_timepoint

template<typename TaggingAuxScalar = float>
size_t deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_current_timepoint
protected

Definition at line 766 of file token_sequence_analyzer.h.

◆ m_fixed_ini_cache

template<typename TaggingAuxScalar = float>
std::unordered_set<morph_model::morph_feats_t> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_fixed_ini_cache
protected

Definition at line 783 of file token_sequence_analyzer.h.

◆ m_fixed_lemm_cache

template<typename TaggingAuxScalar = float>
std::unordered_set<morph_model::morph_feats_t> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_fixed_lemm_cache
protected

Definition at line 785 of file token_sequence_analyzer.h.

◆ m_lemm

template<typename TaggingAuxScalar = float>
lemmatization::impl::LemmatizationImpl deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_lemm
protected

Definition at line 775 of file token_sequence_analyzer.h.

◆ m_lemm_buffers

template<typename TaggingAuxScalar = float>
std::vector<std::vector<StringIndex::idx_t> > deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_lemm_buffers
protected

Definition at line 772 of file token_sequence_analyzer.h.

◆ m_lemm_cache

template<typename TaggingAuxScalar = float>
std::unordered_map<lemm_cache_key_t, StringIndex::idx_t, lemm_cache_key_hash> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_lemm_cache
protected

Definition at line 778 of file token_sequence_analyzer.h.

◆ m_lemm_rules

template<typename TaggingAuxScalar = float>
lemmatization::lemm_rules_t<morph_model::morph_feats_t> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_lemm_rules
protected

Definition at line 786 of file token_sequence_analyzer.h.

◆ m_lower_ini_cache

template<typename TaggingAuxScalar = float>
std::unordered_set<morph_model::morph_feats_t> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_lower_ini_cache
protected

Definition at line 784 of file token_sequence_analyzer.h.

◆ m_output_callback

template<typename TaggingAuxScalar = float>
output_callback_t deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_output_callback
protected

Definition at line 788 of file token_sequence_analyzer.h.

◆ m_stridx

template<typename TaggingAuxScalar = float>
StringIndex& deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_stridx
protected

Definition at line 769 of file token_sequence_analyzer.h.

◆ m_stridx_ptr

template<typename TaggingAuxScalar = float>
std::shared_ptr<StringIndex> deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_stridx_ptr
protected

Definition at line 768 of file token_sequence_analyzer.h.

◆ m_unk_idx

template<typename TaggingAuxScalar = float>
StringIndex::idx_t deeplima::TokenSequenceAnalyzer< TaggingAuxScalar >::m_unk_idx
protected

Definition at line 770 of file token_sequence_analyzer.h.


The documentation for this class was generated from the following file: