public void CalculateWordWeights(bool isComparison = false, double percentageMax = 60, EssayComparisonAddProgressPercentage AddPercentage = null) { double step = !isComparison ? (percentageMax - ReferringManager.Instance.ProgressPercentageCurrent) / sentenceList.Count : (percentageMax - EssayComparisonManager.Instance.ProgressPercentageCurrent) / sentenceList.Count; int sentenceIndex = 0; //choose sentence foreach (var sentence in sentenceList) { var wordsInSentence = sentence.DivideTextToWords(); //choose word foreach (var wordVariable in wordsInSentence) { var word = string.Empty; var stemmedWord = string.Empty; var wordPOS = "-"; var synsets = new List<SynSet>(); var synsetsWithPOS = new List<SynSet>(); word = wordVariable; //check word length if (ReferringManager.Instance.IsWordCutActivated) { if (word.Length < ReferringManager.Instance.WordCutLength) continue; } //stemm the word stemmedWord = Stemm(word); //check if word already in list if (goodWordList.Select(c => Stemm(c.Value)).Contains(stemmedWord)) continue; //skip for restricted words if (IsWordRestricted(word)) continue; if (ReferringManager.Instance.IsPOSDetectionActivated) { //detect part of speech wordPOS = DetectPOS(word); //is word noun, verb, adjective or adverb? if (!IsPOSGood(wordPOS)) continue; } //add current word with using-count characteristics AddWordWithCalculation(word, wordPOS); //Skip next steps if WordNet isn't activated if (!ReferringManager.Instance.IsWordNetActivated) continue; if (ReferringManager.Instance.IsStemmingActivated) { word = stemmedWord; } //search synsets synsets = GetSynsets(word, wordPOS); //try to find synsets another one if there no synsets found if (synsets.Count == 0) { if (!ReferringManager.Instance.IsStemmingActivated) { word = stemmedWord; synsets = GetSynsets(word, wordPOS); } //no synsets are found even after stemming, go to next word if (synsets.Count == 0) continue; } //synsets are found, begin updating //take required synset var requiredSynset = GetRequiredSynset(synsets); //update word weight from synword's using UpdateWordWeight(word, stemmedWord, requiredSynset); } ++sentenceIndex; goodSentenceList.Add(new Sentence { Index = sentenceIndex, Value = sentence, Weight = 0 }); if (!isComparison) { //Add percentage by ReferringProcess class if (UsePercentage) AddProgressPercentage(step); } else { //Add percentage by EssayComparisonProcess class AddPercentage(step); } } Logger.LogInfo("Word weights are calculated."); }
public void CalculateWordWeights(bool isComparison = false, double percentageMax = 60, EssayComparisonAddProgressPercentage AddPercentage = null) { double step = !isComparison ? (percentageMax - ReferringManager.Instance.ProgressPercentageCurrent) / sentenceList.Count : (percentageMax - EssayComparisonManager.Instance.ProgressPercentageCurrent) / sentenceList.Count; int sentenceIndex = 0; //choose sentence foreach (var sentence in sentenceList) { var wordsInSentence = sentence.DivideTextToWords(); //choose word foreach (var wordVariable in wordsInSentence) { var word = string.Empty; var stemmedWord = string.Empty; var wordPOS = "-"; var synsets = new List <SynSet>(); var synsetsWithPOS = new List <SynSet>(); word = wordVariable; //check word length if (ReferringManager.Instance.IsWordCutActivated) { if (word.Length < ReferringManager.Instance.WordCutLength) { continue; } } //stemm the word stemmedWord = Stemm(word); //check if word already in list if (goodWordList.Select(c => Stemm(c.Value)).Contains(stemmedWord)) { continue; } //skip for restricted words if (IsWordRestricted(word)) { continue; } if (ReferringManager.Instance.IsPOSDetectionActivated) { //detect part of speech wordPOS = DetectPOS(word); //is word noun, verb, adjective or adverb? if (!IsPOSGood(wordPOS)) { continue; } } //add current word with using-count characteristics AddWordWithCalculation(word, wordPOS); //Skip next steps if WordNet isn't activated if (!ReferringManager.Instance.IsWordNetActivated) { continue; } if (ReferringManager.Instance.IsStemmingActivated) { word = stemmedWord; } //search synsets synsets = GetSynsets(word, wordPOS); //try to find synsets another one if there no synsets found if (synsets.Count == 0) { if (!ReferringManager.Instance.IsStemmingActivated) { word = stemmedWord; synsets = GetSynsets(word, wordPOS); } //no synsets are found even after stemming, go to next word if (synsets.Count == 0) { continue; } } //synsets are found, begin updating //take required synset var requiredSynset = GetRequiredSynset(synsets); //update word weight from synword's using UpdateWordWeight(word, stemmedWord, requiredSynset); } ++sentenceIndex; goodSentenceList.Add(new Sentence { Index = sentenceIndex, Value = sentence, Weight = 0 }); if (!isComparison) { //Add percentage by ReferringProcess class if (UsePercentage) { AddProgressPercentage(step); } } else { //Add percentage by EssayComparisonProcess class AddPercentage(step); } } Logger.LogInfo("Word weights are calculated."); }