tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
tesseract::Dawg Class Referenceabstract

#include <dawg.h>

Inheritance diagram for tesseract::Dawg:
Collaboration diagram for tesseract::Dawg:

Public Member Functions

DawgType type () const
 
const STRINGlang () const
 
PermuterType permuter () const
 
virtual ~Dawg ()
 
bool word_in_dawg (const WERD_CHOICE &word) const
 Returns true if the given word is in the Dawg. More...
 
bool prefix_in_dawg (const WERD_CHOICE &prefix, bool requires_complete) const
 
int check_for_words (const char *filename, const UNICHARSET &unicharset, bool enable_wildcard) const
 
void iterate_words (const UNICHARSET &unicharset, TessCallback1< const WERD_CHOICE *> *cb) const
 
void iterate_words (const UNICHARSET &unicharset, TessCallback1< const char *> *cb) const
 
virtual EDGE_REF edge_char_of (NODE_REF node, UNICHAR_ID unichar_id, bool word_end) const =0
 Returns the edge that corresponds to the letter out of this node. More...
 
virtual void unichar_ids_of (NODE_REF node, NodeChildVector *vec, bool word_end) const =0
 
virtual NODE_REF next_node (EDGE_REF edge_ref) const =0
 
virtual bool end_of_word (EDGE_REF edge_ref) const =0
 
virtual UNICHAR_ID edge_letter (EDGE_REF edge_ref) const =0
 Returns UNICHAR_ID stored in the edge indicated by the given EDGE_REF. More...
 
virtual void print_node (NODE_REF node, int max_num_edges) const =0
 
virtual void unichar_id_to_patterns (UNICHAR_ID unichar_id, const UNICHARSET &unicharset, GenericVector< UNICHAR_ID > *vec) const
 
virtual EDGE_REF pattern_loop_edge (EDGE_REF edge_ref, UNICHAR_ID unichar_id, bool word_end) const
 

Static Public Attributes

static const int16_t kDawgMagicNumber = 42
 Magic number to determine endianness when reading the Dawg from file. More...
 
static const UNICHAR_ID kPatternUnicharID = 0
 

Protected Member Functions

 Dawg (DawgType type, const STRING &lang, PermuterType perm, int debug_level)
 
NODE_REF next_node_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the next node visited by following this edge. More...
 
bool marker_flag_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the marker flag of this edge. More...
 
int direction_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the direction flag of this edge. More...
 
bool end_of_word_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns true if this edge marks the end of a word. More...
 
UNICHAR_ID unichar_id_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns UNICHAR_ID recorded in this edge. More...
 
void set_next_node_in_edge_rec (EDGE_RECORD *edge_rec, EDGE_REF value)
 Sets the next node link for this edge in the Dawg. More...
 
void set_marker_flag_in_edge_rec (EDGE_RECORD *edge_rec)
 Sets this edge record to be the last one in a sequence of edges. More...
 
int given_greater_than_edge_rec (NODE_REF next_node, bool word_end, UNICHAR_ID unichar_id, const EDGE_RECORD &edge_rec) const
 
bool edge_rec_match (NODE_REF next_node, bool word_end, UNICHAR_ID unichar_id, NODE_REF other_next_node, bool other_word_end, UNICHAR_ID other_unichar_id) const
 
void init (int unicharset_size)
 
bool match_words (WERD_CHOICE *word, int32_t index, NODE_REF node, UNICHAR_ID wildcard) const
 
void iterate_words_rec (const WERD_CHOICE &word_so_far, NODE_REF to_explore, TessCallback1< const WERD_CHOICE *> *cb) const
 

Protected Attributes

DawgType type_
 
STRING lang_
 
PermuterType perm_
 Permuter code that should be used if the word is found in this Dawg. More...
 
int unicharset_size_
 
int flag_start_bit_
 
int next_node_start_bit_
 
uint64_t next_node_mask_
 
uint64_t flags_mask_
 
uint64_t letter_mask_
 
int debug_level_
 

Detailed Description

Abstract class (an interface) that declares methods needed by the various tesseract classes to operate on SquishedDawg and Trie objects.

This class initializes all the edge masks (since their usage by SquishedDawg and Trie is identical) and implements simple accessors for each of the fields encoded in an EDGE_RECORD. This class also implements word_in_dawg() and check_for_words() (since they use only the public methods of SquishedDawg and Trie classes that are inherited from the Dawg base class).

