Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

C++ Dictionary

I'm looking for a C++ dictionary. I have some character strings and first I need to use a dictionary to see if it is a word and not random characters thrown together. Secondly, if it is a word, I need to check if it falls in one of the categories I have specified, such as travel, sports, etc. Does anyone knows if such a code or libarary exists somewhere?
[361 byte] By [ayousuf] at [2007-11-11 8:51:03]
# 1 Re: C++ Dictionary
A relatively easy way to implement a dictionary is by using a hashtable. you could use structs which contain the category, or other grouping, of the word, with the word itself. The STL includes a hash_map which you can use [map, since you want entries to be unique]. There are word lists you can download to populate your dictionary or, if needed, you can create that list yourself.
nspils at 2007-11-11 21:00:59 >
# 2 Re: C++ Dictionary
simply implement it as a hash map provided by the STL in C++.
I guess you would be having a data structure like:

map< string, string > dictMap;
where the key of the map would be the dictionary word, and the value of that would be the category.

Now for a given word and its category you look up the hashmap for a match of the word and if there is a match, then check its corresponding value for the category.

Regards,
Tapajyoti
tdas at 2007-11-11 21:01:59 >
# 3 Re: C++ Dictionary
The general idea, as others have pointed, is using an associative container such as map. Notice however that STL doesn't officially have hashed containers yet so you want to stick to map<string, string> instead of hashed_map or unordered_map.
However, instead of creating pairs of strings, perhaps you want to do something more sohpisticated: create a class called Word that represents a dictionary entry which includes a string (the word itself), its category and perhaps additional tags that may be later required. Then create a map <string, Word> that represents your dictionary.
Danny at 2007-11-11 21:03:03 >