Tesseract 3.01
tesseract::Dawg Class Reference

#include <dawg.h>

Inheritance diagram for tesseract::Dawg:
tesseract::SquishedDawg tesseract::Trie

List of all members.

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.
int check_for_words (const char *filename, const UNICHARSET &unicharset, bool enable_wildcard) 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.
virtual void unichar_ids_of (NODE_REF node, NodeChildVector *vec) 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.
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 kDawgMagicNumber = 42
 Magic number to determine endianness when reading the Dawg from file.
static const UNICHAR_ID kPatternUnicharID = 0

Protected Member Functions

 Dawg ()
NODE_REF next_node_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the next node visited by following this edge.
bool marker_flag_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the marker flag of this edge.
int direction_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns the direction flag of this edge.
bool end_of_word_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns true if this edge marks the end of a word.
UNICHAR_ID unichar_id_from_edge_rec (const EDGE_RECORD &edge_rec) const
 Returns UNICHAR_ID recorded in this edge.
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.
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.
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 (DawgType type, const STRING &lang, PermuterType perm, int unicharset_size, int debug_level)
bool match_words (WERD_CHOICE *word, inT32 index, NODE_REF node, UNICHAR_ID wildcard) const

Protected Attributes

DawgType type_
STRING lang_
PermuterType perm_
 Permuter code that should be used if the word is found in this Dawg.
int unicharset_size_
int flag_start_bit_
int next_node_start_bit_
uinT64 next_node_mask_
uinT64 flags_mask_
uinT64 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

virtual tesseract::Dawg::~Dawg ( ) [inline, virtual]
tesseract::Dawg::Dawg ( ) [inline, protected]

Member Function Documentation

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.

int tesseract::Dawg::direction_from_edge_rec ( const EDGE_RECORD edge_rec) const [inline, protected]

Returns the direction flag of this edge.

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.

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.

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 [inline, protected]

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).

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.

bool tesseract::Dawg::end_of_word_from_edge_rec ( const EDGE_RECORD edge_rec) const [inline, protected]

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

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 [inline, protected]

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

void tesseract::Dawg::init ( DawgType  type,
const STRING lang,
PermuterType  perm,
int  unicharset_size,
int  debug_level 
) [protected]

Sets type_, lang_, perm_, unicharset_size_. Initializes the values of various masks from unicharset_size_.

const STRING& tesseract::Dawg::lang ( ) const [inline]
bool tesseract::Dawg::marker_flag_from_edge_rec ( const EDGE_RECORD edge_rec) const [inline, protected]

Returns the marker flag of this edge.

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

Matches all of the words that are represented by this string. If wilcard 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.

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.

NODE_REF tesseract::Dawg::next_node_from_edge_rec ( const EDGE_RECORD edge_rec) const [inline, protected]

Returns the next node visited by following this edge.

virtual EDGE_REF tesseract::Dawg::pattern_loop_edge ( EDGE_REF  edge_ref,
UNICHAR_ID  unichar_id,
bool  word_end 
) const [inline, virtual]

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.

PermuterType tesseract::Dawg::permuter ( ) const [inline]
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.

void tesseract::Dawg::set_marker_flag_in_edge_rec ( EDGE_RECORD edge_rec) [inline, protected]

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

void tesseract::Dawg::set_next_node_in_edge_rec ( EDGE_RECORD edge_rec,
EDGE_REF  value 
) [inline, protected]

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

DawgType tesseract::Dawg::type ( ) const [inline]
UNICHAR_ID tesseract::Dawg::unichar_id_from_edge_rec ( const EDGE_RECORD edge_rec) const [inline, protected]

Returns UNICHAR_ID recorded in this edge.

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

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

Reimplemented in tesseract::Trie.

virtual void tesseract::Dawg::unichar_ids_of ( NODE_REF  node,
NodeChildVector vec 
) 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.

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

Returns true if the given word is in the Dawg.


Member Data Documentation

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

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.

PermuterType tesseract::Dawg::perm_ [protected]

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


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines