Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hint:you have to pack (or typecast) the key and the item into a pair in order to put it into, or remove it from, a

Hint:you have to pack (or typecast) the "key" and the "item" into a "pair" in order to put it into, or remove it from, a map or multimap. A "pair" is like a struct with fields: "first" and "second" which refer to the "key" and "item" respectively.

Aim: This assignment is to familiarise you with the use of STL container classes in your programs. On completion you should know how to: Write C++ code using STL container class objects. Devise programs requiring data manipulation with STL containers. Gain experience writing and debugging complex C++ programs incrementally. Prerequisites: Before you undertake this assignment please review the week 8 lecture notes on the Standard Template Library (STL). Also, download and study the week 7&8 STL example programs in the Examples folder. The following links may also prove useful for learning STL containers: http://www.cplusplus.com/reference/stl/ http://www.cprogramming.com/tutorial/stl/stlintro.html http://www.sgi.com/tech/stl/stl_introduction.html If you are unsure on how to do something with STL, try looking at the examples or google STL together with set or map or multi-map etc. Requirements: For this assignment you are to implement a C++ program that can read a text file and display any known words on the screen together with their frequency and position in the file. Below shows a snippet of what the output should look like: Word Count Position(s) a 7 22 65 87 96 130 148 165 all 1 50 and 9 19 70 125 134 138 157 177 247 261 are 1 74 as 2 169 214 automata 1 73 be 1 99 begin 1 106 between 1 132 cell 5 97 131 156 180 238 cellular 1 72 create 1 143 cursor 2 119 124 eight 1 171 every 2 155 237 first 2 20 110 A known word is a word that is in the English dictionary which is defined by the words listed in the file named dictionary.txt. The word Positions are determined by all the places where each word occurs in the data file. For example, in the above screen output, the word first occurred twice, at the 20th and 110th word position in the test data file. A partially completed WordStat class is provided in wordstat.h and wordstat.cpp. A driver program is also provided in main.cpp. The file: output.txt shows the output your completed program should produce when run with redirected input from input.txt. You should do this assignment incrementally by completing the following steps. 2 Step 1 (2 mark) Implement the ReadDictionary() and DisplayDictionary() public member function in the wordstats class in wordstat.h & wordstat.cpp. ReadDictionary should open dictionary.txt and read all the words (in lower case format) into the private Dictionary member: set Dictionary; If you are unsure on using the STL set container, take a look at 08-set.cpp in the examples folder. DisplayDictionary() should display the first 20 words in the Dictionary on the screen. The screenshot below shows an example output of reading and displaying the dictionary. Step-1 Reading and displaying dictionary 25127 words read from dictionary. Displaying the first 20 words in the dictionary... aarhus aaron ababa aback abacus ... abbot abbott abbreviate abc abdicate abdomen Step 2 (2 mark) Implement the ReadTextFile() public member function. This function should read the contents of the file named: testdata.txt into the KnownWords and UnknownWords data members of the WordStats class: WordMap KnownWords; WordMap UnknownWords; Please note that WordMap is typedefed in wordstat.h as: typedef map > WordMap; Only known words should be put in the KnownWords WordMap. A known word is any word that is found in the Dictionary class member. Before attempting to find a word in the Dictionary, you should first preprocess the word by converting all characters to lower case and remove any non-alphabetic characters except for the punctuation marks: hyphen (-) and apostrophe (). You can add additional private member functions to class WordStats if you wish. Your output from step-2 should look something like this: Step-2 Reading known wrods from text file: 89 known words read. 49 unknown words read. If you are unsure on working with map containers, an example is provided in 08-map.cpp in the example folder. 3 Step 3 (1 mark) Implement the DisplayKnownWordStats(); public member function. This function should iterate the KnownWords WordMap and display the word stats on the screen as shown on page 1. If you are unsure on how to do this with a map look at 08-map.cpp in the example folder. Step 4 (1 mark) Implement the DisplayUnknownWordStats() public member function. This function should display the unknown words in the same format as step-3. Note: try to avoid duplicating code for this by declaring an additional private member function that is passed a WordMap by reference and called by both the display functions from step-3 and step-4. Step 5 (1 marks) Implement the DisplayMostFreqKnownWords() public member function. This function should display the 10 most frequently occurring words in the KnownWords container. E.g. Step-5 Displaying most frequent known words: Word Count the 21 live 10 of 9 and 9 or 7 in 7 a 7 to 6 is 6 cell 5 To do this declare a local multimap; container. You will need to iterate the KnownWords container and insert the size of the vector (as the key) and the word into the local multimap. This multimap can then be iterated to display the 10 most frequent words on the screen. Step 6 (1 mark) Implement the DisplayMostFreqUnknownWords() public member function to display the 10 most frequently occurring words in the UnknownWords container. Again, try to avoid duplicate code by adding another private member function called by the display functions from setp-5 and 6. Step 7 (2 marks) Implement the DisplayOriginalText() public member function. To do this declare a local map; container and do the same as you did with Step 6, except you should also iterate the vectors in the KnownWords and UnknownWords containers and add the pair for all words and their positions. This will sort the words into their original text order based on the word position numbers. The screen output should look something like below. the game of life written by ian sharpe the game of life was invented by the mathematician john conway and first reached a wide public when it was written up in scientific american in 1970 or thereabouts in those days it was mostly played on squared paper nowadays computers take all the hard work out of this fascinating invention to some it's nothing more than a toy to others it and related cellular automata are subjects for serious study in this implementation the screen is divided into a grid of cells 40 wide by 24 deep a cell may be live (red or dead (white) you begin by creating the first generation of live cells or seed . . .

