rendered paste body// /*--------------------------------------------------------*\// | Main Program: Tag_Cloud_Generator// |*--------------------------------------------------------*|// | Date: 2009 June 02// | Author: Michael Kusold & Marko Skugor// |// | Brief User's Manual:// | Allows the user to create a html tag cloud with // | input done by redirection.// |// \*--------------------------------------------------------*////-------------------------------------------------------------/// Global Context ---------------------------------------------///-------------------------------------------------------------#include "RESOLVE_Foundation.h"#include "CT/Word_Occurrence/Kernel.h"#include "CT/Sorting_Machine/Kernel_3_C.h"#include "CI/Text/Are_In_Order_1.h"///-------------------------------------------------------------/// Instantiations ---------------------------------------------///-------------------------------------------------------------concrete_instanceclass Word_Occurrence_Map : instantiates Word_Occurrence_Kernel <Text>{};//--------------------------------------------------------------concrete_instanceclass Word_Occur_Rec : instantiates Record < Text, Integer >{};field_name (Word_Occur_Rec, 0, Text, word);field_name (Word_Occur_Rec, 1, Integer, count);///-------------------------------------------------------------/// Utility Classes - ------------------------------------------///-------------------------------------------------------------concrete_instanceutility_class Word_Text_Are_In_Order_1 : implements abstract_instance General_Are_In_Order <Word_Occur_Rec>{public: /*! math definition ARE_IN_ORDER ( x: string of character, y: string of character ): boolean is x <= y !*/ utility_function_body Boolean Are_In_Order ( preserves Word_Occur_Rec& x, preserves Word_Occur_Rec& y ) { return (x[word] <= y[word]); };};//--------------------------------------------------------------concrete_instanceutility_class Word_Count_Are_In_Order_1 : implements abstract_instance General_Are_In_Order <Word_Occur_Rec>{public: /*! math definition ARE_IN_ORDER ( x: string of character, y: string of character ): boolean is x <= y !*/ utility_function_body Boolean Are_In_Order ( preserves Word_Occur_Rec& x, preserves Word_Occur_Rec& y ) { return (x[count] <= y[count]); };};//--------------------------------------------------------------concrete_instanceclass Sorting_Machine_Text : instantiates Sorting_Machine_Kernel_3_C < Word_Occur_Rec, Word_Text_Are_In_Order_1 >{};//--------------------------------------------------------------concrete_instanceclass Sorting_Machine_Count : instantiates Sorting_Machine_Kernel_3_C < Word_Occur_Rec, Word_Count_Are_In_Order_1 >{};///-------------------------------------------------------------/// Global operations ------------------------------------------///-------------------------------------------------------------// global_procedure Get_Line (// preserves Character_IStream& input,// produces Text line// );// global_procedure Get_Word (// alters Text& line,// produces Text word// ); global_procedure Get_Next_Word ( alters Character_IStream& ins, produces Text word ); global_procedure Remove_Non_White ( alters Text& line ); global_function Boolean Is_Common_Word ( preserves Text& word );///-------------------------------------------------------------/// Global operation bodies ------------------------------------///-------------------------------------------------------------// procedure_body Get_Line (// preserves Character_IStream& input,// produces Text line// )// {// object Boolean end = false;// while(end == false)// {// object Character ch; // input.Remove(0,ch);// if(ch=='\n')// {// end = true;// }// else// {// line.Add(line.Length(), ch);// } // }// }// procedure_body Get_Word (// alters Text& line,// produces Text word// )// {// object Boolean end = false; // while(end == false)// {// object Character ch; // line.Remove(0,ch);// if(ch=='\n' || ch=='\t' || ch == ' ')// {// end = true;// Remove_Non_White(line);// }// else// {// To_Lower(ch);// word.Add(word.Length(),ch);// }// }// }global_procedure_body Get_Next_Word ( alters Character_IStream& ins, produces Text& word ){ object Boolean done, in_word; word.Clear (); // make sure word starts empty while (not ins.At_EOS () and not done) { object Character ch; ins.Read (ch); // input one character at a time if (Is_Alpha (ch)) // ch is a letter { in_word = true; // we are now inside a word word.Add (word.Length (), ch); } else // ch is not a letter { if (in_word) // we were inside a word, so we must be done { done = true; } } }}// procedure_body Remove_Non_White (// alters Text& line// )// {// object Boolean end = false; // while(end==false)// {// object Character ch;// line.Remove(0,ch); // if(ch=='\n' && ch=='\t' && ch==' ')// {// }// else// {// line.Add(0,ch);// end = true;// }// }// } function_body Boolean Is_Common_Word ( preserves Text& word ){ object Boolean answer = false; object Text word_copy = word; if(word =="a") { answer = true; } else if(word =="and") { answer = true; } else if(word == "all") { answer = true; } else if(word == "am") { answer = true; } else if(word == "an") { answer = true; } else if(word == "and") { answer = true; } else if(word == "any") { answer = true; } else if(word == "are") { answer = true; } else if(word == "as") { answer = true; } else if(word == "at") { answer = true; } else if(word == "be") { answer = true; } else if(word == "been") { answer = true; } else if(word == "but") { answer = true; } else if(word == "by") { answer = true; } else if(word == "can") { answer = true; } else if(word == "do") { answer = true; } else if(word == "for") { answer = true; } else if(word == "from") { answer = true; } else if(word == "had") { answer = true; } else if(word == "has") { answer = true; } else if(word == "have") { answer = true; } else if(word == "he") { answer = true; } else if(word == "her") { answer = true; } else if(word == "him") { answer = true; } else if(word == "his") { answer = true; } else if(word == "i") { answer = true; } else if(word == "if") { answer = true; } else if(word == "in") { answer = true; } else if(word == "is") { answer = true; } else if(word == "it") { answer = true; } else if(word == "me") { answer = true; } else if(word == "my") { answer = true; } else if(word == "not") { answer = true; } else if(word == "now") { answer = true; } else if(word == "of") { answer = true; } else if(word == "on") { answer = true; } else if(word == "s") { answer = true; } else if(word == "say") { answer = true; } else if(word == "she") { answer = true; } else if(word == "should") { answer = true; } else if(word == "so") { answer = true; } else if(word == "some") { answer = true; } else if(word == "t") { answer = true; } else if(word == "that") { answer = true; } else if(word == "the") { answer = true; } else if(word == "there") { answer = true; } else if(word == "they") { answer = true; } else if(word == "this") { answer = true; } else if(word == "to") { answer = true; } else if(word == "very") { answer = true; } else if(word == "was") { answer = true; } else if(word == "we") { answer = true; } else if(word == "what") { answer = true; } else if(word == "who") { answer = true; } else if(word == "will") { answer = true; } else if(word == "with") { answer = true; } else if(word == "would") { answer = true; } else if(word == "you") { answer = true; } else if(word == "your") { answer = true; } return answer;} ///-------------------------------------------------------------/// Interface --------------------------------------------------///-------------------------------------------------------------program_body main (){ object Word_Occurrence_Map word_occur, final; // object Sorting_Machine_Text sort_word_occur;// object Sorting_Machine_Integer sort_final; object Character_OStream outs; object Character_IStream ins; object Character ch; object Integer top_words, i; object Text tba, line; ins.Open_External (""); outs.Open_External (""); //Set the number of words you want outputted here top_words = 100; //Output Header information outs << "<html>\n" << "<head>\n" << "<title>Tag Cloud</title>\n" << "<link href=\"tagcloud.css\" rel=\"stylesheet\" type=\"text/css\">\n" << "</head>\n" << "<body>\n"; //Get Author ins >> line; //Output Top X Words in Author's outs << "<h2>Top " << top_words << " Words in " << line << "'s "; //Get Title ins >> line; //Output "Title" outs << "\"" << line << "\"</h2>\n" << "<hr>\n" << "<div class=\"cdiv\">\n" << "<p class=\"cbox\">\n"; //Read all words in the Text into word_occur that !Is_Common_Word while (not ins.At_EOS ()) { Get_Next_Word(ins,tba);// ins >> line;// while(line.Length()>0)// {// Get_Word(line,tba); if(!Is_Common_Word(tba)) { word_occur.Add(tba); }// } } //Sort based on number of times that word appears //Remove the first "top_words" //Add them to Word_Occurrence called final i.Clear(); while(i<top_words) { object Integer count; object Text word; word_occur.Remove_Any(word,count);// final.Add(word,count); i++; }// word_occur.Clear(); //Sort final based on Alphabetical //Remove, compute frequency, and output to tagcloud i.Clear(); while(i<top_words) { object Integer occur, total=final.Total(); object Real freq;// final.Remove(tba,occur); freq = To_Real(occur/total); if(freq >=.95) { outs << "<span style=\"cursor:default\" class=\"f48\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .95 && freq >= .90) { outs << "<span style=\"cursor:default\" class=\"f46\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .90 && freq >= .85) { outs << "<span style=\"cursor:default\" class=\"f44\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .85 && freq >= .80) { outs << "<span style=\"cursor:default\" class=\"f42\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .80 && freq >= .75) { outs << "<span style=\"cursor:default\" class=\"f40\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .75 && freq >= .70) { outs << "<span style=\"cursor:default\" class=\"f38\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .70 && freq >= .65) { outs << "<span style=\"cursor:default\" class=\"f36\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .65 && freq >= .60) { outs << "<span style=\"cursor:default\" class=\"f34\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .60 && freq >= .55) { outs << "<span style=\"cursor:default\" class=\"f32\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .55 && freq >= .50) { outs << "<span style=\"cursor:default\" class=\"f30\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .50 && freq >= .45) { outs << "<span style=\"cursor:default\" class=\"f28\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .45 && freq >= .40) { outs << "<span style=\"cursor:default\" class=\"f26\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .40 && freq >= .35) { outs << "<span style=\"cursor:default\" class=\"f24\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .35 && freq >= .30) { outs << "<span style=\"cursor:default\" class=\"f22\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .30 && freq >= .25) { outs << "<span style=\"cursor:default\" class=\"f20\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .25 && freq >= .20) { outs << "<span style=\"cursor:default\" class=\"f18\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .20 && freq >= .15) { outs << "<span style=\"cursor:default\" class=\"f16\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .15 && freq >= .10) { outs << "<span style=\"cursor:default\" class=\"f14\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .10 && freq >= .05) { outs << "<span style=\"cursor:default\" class=\"f12\" title=\"count: " << occur << "\">" << tba << "</span>"; } else if( freq < .05 && freq >= .00) { outs << "<span style=\"cursor:default\" class=\"f10\" title=\"count: " << occur << "\">" << tba << "</span>"; } else { outs << "<h1>Your code is FUBAR</h1>"; } i++; } outs << "</p>\n" << "</div>\n" << "</body>\n" << "</html>"; ins.Close_External (); outs.Close_External ();}