nlib
nn::nlib::succinct::WordFilter Class Referencefinal

Class that checks whether text contains the predefined set of words. More...

#include "nn/nlib/succinct/WordFilter.h"

Public Types

typedef bool(* MatchCallback) (const char *first, const char *last, uint32_t nodeid, void *user_obj)
 The callback that is called when the pattern is matched. More...
 

Public Member Functions

void Match (const char *doc, MatchCallback callback, void *user_obj) noexcept
 Inspects the string to detect the registered string. More...
 
void Match (const char *doc, MatchCallback callback) noexcept
 A parameter omitted version of the above function which passes nullptr as a parameter.
 
void Match (const char *data, size_t n, MatchCallback callback, void *user_obj) noexcept
 Inspects the data to detect the target pattern. More...
 
void Match (const char *data, size_t n, MatchCallback callback) noexcept
 A parameter omitted version of the above function which passes nullptr as a parameter.
 
Constructor, Destructor, and Initialization
constexpr WordFilter () noexcept
 Instantiates the object with default parameters (default constructor). Requires initialization with Init() after execution.
 
 ~WordFilter () noexcept
 Destructor.
 
WordFilterassign (WordFilter &rhs, move_tag)
 Corresponds to a move assignment operator.
 
 WordFilter (WordFilter &rhs, move_tag)
 Corresponds to a move constructor.
 
 WordFilter (WordFilter &&rhs)
 Instantiates the object (move constructor).
 
WordFilteroperator= (WordFilter &&rhs)
 Move assignment operator.
 
bool Init () noexcept
 Initializes an object. Returns true if successful.
 
void Reset () noexcept
 Resets this object to the state immediately after the default constructor was executed.
 
Importing and Exporting
bool Export (BinaryWriter *w) const noexcept
 Writes the object to the file. More...
 
bool Import (BinaryReader *r) noexcept
 Reads the written object. More...
 

Detailed Description

Class that checks whether text contains the predefined set of words.

Description
This class is similar to the AhoCorasick class, but the callback is not made if the matched term is part of the specified excluded terms.
When a specified term is found, the MatchCallback function is called. The callback is not called when the matched term is part or whole of a predefined excluded term.
Consider the behavior when you are matching the pattern "abc" but "zabc" is an excluded term.
  • "abcd" matches "abc" so the callback is called.
  • "zabcd" matches "abc" but "zabc" is an excluded term, so the callback is not called even though it matches the pattern.

Definition at line 30 of file WordFilter.h.

Member Typedef Documentation

◆ MatchCallback

nn::nlib::succinct::WordFilter::MatchCallback

The callback that is called when the pattern is matched.

Parameters
[in]firstPointer to the start of the matched pattern.
[in]lastPointer to the end of the matched pattern.
[in]nodeidThe ID of the matched pattern.
[in]user_objPointer to the user-specified object.

Definition at line 32 of file WordFilter.h.

Member Function Documentation

◆ Export()

nn::nlib::succinct::WordFilter::Export ( BinaryWriter w) const
noexcept

Writes the object to the file.

Parameters
[in]wWrite out object.
Returns
Returns true when successful.
Description
The written data can be read and restored using the Import function. The data is always written little endian.

◆ Import()

nn::nlib::succinct::WordFilter::Import ( BinaryReader r)
noexcept

Reads the written object.

Parameters
[in]rRead out object.
Returns
Returns true when import is successful.

◆ Match() [1/2]

nn::nlib::succinct::WordFilter::Match ( const char *  doc,
MatchCallback  callback,
void *  user_obj 
)
inlinenoexcept

Inspects the string to detect the registered string.

Parameters
[in]docString that terminates at null.
[in]callbackCallback function called when the term is detected.
[in,out]user_objPointer to the user-specified object.

Definition at line 38 of file WordFilter.h.

◆ Match() [2/2]

nn::nlib::succinct::WordFilter::Match ( const char *  data,
size_t  n,
MatchCallback  callback,
void *  user_obj 
)
noexcept

Inspects the data to detect the target pattern.

Parameters
[in]dataPointer to the head of the data to be inspected.
[in]nData size.
[in]callbackCallback function called when the pattern is detected.
[in,out]user_objPointer to the user-specified object.

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