/*************************************************************************** * main.cpp * ***************************************************************************/ #include #include "wordstats.h" using namespace std;

int main(){ WordStats ws; cout << "Begin Text File Analyser Tests ";

cout << "Step-1 Reading and displaying dictionary "; ws.ReadDictionary(); ws.DisplayDictionary();

cout << "Step-2 Reading words from text file "; ws.ReadTxtFile();

cout << "Step-3 Displaying known words: "; ws.DisplayKnownWordStats();

cout << "Step-4 Displaying unknown words: "; ws.DisplayUnknownWordStats();

cout << "Step-5 Displaying most frequent known words "; ws.DisplayMostFreqKnownWords();

cout << "Step-6 Displaying most frequent unknown words "; ws.DisplayMostFreqUnknownWords();

cout << "Step-7 Displaying original text "; ws.DisplayOriginalText();

cout << " End Text File Analyser Tests ";

return 0; }

/********************************************************************** * wordstats.cpp * **********************************************************************/ #include #include #include #include #include #include "wordstats.h" using namespace std;

WordStats::WordStats(){ strcpy(Filename,"testdata.txt"); }

// Reads dictionary.txt into Dictionary void WordStats::ReadDictionary(){ }

// Displays Dictwords 10 at a time void WordStats::DisplayDictionary(){ }

// Reads textfile into KnownWords and UnknownWords void WordStats::ReadTxtFile(){ }

// Displays stats of words in KnownWords void WordStats::DisplayKnownWordStats(){ }

// Displays stats of words in Unknownwords void WordStats::DisplayUnknownWordStats(){ }

// Displays 20 most frequent words in KnownWords void WordStats::DisplayMostFreqKnownWords(){ }

// Displays 20 most frequent words in UnknownWords void WordStats::DisplayMostFreqUnknownWords(){ }

// Displays original text from KnownWords & UnknownWords void WordStats::DisplayOriginalText(){ }

// ============ Private Fns ========================

// add your private fns here...

/********************************************************************** * wordstats.h * **********************************************************************/ #ifndef WORDSTATS_H_ #define WORDSTATS_H_

#include #include #include #include #include using namespace std;

// Definition of data contained in BinaryTree

typedef map > WordMap; typedef WordMap::iterator WordMapIter;

