Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C

Using Ternary DAGs for Spelling Correction

Rate me:
Please Sign up or sign in to vote.
4.97/5 (32 votes)
10 Jan 2009Zlib9 min read 57.6K   739   52  
A new data structure for spellchecking and spelling correction
// Ternary DAG spellchecker
// (c) Peter Kankowski, 2008. kankowski@narod.ru

#pragma pack(push)
#pragma pack(1)

// Dictionary node stored in file
struct ST_FILE_NODE {
	char ch;
	char _padding;
	unsigned short left;
	unsigned short right;
	unsigned short middle;
};
typedef struct ST_FILE_NODE ST_FILE_NODE;
#pragma pack(pop)

#define ST_DICT_SIGNATURE "Aba dict"
#define ST_MAX_WORD 100

// Open a dictionary, returns NULL in case of error
ST_FILE_NODE * ST_open_dict (const char * filename);

// Returns a non-zero value if the word is present in the dictionary
int ST_find_exact (ST_FILE_NODE * dict, const char * word);

// Enumerate spelling suggestions (fuzzy matches)
void ST_enum_suggestions (ST_FILE_NODE * dict, const char * word,
						  void (* enumproc)(const char*, void*), void * param);

// Close the dictionary
void ST_close_dict (ST_FILE_NODE * dict);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Software Developer
Czech Republic Czech Republic
Peter is the developer of Aba Search and Replace, a tool for replacing text in multiple files. He likes to program in C with a bit of C++, also in x86 assembly language, Python, and PHP.

Comments and Discussions