internal void SetPriority(LanguageDictionary.PrefixType prefixType) { switch (prefixType) { case LanguageDictionary.PrefixType.Word: this.m_priority = 20; break; case LanguageDictionary.PrefixType.Prefix: this.m_priority = 10; break; case LanguageDictionary.PrefixType.NotExists: this.m_priority = 0; break; } }
private void GenerateCandidateWordsWithBacktracking(int k, Word w, List <int> keysList, Dictionary <int, List <int> > positionsOfChosenCharsSolution) { Dictionary <int, List <int> > solution = CreateNewDictionary(positionsOfChosenCharsSolution); Word newWord = new Word(w, solution); String newWordString = newWord.ToString(); LanguageDictionary.PrefixType prefixType = languageDictionary.GetPrefixType(newWordString.ToLower()); if (prefixType == LanguageDictionary.PrefixType.NotExists) { return; } //this backtracking assumes that each connected component has only one letter if (k >= keysList.Count) { // solution //if (DifferentDictionaries(w.GetPositionsOfChosenCharsDictionary(), positionsOfChosenCharsSolution)) // TODO: eliminate this function if possible // the if statement from above is unnecessary since we were comparing the solution word with the initial word by their // positions of chosen chars. if (newWordString.ToLower() != w.ToString().ToLower()) { newWord.SetPriority(prefixType); m_candidateWords[newWordString] = newWord; //m_candidateWords.Add(newWord); } return; } int currentKey = keysList[k]; List <int> currentList = new List <int>(); for (int i = 0; i < 3; i++) { currentList.Clear(); currentList.Add(i); positionsOfChosenCharsSolution.Add(currentKey, currentList); GenerateCandidateWordsWithBacktracking(k + 1, w, keysList, positionsOfChosenCharsSolution); positionsOfChosenCharsSolution.Remove(currentKey); } }