Constructor & Destructor Documentation

◆ ~Dawg()

tesseract::Dawg::~Dawg ( )
virtualdefault

◆ Dawg()

tesseract::Dawg::Dawg ( DawgType  type,
const STRING lang,
PermuterType  perm,
int  debug_level 
)
inlineprotected

Member Function Documentation

◆ check_for_words()

int tesseract::Dawg::check_for_words ( const char *  filename,
const UNICHARSET unicharset,
bool  enable_wildcard 
) const

Checks the Dawg for the words that are listed in the requested file. Returns the number of words in the given file missing from the Dawg.

◆ direction_from_edge_rec()

int tesseract::Dawg::direction_from_edge_rec ( const EDGE_RECORD &  edge_rec) const
inlineprotected

Returns the direction flag of this edge.

◆ edge_char_of()

virtual EDGE_REF tesseract::Dawg::edge_char_of ( NODE_REF  node,
UNICHAR_ID  unichar_id,
bool  word_end 
) const
pure virtual

Returns the edge that corresponds to the letter out of this node.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ edge_letter()

virtual UNICHAR_ID tesseract::Dawg::edge_letter ( EDGE_REF  edge_ref) const
pure virtual

Returns UNICHAR_ID stored in the edge indicated by the given EDGE_REF.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ edge_rec_match()

bool tesseract::Dawg::edge_rec_match ( NODE_REF  next_node,
bool  word_end,
UNICHAR_ID  unichar_id,
NODE_REF  other_next_node,
bool  other_word_end,
UNICHAR_ID  other_unichar_id 
) const
inlineprotected

Returns true if all the values are equal (any value matches next_node if next_node == NO_EDGE, any value matches word_end if word_end is false).

◆ end_of_word()

virtual bool tesseract::Dawg::end_of_word ( EDGE_REF  edge_ref) const
pure virtual

Returns true if the edge indicated by the given EDGE_REF marks the end of a word.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ end_of_word_from_edge_rec()

bool tesseract::Dawg::end_of_word_from_edge_rec ( const EDGE_RECORD &  edge_rec) const
inlineprotected

Returns true if this edge marks the end of a word.

◆ given_greater_than_edge_rec()

int tesseract::Dawg::given_greater_than_edge_rec ( NODE_REF  next_node,
bool  word_end,
UNICHAR_ID  unichar_id,
const EDGE_RECORD &  edge_rec 
) const
inlineprotected

Sequentially compares the given values of unichar ID, next node and word end marker with the values in the given EDGE_RECORD. Returns: 1 if at any step the given input value exceeds that of edge_rec (and all the values already checked are the same) 0 if edge_rec_match() returns true -1 otherwise

◆ init()

void tesseract::Dawg::init ( int  unicharset_size)
protected

Sets unicharset_size_. Initializes the values of various masks from unicharset_size_.

◆ iterate_words() [1/2]

void tesseract::Dawg::iterate_words ( const UNICHARSET unicharset,
TessCallback1< const WERD_CHOICE *> *  cb 
) const

◆ iterate_words() [2/2]

void tesseract::Dawg::iterate_words ( const UNICHARSET unicharset,
TessCallback1< const char *> *  cb 
) const

◆ iterate_words_rec()

void tesseract::Dawg::iterate_words_rec ( const WERD_CHOICE word_so_far,
NODE_REF  to_explore,
TessCallback1< const WERD_CHOICE *> *  cb 
) const
protected

◆ lang()

const STRING& tesseract::Dawg::lang ( ) const
inline

◆ marker_flag_from_edge_rec()

bool tesseract::Dawg::marker_flag_from_edge_rec ( const EDGE_RECORD &  edge_rec) const
inlineprotected

Returns the marker flag of this edge.

◆ match_words()

bool tesseract::Dawg::match_words ( WERD_CHOICE word,
int32_t  index,
NODE_REF  node,
UNICHAR_ID  wildcard 
) const
protected

Matches all of the words that are represented by this string. If wildcard is set to something other than INVALID_UNICHAR_ID, the *'s in this string are interpreted as wildcards. WERD_CHOICE param is not passed by const so that wildcard searches can modify it and work without having to copy WERD_CHOICEs.

◆ next_node()

virtual NODE_REF tesseract::Dawg::next_node ( EDGE_REF  edge_ref) const
pure virtual

