StringEncodingDictionary< Token > Class Template Reference

This class provides a dictionary interface for the purpose of string encoding. More...

Public Types

using MapType = std::unordered_map< Token, size_t >
 A convenient alias for the internal type of the map. More...

 
using TokenType = Token
 The type of the token that the dictionary stores. More...

 

Public Member Functions

template
<
typename
T
>
size_t AddToken (T &&token)
 The function adds the given token to the dictionary and assigns a label to the token. More...

 
void Clear ()
 Clear the dictionary. More...

 
bool HasToken (const Token &token) const
 The function returns true if the dictionary contains the given token. More...

 
const MapTypeMapping () const
 Get the mapping. More...

 
MapTypeMapping ()
 Modify the mapping. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const unsigned int)
 Serialize the class to the given archive. More...

 
size_t Size () const
 Get the size of the dictionary. More...

 
size_t Value (const Token &token) const
 The function returns the label assigned to the given token. More...

 

Detailed Description


template
<
typename
Token
>

class mlpack::data::StringEncodingDictionary< Token >

This class provides a dictionary interface for the purpose of string encoding.

It works like an adapter to the internal dictionary.

Template Parameters
TokenType of the token that the dictionary stores.

Definition at line 32 of file string_encoding_dictionary.hpp.

Member Typedef Documentation

◆ MapType

using MapType = std::unordered_map<Token, size_t>

A convenient alias for the internal type of the map.

Definition at line 36 of file string_encoding_dictionary.hpp.

◆ TokenType

using TokenType = Token

The type of the token that the dictionary stores.

Definition at line 39 of file string_encoding_dictionary.hpp.

Member Function Documentation

◆ AddToken()

size_t AddToken ( T &&  token)
inline

The function adds the given token to the dictionary and assigns a label to the token.

The label is equal to the resulting size of the dictionary. The function returns the assigned label.

Parameters
tokenThe given token.

Definition at line 59 of file string_encoding_dictionary.hpp.

◆ Clear()

void Clear ( )
inline

Clear the dictionary.

Definition at line 83 of file string_encoding_dictionary.hpp.

◆ HasToken()

bool HasToken ( const Token &  token) const
inline

The function returns true if the dictionary contains the given token.

Parameters
tokenThe given token.

Definition at line 46 of file string_encoding_dictionary.hpp.

◆ Mapping() [1/2]

const MapType& Mapping ( ) const
inline

Get the mapping.

Definition at line 89 of file string_encoding_dictionary.hpp.

◆ Mapping() [2/2]

MapType& Mapping ( )
inline

Modify the mapping.

Definition at line 91 of file string_encoding_dictionary.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const unsigned  int 
)
inline

Serialize the class to the given archive.

Definition at line 97 of file string_encoding_dictionary.hpp.

◆ Size()

size_t Size ( ) const
inline

Get the size of the dictionary.

Definition at line 80 of file string_encoding_dictionary.hpp.

◆ Value()

size_t Value ( const Token &  token) const
inline

The function returns the label assigned to the given token.

The function throws std::out_of_range if no such token is found.

Parameters
tokenThe given token.

Definition at line 74 of file string_encoding_dictionary.hpp.


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