LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
deeplima::MwtLexicon Class Reference

Multiword-token (MWT) lexicon: how to expand a surface token (French "du") into its syntactic words ("de", "le"). More...

#include <deeplima/mwt_lexicon.h>

Classes

struct  Rule

Public Member Functions

 MwtLexicon ()=default
 MwtLexicon (const std::string &fn)
void load (const std::string &fn)
void load (std::istream &f)
size_t size () const
size_t rules_size () const
bool has_seq2seq () const
void add_entry (const std::string &surface, const std::vector< std::string > &words)
void add_rule (Rule r)
const std::vector< std::string > * lookup (const std::string &surface) const
const Rule * find_rule (const std::string &surface) const
bool expand (const std::string &surface, std::vector< std::string > &words, bool use_rules) const
size_t learn_rules (uint32_t min_support)
void write_rules (std::ostream &out) const

Static Public Member Functions

static std::vector< Rule > rules_of (const std::string &surface, const std::vector< std::string > &words)
static size_t common_prefix (const std::string &a, const std::string &b)
static size_t common_suffix (const std::string &a, const std::string &b)

Detailed Description

Multiword-token (MWT) lexicon: how to expand a surface token (French "du") into its syntactic words ("de", "le").

Shared by deeplima's MwtExpander, by deeplima-mwt-dict, which builds it from training CoNLL-U files, and by LIMA's RnnTokenizer.

Two layers:

  • a dictionary of the surfaces seen in training, with their most frequent expansion;
  • affix rules, the fallback for a surface the segmenter flags as multiword but that the dictionary does not know. A suffix rule cuts a surface ending, rewrites the end of the remaining stem and adds fixed words: Polish "zrobiłem" = "zrobił" + "em" (suffix "em", no rewrite, word "em"); a Tamil surface may end with a fused form of the clitic, the rule's rewrite restores the stem's last letters. A prefix rule is the mirror (Arabic "و" + stem). Rules are learned from the dictionary itself: each entry gives one suffix rule (from its longest common prefix with its first word) and one prefix rule (from its longest common suffix with its last word); a rule is kept when at least min_support entries give it, and, for each affix, only the best rule. Rules are scored by their precision on the dictionary, support / (entries having the affix + 1), smoothed so that a rare affix does not win over a frequent one.
  • optionally, a character seq2seq model (MwtSeq2Seq, <file>.s2s beside the dictionary file), for flagged surfaces whose split is not a concatenation (Amharic, Tamil); the model file says whether it is tried before or after the affix rules.

Rules and the seq2seq are only meant for surfaces the segmenter flagged: applied to every token, they would split most words.

File format (UTF-8, one entry per line, tab-separated): surface count word1 word2 ... dictionary #rule suffix|prefix affix rewrite support applicable word1 ... A line starting with '#' is a comment to older readers, which thus keep reading the dictionary and ignore the rules.

Definition at line 63 of file mwt_lexicon.h.

Constructor & Destructor Documentation

◆ MwtLexicon() [1/2]

deeplima::MwtLexicon::MwtLexicon ( )
default

◆ MwtLexicon() [2/2]

deeplima::MwtLexicon::MwtLexicon ( const std::string & fn)
inlineexplicit

Definition at line 109 of file mwt_lexicon.h.

Member Function Documentation

◆ add_entry()

void deeplima::MwtLexicon::add_entry ( const std::string & surface,
const std::vector< std::string > & words )
inline

Definition at line 195 of file mwt_lexicon.h.

◆ add_rule()

void deeplima::MwtLexicon::add_rule ( Rule r)
inline

Definition at line 201 of file mwt_lexicon.h.

◆ common_prefix()

size_t deeplima::MwtLexicon::common_prefix ( const std::string & a,
const std::string & b )
inlinestatic

Definition at line 405 of file mwt_lexicon.h.

◆ common_suffix()

size_t deeplima::MwtLexicon::common_suffix ( const std::string & a,
const std::string & b )
inlinestatic

Definition at line 421 of file mwt_lexicon.h.

◆ expand()

bool deeplima::MwtLexicon::expand ( const std::string & surface,
std::vector< std::string > & words,
bool use_rules ) const
inline

Definition at line 251 of file mwt_lexicon.h.

◆ find_rule()

const Rule * deeplima::MwtLexicon::find_rule ( const std::string & surface) const
inline

Definition at line 224 of file mwt_lexicon.h.

◆ has_seq2seq()

bool deeplima::MwtLexicon::has_seq2seq ( ) const
inline

Definition at line 190 of file mwt_lexicon.h.

◆ learn_rules()

size_t deeplima::MwtLexicon::learn_rules ( uint32_t min_support)
inline

Definition at line 290 of file mwt_lexicon.h.

◆ load() [1/2]

void deeplima::MwtLexicon::load ( const std::string & fn)
inline

Definition at line 114 of file mwt_lexicon.h.

◆ load() [2/2]

void deeplima::MwtLexicon::load ( std::istream & f)
inline

Definition at line 130 of file mwt_lexicon.h.

◆ lookup()

const std::vector< std::string > * deeplima::MwtLexicon::lookup ( const std::string & surface) const
inline

Definition at line 217 of file mwt_lexicon.h.

◆ rules_of()

std::vector< Rule > deeplima::MwtLexicon::rules_of ( const std::string & surface,
const std::vector< std::string > & words )
inlinestatic

Definition at line 370 of file mwt_lexicon.h.

◆ rules_size()

size_t deeplima::MwtLexicon::rules_size ( ) const
inline

Definition at line 185 of file mwt_lexicon.h.

◆ size()

size_t deeplima::MwtLexicon::size ( ) const
inline

Definition at line 180 of file mwt_lexicon.h.

◆ write_rules()

void deeplima::MwtLexicon::write_rules ( std::ostream & out) const
inline

Definition at line 347 of file mwt_lexicon.h.


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