41 #define NO_EDGE (inT64) 0xffffffffffffffffi64 44 #define NO_EDGE (inT64) 0xffffffffffffffffll 84 #define FORWARD_EDGE (inT32) 0 85 #define BACKWARD_EDGE (inT32) 1 86 #define MAX_NODE_EDGES_DISPLAY (inT64) 100 87 #define MARKER_FLAG (inT64) 1 88 #define DIRECTION_FLAG (inT64) 2 89 #define WERD_END_FLAG (inT64) 4 90 #define LETTER_START_BIT 0 91 #define NUM_FLAG_BITS 3 92 #define REFFORMAT "%lld" 101 static const char kWildcard[] =
"*";
144 bool enable_wildcard)
const;
160 bool word_end)
const = 0;
165 bool word_end)
const = 0;
253 curr_word_end, curr_unichar_id))
return 0;
254 if (unichar_id > curr_unichar_id)
return 1;
255 if (unichar_id == curr_unichar_id) {
256 if (
next_node > curr_next_node)
return 1;
258 if (word_end > curr_word_end)
return 1;
272 return ((unichar_id == other_unichar_id) &&
274 (!word_end || (word_end == other_word_end)));
280 PermuterType perm,
int unicharset_size,
int debug_level);
386 const char *debug_msg) {
388 if (
data_[i] == new_pos)
return false;
412 read_squished_dawg(file,
type,
lang, perm, debug_level);
413 num_forward_edges_in_node0 = num_forward_edges(0);
422 read_squished_dawg(file,
type,
lang, perm, debug_level);
423 num_forward_edges_in_node0 = num_forward_edges(0);
428 int unicharset_size,
int debug_level) :
429 edges_(edges), num_edges_(num_edges) {
431 num_forward_edges_in_node0 = num_forward_edges(0);
432 if (debug_level > 3) print_all(
"SquishedDawg:");
440 bool word_end)
const;
445 bool word_end)
const {
447 if (!edge_occupied(edge) || edge == NO_EDGE)
return;
448 assert(forward_edge(edge));
453 }
while (!last_edge(edge++));
498 inline void set_empty_edge(
EDGE_REF edge_ref) {
502 inline void clear_all_edges() {
503 for (
int edge = 0; edge < num_edges_; edge++) set_empty_edge(edge);
506 inline void clear_marker_flag(
EDGE_REF edge_ref) {
510 inline bool forward_edge(
EDGE_REF edge_ref)
const {
511 return (edge_occupied(edge_ref) &&
515 inline bool backward_edge(
EDGE_REF edge_ref)
const {
516 return (edge_occupied(edge_ref) &&
520 inline bool edge_occupied(
EDGE_REF edge_ref)
const {
524 inline bool last_edge(
EDGE_REF edge_ref)
const {
536 void print_edge(
EDGE_REF edge)
const;
539 void print_all(
const char* msg) {
540 tprintf(
"\n__________________________\n%s\n", msg);
541 for (
int i = 0; i < num_edges_; ++i) print_edge(i);
542 tprintf(
"__________________________\n");
551 int num_forward_edges_in_node0;
556 #endif // DICT_DAWG_H_
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.
virtual EDGE_REF pattern_loop_edge(EDGE_REF edge_ref, UNICHAR_ID unichar_id, bool word_end) const
bool prefix_in_dawg(const WERD_CHOICE &prefix, bool requires_complete) const
static const UNICHAR_ID kPatternUnicharID
bool marker_flag_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the marker flag of this edge.
virtual void print_node(NODE_REF node, int max_num_edges) const =0
bool operator==(const DawgPosition &other)
void write_squished_dawg(const char *filename)
EDGE_REF edge_char_of(NODE_REF node, UNICHAR_ID unichar_id, bool word_end) const
Returns the edge that corresponds to the letter out of this node.
NODE_REF next_node(EDGE_REF edge) const
DawgPosition(int dawg_idx, EDGE_REF dawgref, int punc_idx, EDGE_REF puncref, bool backtopunc)
virtual bool end_of_word(EDGE_REF edge_ref) const =0
void write_squished_dawg(FILE *file)
Writes the squished/reduced Dawg to a file.
void print_node(NODE_REF node, int max_num_edges) const
static const inT16 kDawgMagicNumber
Magic number to determine endianness when reading the Dawg from file.
bool match_words(WERD_CHOICE *word, inT32 index, NODE_REF node, UNICHAR_ID wildcard) const
int given_greater_than_edge_rec(NODE_REF next_node, bool word_end, UNICHAR_ID unichar_id, const EDGE_RECORD &edge_rec) const
PermuterType perm_
Permuter code that should be used if the word is found in this Dawg.
int push_back(DawgPosition object)
SquishedDawg(const char *filename, DawgType type, const STRING &lang, PermuterType perm, int debug_level)
int direction_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the direction flag of this edge.
UNICHAR_ID edge_letter(EDGE_REF edge_ref) const
Returns UNICHAR_ID stored in the edge indicated by the given EDGE_REF.
int check_for_words(const char *filename, const UNICHARSET &unicharset, bool enable_wildcard) const
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.
virtual UNICHAR_ID edge_letter(EDGE_REF edge_ref) const =0
Returns UNICHAR_ID stored in the edge indicated by the given EDGE_REF.
void iterate_words(const UNICHARSET &unicharset, TessCallback1< const WERD_CHOICE *> *cb) const
virtual void unichar_id_to_patterns(UNICHAR_ID unichar_id, const UNICHARSET &unicharset, GenericVector< UNICHAR_ID > *vec) const
unsigned long long int uinT64
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.
PermuterType permuter() const
virtual NODE_REF next_node(EDGE_REF edge_ref) const =0
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.
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
bool end_of_word(EDGE_REF edge_ref) const
SquishedDawg(EDGE_ARRAY edges, int num_edges, DawgType type, const STRING &lang, PermuterType perm, int unicharset_size, int debug_level)
GenericVector< SuccessorList * > SuccessorListsVector
bool add_unique(const DawgPosition &new_pos, bool debug, const char *debug_msg)
GenericVector< NodeChild > NodeChildVector
NODE_REF next_node_from_edge_rec(const EDGE_RECORD &edge_rec) const
Returns the next node visited by following this edge.
bool word_in_dawg(const WERD_CHOICE &word) const
Returns true if the given word is in the Dawg.
void iterate_words_rec(const WERD_CHOICE &word_so_far, NODE_REF to_explore, TessCallback1< const WERD_CHOICE *> *cb) const
void unichar_ids_of(NODE_REF node, NodeChildVector *vec, bool word_end) const
virtual void unichar_ids_of(NODE_REF node, NodeChildVector *vec, bool word_end) const =0
void init(DawgType type, const STRING &lang, PermuterType perm, int unicharset_size, int debug_level)
const STRING & lang() const
SquishedDawg(FILE *file, DawgType type, const STRING &lang, PermuterType perm, int debug_level)
NodeChild(UNICHAR_ID id, EDGE_REF ref)
GenericVector< int > SuccessorList