public TextSummary(TextInfo info, string text, int decimals = 3) { var words = GetWords(text, false); var sentences = GetSentences(text); Author = info.Author; Title = info.Title; Year = info.Year; YearInterval = info.YearInterval; Textlength = text.Length; SentencesCount = sentences.Count; WordsCount = words.Count; StopWordsCount = WordsCount - GetWords(text, true).Count; WordFrequencyList = GetWordFrequencyList(words, decimals); Words = FillWordMetrics(info.Title, words, decimals); DifferentWordsCount = WordFrequencyList.Count(); HapaxLegomena = WordFrequencyList.Count(x => x.Antal == 1); HapaxDisLegomena = WordFrequencyList.Count(x => x.Antal == 2); HapaxTrisLegomena = WordFrequencyList.Count(x => x.Antal == 3); Sentences = FillSentenceMetrics(info.Title, sentences, decimals); WordsBeginningWithWovels = WordsBeginningWithVowel(words); LongWordsCount = words.Count(x => x.Length > 6); Lix = CalculateLix(WordsCount, SentencesCount, LongWordsCount, decimals); AutomatedReadability = CalculateAutomatedReadability(WordsCount, SentencesCount, Textlength, decimals); ColemanLiau = CalculateColemanLiau(WordsCount, SentencesCount, Textlength, decimals); Herdan = CalculateHerdan(WordsCount, DifferentWordsCount, decimals); Guiraud = CalculateGuiraud(WordsCount, DifferentWordsCount, decimals); Uber = CalculateUber(WordsCount, DifferentWordsCount, decimals); Smog = CalculateSmogIndex(words, SentencesCount, decimals); // Sentiments = CalculateSentiments(info.Title, words); }
public static SentenceMetrics FillSentenceMetrics(string label, List <string> sentences, int decimals) { var metrics = new SentenceMetrics(); if (sentences.Count > 0) { List <int> lengths = new List <int>(); foreach (var sentence in sentences) { var wordscount = GetWords(sentence, false).Count; lengths.Add(wordscount); } metrics.Max = lengths.Max(); metrics.Min = lengths.Min(); metrics.Mean = Math.Round(lengths.Average(), decimals); metrics.Median = CalculateMedian(lengths); metrics.Variance = Math.Round(lengths.Average(x => Math.Pow(x - metrics.Mean, 2)), decimals); metrics.StandarDeviation = Math.Round(Math.Sqrt(metrics.Variance), decimals); metrics.Mode = CalculateMode(lengths); metrics.Label = label; } return(metrics); }