10 Replies - 7030 Views - Last Post: 19 January 2010 - 08:17 AM Rate Topic: -----

#1 jpau  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-January 10

How to import english dictionary in C++?

Posted 17 January 2010 - 10:58 PM

can anyone give me advice on how to import english dictionary in C++?
Is This A Good Question/Topic? 0
  • +

Replies To: How to import english dictionary in C++?

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: How to import english dictionary in C++?

Posted 17 January 2010 - 11:35 PM

Please try not to double post.

You could use something like Wordnet, or the dictionary that's in every *nix . I think it's something like /usr/share/dict, but i can't remember

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: How to import english dictionary in C++?

Posted 18 January 2010 - 01:00 AM

import from what, what kind of file, any specifics would be helpful so I can point you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: How to import english dictionary in C++?

Posted 18 January 2010 - 05:59 AM

Like carltech said, the task you've described has little meaning. Please provide to us exactly what you mean by "import English dictionary."
Was This Post Helpful? 0
  • +
  • -

#5 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: How to import english dictionary in C++?

Posted 18 January 2010 - 05:07 PM

This is related to his question so it may help him out. I know I was wanting to make a hangman game but wanted a way to check if the person actually inputed a word by checking against a dictionary database thing. But had no idea how to, and still don't. :P
Was This Post Helpful? 0
  • +
  • -

#6 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: How to import english dictionary in C++?

Posted 18 January 2010 - 05:43 PM

If you just need a list of words then a text file would work fine and you could use ifstream

If you want definitions and synonyms and a complex system of stuff then a database would probably be best. To get to the database you can use DTL(data template library) to make an ODBC(open database connection) and go through your db.

or probably the best way is to use either QT or wxWidgets as I believe both of them have ODBC support.
Was This Post Helpful? 0
  • +
  • -

#7 maybnxtseasn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 04-April 09

Re: How to import english dictionary in C++?

Posted 19 January 2010 - 05:42 AM

import the words into a list which is a resizable list with sorting capabilities.....if it's sorted...u can scan faster with comparing ascii characters

This post has been edited by maybnxtseasn: 19 January 2010 - 05:42 AM

Was This Post Helpful? 0
  • +
  • -

#8 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: How to import english dictionary in C++?

Posted 19 January 2010 - 06:04 AM

or you could just do a search in the file for the word whenever it is entered as input.
Was This Post Helpful? 0
  • +
  • -

#9 maybnxtseasn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 04-April 09

Re: How to import english dictionary in C++?

Posted 19 January 2010 - 06:08 AM

View Postcarltech, on 19 Jan, 2010 - 05:04 AM, said:

or you could just do a search in the file for the word whenever it is entered as input.


carl if you could post an example...im quite new to programming and from what i grasped was that if i wanted to work or compare or find values in a different file i had to first store them in my program as some sort of list! =] thx!
Was This Post Helpful? 0
  • +
  • -

#10 borninlyoko  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 7
  • View blog
  • Posts: 350
  • Joined: 03-December 09

Re: How to import english dictionary in C++?

Posted 19 January 2010 - 06:25 AM

If you want to import the dictionary, you could either have the program refer to Firefox's built in dictionary, which is found usually at the filepath "C:\Program Files (x86)\Mozilla Firefox\dictionaries". Either that or you could have it link to a website such as Dictionary.com
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: How to import english dictionary in C++?

Posted 19 January 2010 - 08:17 AM

You can find many "word lists" online that will form a nice dictionary. You can use an ifstream to read in the text.

Since I am not much in the mood to write an example using a full word list from a file I will use a stringstream rather than an ifstream (but all of the functions will work the same, you just have to change the source stream).


So here is an example of how you might use a word list in-memory
#include<iostream>
#include<set>
#include<string>
#include<cctype>
#include<algorithm>

#include<sstream> //used in main() for example

class WordList {
	typedef std::set<std::string> WordSet;
	WordSet wordSet;
	std::string &toUpperCase(std::string &str) {
		std::transform(str.begin(), str.end(), str.begin(), std::toupper);
		return str;	
	}
	public:
	WordList(std::istream &wordSource) {
		std::string word;
		while(wordSource.good()) {
			wordSource >> word;
			wordSet.insert(toUpperCase(word));
		}
	}
	
	bool insertWord(std::string word) {
		return (wordSet.insert(toUpperCase(word))).second;
	}
	
	bool isInWordList(std::string word) {
		return wordSet.find(toUpperCase(word))!=wordSet.end();
	}
};

using namespace std;

int main() {
	//words taken from SAT word list: http://www.majortests.com/sat/wordlist-16
	string aListOfWords =   "Accolade Allusion Ambivalence Ambivalent Analogy Anecdote Anomalous Apparition Aspersion Belligerence Bombastic\n"
							"Candid Capricious Cherished Cliche Conception Convoluted Credence Cryptic Currency Decorous Denunciation Derailed\n"
							"Derivative Despotic Detritus Diaphanous Dictum Dilettante Disdained Dispassionate Dowager Dubious Egalitarian Elicit\n"
							"Elliptical Epitomizes Equivocate Evasiveness Explicitly Foraging Hypothetical Iconoclast Idiosyncratic Imponderable\n"
							"Indecorous Indigence Inept Inherent Intricate Irrefutable Jingoism Jubilant Judicious Lament Loquacious Mendicancy\n"
							"Metaphorical Milieu Mitigated Nascent Nostalgia Obtrusive Orthographical Ossified Ostentatious Palpable Pastoral\n"
							"Pedestrian Perfidy Profligacy Prohibitive Prudence Pugnacious Purveyor Resonance Respite Resurgence Sparse\n"
							"Stringent Succumbing Supercilious Tenacity Transcend Variegated Venerable Viable Visceral";
	istringstream issWords(aListOfWords,istringstream::in); 
	WordList words(issWords); // here you would just insert the file stream rather than an input stream...
	string userWord;
	cout << "Please enter a word: ";
	cin >> userWord;
	if (words.isInWordList(userWord)) {
		cout << "You got a word" << endl;
	} else {
		cout << "No such word in my list!" << endl;
	}
	return 0;
}



Note however that if you are dealing with a LARGE wordlist, then you may want to use a technique where you keep the list of words in the file rather than in memory. TO do that you will want to have a file format that allows you to quickly find words. (sorted list or a search tree).

If you wanted to make this a real dictionary then you would use a std::map rather than a std::set.

**edit: I noticed that my word list was faulty (the regex I used to extract the words was cutting off the last letter) so I corrected the word list.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1