liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
|
A Directed Acyclic Word Graph (DAWG) maps sequences of characters to form words; the collection of words is known as a dictionary. More...
#include <dawg.h>
Public Member Functions | |
Dawg (DawgNode *root, std::size_t size) | |
Constructs a new DAWG with the given root node and number of dictionary terms (size). | |
Dawg () | |
Constructs an empty DAWG with a default root node (there are no outgoing edges or reachable terms from the root, not even the empty string). | |
virtual | ~Dawg () |
Deletes all the nodes associated with this dictionary. | |
virtual auto | add (const std::string &term) -> bool=0 |
Adds a new term to this dictionary by adding missing sequential edges leading outward from the root node. | |
virtual auto | remove (const std::string &term) -> bool=0 |
Removes a term from this dictionary and cleans up its path. | |
auto | contains (const std::string &term) const -> bool |
Determines whether the given term is contained within this dictionary. | |
auto | root () const -> DawgNode * |
Returns a pointer to the root node of this dictionary from which all its terms may be determined. | |
auto | size () const -> size_t |
Returns the number of terms in this dictionary. | |
auto | begin () const -> DawgIterator |
Returns an iterator pointing to the first term in this dictionary, from which all terms may be iterated over. | |
auto | end () const -> DawgIterator |
Returns an iterator representing the boundary following the final term in this dictionary. | |
auto | operator== (const Dawg &other) const -> bool |
Determines whether another DAWG is equivalent to this one. | |
Protected Member Functions | |
auto | all_nodes () const -> std::unordered_set< DawgNode * > |
Returns a set of all nodes reachable from the root, including the root. | |
Protected Attributes | |
DawgNode * | _root |
Root node of this DAWG from which all its terms may be reached. | |
std::size_t | _size |
Number of terms reachable from the root node. | |
Friends | |
class | std::hash< Dawg > |
Specifies the hash function for this DAWG may view its membership. | |
auto | operator<< (std::ostream &out, const Dawg &dawg) -> std::ostream & |
Specifies the output streaming operator for this DAWG may view its membership. | |
A Directed Acyclic Word Graph (DAWG) maps sequences of characters to form words; the collection of words is known as a dictionary.
As its name implies, it is a directed, acyclic automaton having a single root node from which all terms in the dictionary are reachable. It is important that only those terms in the dictionary may be formed by traversing the edges of the DAWG, no terms that are not in the dictionary may be formed by joining subsequent outgoing edges from the root. Nodes denoting word boundaries are flagged as being final.
liblevenshtein::Dawg::Dawg | ( | DawgNode * | root, |
std::size_t | size ) |
Constructs a new DAWG with the given root node and number of dictionary terms (size).
The number of terms reachable by combining the subsequent outgoing edges from the root must be equal to the size.
root | Node from which all dictionary terms may be reached by subsequently traversing its outgoing edges. |
size | Number of terms in the dictionary. |
Definition at line 12 of file dawg.cpp.
liblevenshtein::Dawg::Dawg | ( | ) |
|
virtual |
Deletes all the nodes associated with this dictionary.
Definition at line 22 of file dawg.cpp.
References all_nodes().
Adds a new term to this dictionary by adding missing sequential edges leading outward from the root node.
term | The term to add to this dictionary. |
Implemented in liblevenshtein::SortedDawg.
Returns a set of all nodes reachable from the root, including the root.
Definition at line 28 of file dawg.cpp.
References _root, and query().
Referenced by liblevenshtein::SortedDawg::clean_up(), and ~Dawg().
auto liblevenshtein::Dawg::begin | ( | ) | const -> DawgIterator |
Determines whether the given term is contained within this dictionary.
term | Query term whose membership in this dictionary must be determined. |
Definition at line 43 of file dawg.cpp.
References liblevenshtein::DawgNode::is_final(), query(), and liblevenshtein::DawgNode::transition().
Referenced by liblevenshtein::from_protobuf().
auto liblevenshtein::Dawg::end | ( | ) | const -> DawgIterator |
Returns an iterator representing the boundary following the final term in this dictionary.
The value of the iterator is not a term, but represent a boundary that must not be crossed.
Definition at line 63 of file dawg.cpp.
References _size.
Removes a term from this dictionary and cleans up its path.
term | The term to remove from this dictionary. |
Implemented in liblevenshtein::SortedDawg.
|
protected |
Root node of this DAWG from which all its terms may be reached.
Definition at line 126 of file dawg.h.
Referenced by all_nodes(), begin(), and root().
|
protected |