// Computes Gunning Fog score private static void GunningFog(LinguisticAnalysis analysis, StringBuilder commentToPost) { double index = 0.4 * ((analysis.GetWords() / analysis.GetSentences()) + analysis.GetPercentageHardWords()); index = Math.Round(index, 4, MidpointRounding.AwayFromZero); commentToPost.Append(String.Format("`Gunning Fog Grade Level: {0}`\n\n", index)); }
// Computes Flesch-Kincaid Grade Level score private static void FleschKincaid(LinguisticAnalysis analysis, StringBuilder commentToPost) { double index = (.39 * (analysis.GetWords() / analysis.GetSentences())) + (11.8 * (analysis.GetSyllables() / analysis.GetWords())) - 15.59; index = Math.Round(index, 2, MidpointRounding.AwayFromZero); commentToPost.Append(String.Format("`Flesch-Kincaid Grade Level: {0}`\n\n", index)); }
// Computes the Flesch Ease score private static void Flesch(LinguisticAnalysis analysis, StringBuilder commentToPost) { double index = 206.835 - (1.015 * (analysis.GetWords() / analysis.GetSentences())) - (84.6 * (analysis.GetSyllables() / analysis.GetWords())); index = Math.Round(index, 2, MidpointRounding.AwayFromZero); commentToPost.Append(String.Format("`Flesch Ease: {0}`\n\n", index)); }
// Computes Automated Readability Index score private static void AutoRI(LinguisticAnalysis analysis, StringBuilder commentToPost) { double index = (4.71 * (analysis.GetCharacters() / analysis.GetWords())) + (.5 * (analysis.GetWords() / analysis.GetSentences())) - 21.43; index = Math.Round(index, 2, MidpointRounding.AwayFromZero); commentToPost.Append(String.Format("`Automated Readability Index: {0}`\n\n", index)); }
// Readability test protected static void ReadabilityAnalysis(LinguisticAnalysis analysis, StringBuilder commentToPost) { if (!analysis.EmptyComment) { Flesch(analysis, commentToPost); FleschKincaid(analysis, commentToPost); AutoRI(analysis, commentToPost); GunningFog(analysis, commentToPost); } else { commentToPost.Append("Empty comment. No analysis to perform."); } }
static int Main(string[] args) { Reddit reddit = new Reddit(); Login(reddit); Subreddit subreddit = GetFrontPage(reddit); IEnumerable<Post> topPosts = GetTopPosts(subreddit); Subreddit subredditToPostTo = reddit.GetSubreddit("readability"); foreach (Post post in topPosts) { StringBuilder commentToPost = new StringBuilder(String.Format("Thread link: http://www.reddit.com/{0}\n\n***\n\n", post.Id)); List<Comment> topComments = GetTopComments(post); foreach (Comment comment in topComments) { commentToPost.Append(String.Format("\"{0}\"\n\n", comment.Body)); // Removes formatting so that linguistic analysis works properly string commentText = comment.Body; RemoveFormatting(ref commentText); LinguisticAnalysis analysis = new LinguisticAnalysis(commentText); commentToPost.Append(String.Format("`Words: {0}`\n\n`Characters: {1}`\n\n`Sentences: {2}`\n\n`Syllables: {3}`\n\n`% Hard Words: {4}`\n\n", analysis.GetWords(), analysis.GetCharacters(), analysis.GetSentences(), analysis.GetSyllables(), analysis.GetPercentageHardWords())); ReadabilityAnalysis(analysis, commentToPost); commentToPost.Append("***\n\n"); } PostRedditThread(subredditToPostTo, post.Title, commentToPost); } Console.WriteLine(LOG_SUCCESSFUL_RUN); Console.Read(); // Remove later return 1; }