public void GuessLanguageTest() { TranslationDictionary myTransDict = new TranslationDictionary(); myTransDict.Languages = new Language[] { new Language("german", new Word[] { new Word("hallo", "hello"), new Word("der", "the"), new Word("sein", "to be") }), new Language("chinese", new Word[] { new Word("nihau", "hello"), new Word("li", "the"), new Word("lihe", "to be") }) }; Assert.AreEqual("chinese", myTransDict.GuessLanguage("niha").Name); Assert.AreEqual("chinese", myTransDict.GuessLanguage("lih").Name); Assert.AreEqual("chinese", myTransDict.GuessLanguage("lile").Name); Assert.AreEqual("german", myTransDict.GuessLanguage("seid").Name); Assert.AreEqual("german", myTransDict.GuessLanguage("seil").Name); Assert.AreEqual("german", myTransDict.GuessLanguage("hallö").Name); Assert.AreEqual("german", myTransDict.GuessLanguage("dea").Name); }
/// <summary> /// searches for some similar words that match best to the ReferenceWord. /// All Words will be of the same language /// this language will be guessed based on the ReferenceWord. /// </summary> /// <param name="ReferenceWord"></param> /// <returns>array of similar words to the ReferenceWord</returns> public string[] FindSimilarWords(string ReferenceWord) { //- Show similar words to the entered word in the same language and sort them by relevance // that's actually tricky, as we don't know for sure what language the user will be using. // we can however search through our whole database, find the most matching word, get its language // and then make suggestions based on that language. if (string.IsNullOrWhiteSpace(ReferenceWord)) { return(new string[0]); } // , then return findsimilarwords(); Language l = MyTranslationDictionary.GuessLanguage(ReferenceWord); if (l != null) { return(l.FindSimilarWords(ReferenceWord, 5, 0.3d)); } return(new string[0]); }