private void addParagraphScore(RankedSelectedMeaning meaning, string paragraph, int paragraphDistance, StringBuilder explanationSB) { double distanceModifier = paragraphDistance == 0 ? 1.0 : (double)paragraphDistance * (double)_paragraphDistanceModifier; bool nothingCounted = true; foreach (Match word in Regex.Matches(paragraph, _wordRegularExpresion)) { if (word.Length > _relevantWordMinimumLength) { double initialScore = meaning.Score; int acronymPartsCount = getNumOfMatches(meaning.MeaningCaption, word.Value); meaning.Score += acronymPartsCount * _acronymPartWeight / distanceModifier; int categoriesPartCount = getNumOfMatches(string.Join(", ", meaning.Meaning.Categories), word.Value); meaning.Score += categoriesPartCount * _categoryWeight / distanceModifier; if (acronymPartsCount > 0 || categoriesPartCount > 0) { explanationSB.AppendFormat("{4}\tWord: {0}\t\t\tAcronym Parts: {1}\t\tCategories Part: {2}\t\tScore:{3}", word.Value, acronymPartsCount, categoriesPartCount, meaning.Score - initialScore, Environment.NewLine); nothingCounted = false; } } } if (nothingCounted) { explanationSB.AppendFormat("\t\tnothing relevant"); } }
private void calculateScore(RankedSelectedMeaning meaning, TextSplitted textSplitted) { meaning.Score = 0.0; StringBuilder explanationSB = new StringBuilder(); explanationSB.Append("Main paragraph:"); addParagraphScore(meaning, textSplitted.MainParagraph, 0, explanationSB); List <List <string> > paragraphsToCheck = new List <List <string> > { textSplitted.LeftParagraphs, textSplitted.RightParagraphs }; bool leftParagraph = true; foreach (List <string> paragraphsList in paragraphsToCheck) { int distance = 0; foreach (string paragraph in paragraphsList) { distance++; explanationSB.AppendFormat("{2}{0} paragraph {1}:", leftParagraph ? "Left" : "Right", distance, Environment.NewLine); addParagraphScore(meaning, paragraph, distance, explanationSB); } leftParagraph = false; } explanationSB.AppendFormat("{1}Total score: {0}", meaning.Score, Environment.NewLine); meaning.Explanation = explanationSB.ToString(); }