class WordStats { public: WordStats(); void ReadDictionary(); void DisplayDictionary(); void ReadTxtFile(); void DisplayKnownWordStats(); void DisplayUnknownWordStats(); void DisplayMostFreqKnownWords(); void DisplayMostFreqUnknownWords(); void DisplayOriginalText(); private: WordMap KnownWords; WordMap UnknownWords; set Dictionary; char Filename[256]; //add your private fns here };

#endif

testdata.txt

- Artificial Neural Networks -

Artificial neural networks (ANNs) or connectionist systems are computing systems vaguely inspired by the biological neural networks that constitute animal brains.[1] Such systems "learn" (i.e. progressively improve performance on) tasks by considering examples, generally without task-specific programming. For example, in image recognition, they might learn to identify images that contain cats by analyzing example images that have been manually labeled as "cat" or "no cat" and using the results to identify cats in other images. They do this without any a priori knowledge about cats, e.g., that they have fur, tails, whiskers and cat-like faces. Instead, they evolve their own set of relevant characteristics from the learning material that they process.

An ANN is based on a collection of connected units or nodes called artificial neurons (a simplified version of biological neurons in an animal brain). Each connection (a simplified version of a synapse) between artificial neurons can transmit a signal from one to another. The artificial neuron that receives the signal can process it and then signal artificial neurons connected to it.

In common ANN implementations, the signal at a connection between artificial neurons is a real number, and the output of each artificial neuron is calculated by a non-linear function of the sum of its inputs. Artificial neurons and connections typically have a weight that adjusts as learning proceeds. The weight increases or decreases the strength of the signal at a connection. Artificial neurons may have a threshold such that only if the aggregate signal crosses that threshold is the signal sent. Typically, artificial neurons are organized in layers. Different layers may perform different kinds of transformations on their inputs. Signals travel from the first (input), to the last (output) layer, possibly after traversing the layers multiple times.

The original goal of the ANN approach was to solve problems in the same way that a human brain would. However, over time, attention focused on matching specific tasks, leading to deviations from biology. ANNs have been used on a variety of tasks, including computer vision, speech recognition, machine translation, social network filtering, playing board and video games and medical diagnosis.

output.txt

Begin Text File Analyser Tests

Step-1 Reading and displaying dictionary 25089 words in dictionary.

a a&m a&p a's aarhus aaron ababa aback abacus abalone abandon abase abash abate abater abbas abbe abbey abbot abbott

Step-2 Reading words from text file 110 known words read. 78 unknown words read.

Step-3 Displaying known words: Word Count Position(s) a 14 83 119 129 141 145 152 183 189 202 217 235 241 309 332 about 1 86 aggregate 1 248 an 2 114 136 and 7 68 95 168 192 213 348 351 animal 2 22 137 ann 3 115 178 298 another 1 157 any 1 82 approach 1 299 are 2 10 260 artificial 11 0 3 127 148 159 171 186 197 211 237 258 as 2 63 221 at 2 182 234 attention 1 316 been 2 60 329 between 2 147 185 biology 1 326 board 1 347 brain 2 138 311 by 4 15 33 54 201 can 2 150 165 cat 2 64 67 common 1 177 constitute 1 21 contain 1 52 diagnosis 1 353 different 2 264 268 do 1 79 each 2 139 196 evolve 1 100 example 2 41 56 first 1 279 for 1 40 from 4 107 154 277 325 function 1 204 fur 1 92 goal 1 295 have 5 59 91 216 240 328 however 1 313 human 1 310 identify 2 49 73 if 1 246 image 1 43 improve 1 29 in 6 42 75 135 176 262 304 input 1 280 instead 1 98 is 4 116 188 199 253 it 2 167 175 knowledge 1 85 last 1 283 learn 2 26 47 machine 1 341 material 1 110 may 2 239 266 might 1 46 multiple 1 291 network 1 344 neural 3 1 4 18 neuron 2 160 198 no 1 66 of 11 104 121 132 144 195 205 208 231 270 296 334 on 5 31 118 272 318 331 one 1 155 only 1 245 or 4 7 65 124 227 original 1 294 other 1 76 over 1 314 own 1 102 perform 1 267 performance 1 30 priori 1 84 process 2 113 166 programming 1 39 real 1 190 relevant 1 105 same 1 306 sent 1 256 set 1 103 signal 7 153 164 170 181 233 249 255 social 1 343 solve 1 302 specific 1 320 speech 1 339 strength 1 230 such 2 24 243 sum 1 207 synapse 1 146 that 10 20 51 58 89 111 161 219 244 251 308 the 19 16 70 108 158 163 180 193 206 224 229 232 247 254 278 282 289 293 297 305 their 2 101 273 then 1 169 they 5 45 78 90 99 112 this 1 80 threshold 2 242 252 time 1 315 to 7 48 72 156 174 281 301 323 transmit 1 151 travel 1 276 variety 1 333 version 2 131 143 video 1 349 vision 1 338 was 1 300 way 1 307 weight 2 218 225 without 2 37 81 would 1 312

Step-4 Displaying unknown words: Word Count Position(s) adjusts 1 220 after 1 287 analyzing 1 55 anns 2 6 327 based 1 117 biological 2 17 133 brains 1 23 calculated 1 200 called 1 126 cat-like 1 96 cats 3 53 74 87 characteristics 1 106 collection 1 120 computer 1 337 computing 1 11 connected 2 122 173 connection 3 140 184 236 connectionist 1 8 connections 1 214 considering 1 34 crosses 1 250 decreases 1 228 deviations 1 324 eg 1 88 examples 1 35 faces 1 97 filtering 1 345 focused 1 317 games 1 350 generally 1 36 ie 1 27 images 3 50 57 77 implementations 1 179 including 1 336 increases 1 226 inputs 2 210 274 inspired 1 14 its 1 209 kinds 1 269 labeled 1 62 layer 1 285 layers 3 263 265 290 leading 1 322 learning 2 109 222 manually 1 61 matching 1 319 medical 1 352 networks 3 2 5 19 neurons 8 128 134 149 172 187 212 238 259 nodes 1 125 non-linear 1 203 number 1 191 organized 1 261 output 2 194 284 playing 1 346 possibly 1 286 problems 1 303 proceeds 1 223 progressively 1 28 receives 1 162 recognition 2 44 340 results 1 71 signals 1 275 simplified 2 130 142 systems 3 9 12 25 tails 1 93 task-specific 1 38 tasks 3 32 321 335 times 1 292 transformations 1 271 translation 1 342 traversing 1 288 typically 2 215 257 units 1 123 used 1 330 using 1 69 vaguely 1 13 whiskers 1 94

Step-5 Displaying most frequent known words Word Count the 19 a 14 of 11 artificial 11 that 10 to 7 signal 7 and 7 in 6 they 5

Step-6 Displaying most frequent unknown words Word Count neurons 8 tasks 3 systems 3 networks 3 layers 3 images 3 connection 3 cats 3 typically 2 simplified 2

Step-7 Displaying original text

artificial neural networks artificial neural networks anns or connectionist systems are computing systems vaguely inspired by the biological neural networks that constitute animal brains such systems learn ie progressively improve performance on tasks by considering examples generally without task-specific programming for example in image recognition they might learn to identify images that contain cats by analyzing example images that have been manually labeled as cat or no cat and using the results to identify cats in other images they do this without any a priori knowledge about cats eg that they have fur tails whiskers and cat-like faces instead they evolve their own set of relevant characteristics from the learning material that they process an ann is based on a collection of connected units or nodes called artificial neurons a simplified version of biological neurons in an animal brain each connection a simplified version of a synapse between artificial neurons can transmit a signal from one to another the artificial neuron that receives the signal can process it and then signal artificial neurons connected to it in common ann implementations the signal at a connection between artificial neurons is a real number and the output of each artificial neuron is calculated by a non-linear function of the sum of its inputs artificial neurons and connections typically have a weight that adjusts as learning proceeds the weight increases or decreases the strength of the signal at a connection artificial neurons may have a threshold such that only if the aggregate signal crosses that threshold is the signal sent typically artificial neurons are organized in layers different layers may perform different kinds of transformations on their inputs signals travel from the first input to the last output layer possibly after traversing the layers multiple times the original goal of the ann approach was to solve problems in the same way that a human brain would however over time attention focused on matching specific tasks leading to deviations from biology anns have been used on a variety of tasks including computer vision speech recognition machine translation social network filtering playing board and video games and medical diagnosis

End Text File Analyser Tests

-------------------------------- Process exited after 0.6149 seconds with return value 0 Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5 How banks create money in a fractional reserve banking system.

Answered: 1 week ago