liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
liblevenshtein::StateTransition Class Reference

Transitions Levenshtein States given a characteristic vector. More...

#include <state_transition.h>

Collaboration diagram for liblevenshtein::StateTransition:

Public Member Functions

 StateTransition (PositionTransitionFn transition, CompareFn compare, MergeFn merge, UnsubsumeFn unsubsume, std::size_t max_distance, std::size_t query_length)
 Constructs a new StateTransition function.
 
auto operator() (State *curr_state, std::vector< bool > &characteristic_vector) -> State *
 Returns a successive State to the current one given the characteristic vector.
 

Private Attributes

PositionTransitionFn transition
 Maps Position nodes and characteristic vectors to subsequent Position nodes.
 
CompareFn compare
 Compares Position nodes.
 
MergeFn merge
 Merges Positions into a State.
 
UnsubsumeFn unsubsume
 Removes redundant Positions from a State according to the notion of subsumption.
 
std::size_t max_distance
 Maximum edit distance to consider when matching spelling candidates.
 
std::size_t query_length
 Length of the query term.
 

Detailed Description

Transitions Levenshtein States given a characteristic vector.

Definition at line 28 of file state_transition.h.

Constructor & Destructor Documentation

◆ StateTransition()

liblevenshtein::StateTransition::StateTransition ( PositionTransitionFn transition,
CompareFn compare,
MergeFn merge,
UnsubsumeFn unsubsume,
std::size_t max_distance,
std::size_t query_length )

Constructs a new StateTransition function.

Parameters
transitionMaps Position nodes and characteristic vectors to subsequent Position nodes.
compareCompares Position nodes.
mergeMerges Positions into a State.
unsubsumeRemoves redundant Positions from a State according to the notion of subsumption.
max_distanceMaximum edit distance to consider when matching spelling candidates.
query_lengthLength of the query term.

Definition at line 8 of file state_transition.cpp.

13 : transition(std::move(transition)), compare(std::move(compare)),
14 merge(std::move(merge)), unsubsume(std::move(unsubsume)),
UnsubsumeFn unsubsume
Removes redundant Positions from a State according to the notion of subsumption.
MergeFn merge
Merges Positions into a State.
PositionTransitionFn transition
Maps Position nodes and characteristic vectors to subsequent Position nodes.
std::size_t query_length
Length of the query term.
std::size_t max_distance
Maximum edit distance to consider when matching spelling candidates.
CompareFn compare
Compares Position nodes.

Member Function Documentation

◆ operator()()

auto liblevenshtein::StateTransition::operator() ( State * curr_state,
std::vector< bool > & characteristic_vector ) -> State *

Returns a successive State to the current one given the characteristic vector.

Parameters
curr_stateCurrent State in the Levenshtein automaton.
characteristic_vectorMoving window over matching characters in the query term.
Returns
The next state in the Levenshtein automaton.

Definition at line 17 of file state_transition.cpp.

19 {
20 std::size_t offset = curr_state->head()->term_index();
21 auto *next_state = new State();
22 std::size_t n = max_distance;
23
24 for (Position *position : *curr_state) {
25 merge(next_state, transition(n, position, characteristic_vector, offset));
26 }
27
29
30 if (next_state->head() != nullptr) {
31 next_state->sort(compare);
32 return next_state;
33 }
34
35 delete next_state;
36 return nullptr;
37}
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25

References liblevenshtein::compare(), liblevenshtein::State::head(), liblevenshtein::merge(), and query().

Here is the call graph for this function:

Member Data Documentation

◆ compare

CompareFn liblevenshtein::StateTransition::compare
private

Compares Position nodes.

Definition at line 70 of file state_transition.h.

◆ max_distance

std::size_t liblevenshtein::StateTransition::max_distance
private

Maximum edit distance to consider when matching spelling candidates.

Definition at line 80 of file state_transition.h.

◆ merge

MergeFn liblevenshtein::StateTransition::merge
private

Merges Positions into a State.

Definition at line 73 of file state_transition.h.

◆ query_length

std::size_t liblevenshtein::StateTransition::query_length
private

Length of the query term.

Definition at line 83 of file state_transition.h.

◆ transition

PositionTransitionFn liblevenshtein::StateTransition::transition
private

Maps Position nodes and characteristic vectors to subsequent Position nodes.

Definition at line 67 of file state_transition.h.

◆ unsubsume

UnsubsumeFn liblevenshtein::StateTransition::unsubsume
private

Removes redundant Positions from a State according to the notion of subsumption.

Definition at line 77 of file state_transition.h.


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