Returns the next node visited by following the edge indicated by the given EDGE_REF.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ next_node_from_edge_rec()

NODE_REF tesseract::Dawg::next_node_from_edge_rec ( const EDGE_RECORD &  edge_rec) const
inlineprotected

Returns the next node visited by following this edge.

◆ pattern_loop_edge()

virtual EDGE_REF tesseract::Dawg::pattern_loop_edge ( EDGE_REF  edge_ref,
UNICHAR_ID  unichar_id,
bool  word_end 
) const
inlinevirtual

Returns the given EDGE_REF if the EDGE_RECORD that it points to has a self loop and the given unichar_id matches the unichar_id stored in the EDGE_RECORD, returns NO_EDGE otherwise.

Reimplemented in tesseract::Trie.

◆ permuter()

PermuterType tesseract::Dawg::permuter ( ) const
inline

◆ prefix_in_dawg()

bool tesseract::Dawg::prefix_in_dawg ( const WERD_CHOICE prefix,
bool  requires_complete 
) const

◆ print_node()

virtual void tesseract::Dawg::print_node ( NODE_REF  node,
int  max_num_edges 
) const
pure virtual

Prints the contents of the node indicated by the given NODE_REF. At most max_num_edges will be printed.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ set_marker_flag_in_edge_rec()

void tesseract::Dawg::set_marker_flag_in_edge_rec ( EDGE_RECORD *  edge_rec)
inlineprotected

Sets this edge record to be the last one in a sequence of edges.

◆ set_next_node_in_edge_rec()

void tesseract::Dawg::set_next_node_in_edge_rec ( EDGE_RECORD *  edge_rec,
EDGE_REF  value 
)
inlineprotected

Sets the next node link for this edge in the Dawg.

◆ type()

DawgType tesseract::Dawg::type ( ) const
inline

◆ unichar_id_from_edge_rec()

UNICHAR_ID tesseract::Dawg::unichar_id_from_edge_rec ( const EDGE_RECORD &  edge_rec) const
inlineprotected

Returns UNICHAR_ID recorded in this edge.

◆ unichar_id_to_patterns()

virtual void tesseract::Dawg::unichar_id_to_patterns ( UNICHAR_ID  unichar_id,
const UNICHARSET unicharset,
GenericVector< UNICHAR_ID > *  vec 
) const
inlinevirtual

Fills vec with unichar ids that represent the character classes of the given unichar_id.

Reimplemented in tesseract::Trie.

◆ unichar_ids_of()

virtual void tesseract::Dawg::unichar_ids_of ( NODE_REF  node,
NodeChildVector vec,
bool  word_end 
) const
pure virtual

Fills the given NodeChildVector with all the unichar ids (and the corresponding EDGE_REFs) for which there is an edge out of this node.

Implemented in tesseract::SquishedDawg, and tesseract::Trie.

◆ word_in_dawg()

bool tesseract::Dawg::word_in_dawg ( const WERD_CHOICE word) const

Returns true if the given word is in the Dawg.

Member Data Documentation

◆ debug_level_

int tesseract::Dawg::debug_level_
protected

◆ flag_start_bit_

int tesseract::Dawg::flag_start_bit_
protected

◆ flags_mask_

uint64_t tesseract::Dawg::flags_mask_
protected

◆ kDawgMagicNumber

const int16_t tesseract::Dawg::kDawgMagicNumber = 42
static

Magic number to determine endianness when reading the Dawg from file.

◆ kPatternUnicharID

const UNICHAR_ID tesseract::Dawg::kPatternUnicharID = 0
static

A special unichar id that indicates that any appropriate pattern (e.g.dicitonary word, 0-9 digit, etc) can be inserted instead Used for expressing patterns in punctuation and number Dawgs.

◆ lang_

STRING tesseract::Dawg::lang_
protected

◆ letter_mask_

uint64_t tesseract::Dawg::letter_mask_
protected

◆ next_node_mask_

uint64_t tesseract::Dawg::next_node_mask_
protected

◆ next_node_start_bit_

int tesseract::Dawg::next_node_start_bit_
protected

◆ perm_

PermuterType tesseract::Dawg::perm_
protected

Permuter code that should be used if the word is found in this Dawg.

◆ type_

DawgType tesseract::Dawg::type_
protected

◆ unicharset_size_

int tesseract::Dawg::unicharset_size_
protected

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