class TxtDictionaryTest(unittest.TestCase): dictionary: TxtDictionary def setUp(self) -> None: self.dictionary = TxtDictionary() def test_GetCorrectForm(self): for i in range(self.dictionary.size()): self.assertTrue( len( self.dictionary.getCorrectForm( self.dictionary.getWordWithIndex(i).getName())) == 0) def test_Morphology(self): self.assertEqual("ab", self.dictionary.getWord("ab").getMorphology()) self.assertEqual("çarp+HcH+lHk", self.dictionary.getWord("çarpıcılık").getMorphology()) self.assertEqual( "aciz+lAş+yAbil+mA", self.dictionary.getWord("âcizleşebilme").getMorphology()) self.assertEqual( "ak+Hş+GAn+lAş+DHr+HCH+lHk", self.dictionary.getWord("akışkanlaştırıcılık").getMorphology()) def test_PrepareTrie(self): trie = self.dictionary.prepareTrie() self.assertTrue(Word("ben") in trie.getWordsWithPrefix("bana")) self.assertTrue(Word("sen") in trie.getWordsWithPrefix("sana")) self.assertTrue(Word("metin") in trie.getWordsWithPrefix("metni")) self.assertTrue(Word("ağız") in trie.getWordsWithPrefix("ağzı")) self.assertTrue(Word("ayır") in trie.getWordsWithPrefix("ayrıldı")) self.assertTrue(Word("buyur") in trie.getWordsWithPrefix("buyruldu")) self.assertTrue(Word("ahit") in trie.getWordsWithPrefix("ahdi")) self.assertTrue(Word("kayıp") in trie.getWordsWithPrefix("kaybı")) self.assertTrue(Word("kutup") in trie.getWordsWithPrefix("kutbu")) self.assertTrue( Word("ademelması") in trie.getWordsWithPrefix("ademelmaları")) self.assertTrue( Word("ağaçküpesi") in trie.getWordsWithPrefix("ağaçküpeleri")) self.assertTrue(Word("ağaçlık") in trie.getWordsWithPrefix("ağaçlığı")) self.assertTrue(Word("sumak") in trie.getWordsWithPrefix("sumağı")) self.assertTrue( Word("deveboynu") in trie.getWordsWithPrefix("deveboyunları")) self.assertTrue( Word("gökcismi") in trie.getWordsWithPrefix("gökcisimleri")) self.assertTrue( Word("gökkuşağı") in trie.getWordsWithPrefix("gökkuşakları")) self.assertTrue( Word("hintarmudu") in trie.getWordsWithPrefix("hintarmutları")) self.assertTrue( Word("hintpirinci") in trie.getWordsWithPrefix("hintpirinçleri")) self.assertTrue( Word("sudolabı") in trie.getWordsWithPrefix("sudolapları")) self.assertTrue(Word("ye") in trie.getWordsWithPrefix("yiyor")) self.assertTrue(Word("de") in trie.getWordsWithPrefix("diyor")) self.assertTrue(Word("depola") in trie.getWordsWithPrefix("depoluyor")) self.assertTrue(Word("dışla") in trie.getWordsWithPrefix("dışlıyor")) self.assertTrue(Word("fiyonk") in trie.getWordsWithPrefix("fiyongu")) self.assertTrue(Word("gonk") in trie.getWordsWithPrefix("gongu"))
class TxtDictionaryTest(unittest.TestCase): dictionary: TxtDictionary def setUp(self) -> None: self.dictionary = TxtDictionary("../../turkish_dictionary.txt", "../../turkish_misspellings.txt") def test_GetCorrectForm(self): for i in range(self.dictionary.size()): self.assertTrue( len( self.dictionary.getCorrectForm( self.dictionary.getWordWithIndex(i).getName())) == 0) def test_PrepareTrie(self): trie = self.dictionary.prepareTrie() self.assertTrue(Word("ben") in trie.getWordsWithPrefix("bana")) self.assertTrue(Word("metin") in trie.getWordsWithPrefix("metni")) self.assertTrue(Word("ağız") in trie.getWordsWithPrefix("ağzı")) self.assertTrue(Word("ayır") in trie.getWordsWithPrefix("ayrıldı")) self.assertTrue(Word("buyur") in trie.getWordsWithPrefix("buyruldu")) self.assertTrue(Word("ahit") in trie.getWordsWithPrefix("ahdi")) self.assertTrue(Word("kayıp") in trie.getWordsWithPrefix("kaybı")) self.assertTrue(Word("kutup") in trie.getWordsWithPrefix("kutbu")) self.assertTrue( Word("ademelması") in trie.getWordsWithPrefix("ademelmaları")) self.assertTrue( Word("ağaçküpesi") in trie.getWordsWithPrefix("ağaçküpeleri")) self.assertTrue(Word("ağaçlık") in trie.getWordsWithPrefix("ağaçlığı")) self.assertTrue(Word("sumak") in trie.getWordsWithPrefix("sumağı")) self.assertTrue( Word("deveboynu") in trie.getWordsWithPrefix("deveboyunları")) self.assertTrue( Word("gökcismi") in trie.getWordsWithPrefix("gökcisimleri")) self.assertTrue( Word("gökkuşağı") in trie.getWordsWithPrefix("gökkuşakları")) self.assertTrue( Word("hintarmudu") in trie.getWordsWithPrefix("hintarmutları")) self.assertTrue( Word("hintpirinci") in trie.getWordsWithPrefix("hintpirinçleri")) self.assertTrue( Word("sudolabı") in trie.getWordsWithPrefix("sudolapları")) self.assertTrue(Word("ye") in trie.getWordsWithPrefix("yiyor")) self.assertTrue(Word("de") in trie.getWordsWithPrefix("diyor")) self.assertTrue(Word("depola") in trie.getWordsWithPrefix("depoluyor")) self.assertTrue(Word("dışla") in trie.getWordsWithPrefix("dışlıyor")) self.assertTrue(Word("fiyonk") in trie.getWordsWithPrefix("fiyongu")) self.assertTrue(Word("gonk") in trie.getWordsWithPrefix("gongu"))
def setUp(self) -> None: self.dictionary = TxtDictionary("../../turkish_dictionary.txt", "../../turkish_misspellings.txt") self.lowerCaseDictionary = TxtDictionary("../../lowercase.txt") self.mixedCaseDictionary = TxtDictionary( "../../mixedcase.txt", "../../turkish_misspellings.txt", TxtDictionary.turkishIgnoreCaseComparator)
def setUp(self) -> None: self.simpleTrie = Trie() self.simpleTrie.addWord("azı", Word("azı")) self.simpleTrie.addWord("az", Word("az")) self.simpleTrie.addWord("ad", Word("ad")) self.simpleTrie.addWord("adi", Word("adi")) self.simpleTrie.addWord("adil", Word("adil")) self.simpleTrie.addWord("a", Word("a")) self.simpleTrie.addWord("adilane", Word("adilane")) self.simpleTrie.addWord("ısı", Word("ısı")) self.simpleTrie.addWord("ısıtıcı", Word("ısıtıcı")) self.simpleTrie.addWord("ölü", Word("ölü")) self.simpleTrie.addWord("ölüm", Word("ölüm")) self.simpleTrie.addWord("ören", Word("ören")) self.simpleTrie.addWord("örgü", Word("örgü")) self.complexTrie = Trie() dictionary = TxtDictionary("../../../turkish_dictionary.txt", "../../../turkish_misspellings.txt") for i in range(dictionary.size()): self.complexTrie.addWord( dictionary.getWordWithIndex(i).getName(), dictionary.getWordWithIndex(i))
class DictionaryTest(unittest.TestCase): dictionary: TxtDictionary lowerCaseDictionary: TxtDictionary mixedCaseDictionary: TxtDictionary def setUp(self) -> None: self.dictionary = TxtDictionary("../../turkish_dictionary.txt", "../../turkish_misspellings.txt") self.lowerCaseDictionary = TxtDictionary("../../lowercase.txt") self.mixedCaseDictionary = TxtDictionary( "../../mixedcase.txt", "../../turkish_misspellings.txt", TxtDictionary.turkishIgnoreCaseComparator) def test_GetWordIndex(self): self.assertEqual(0, self.lowerCaseDictionary.getWordIndex("a")) self.assertEqual(3, self.lowerCaseDictionary.getWordIndex("ç")) self.assertEqual(8, self.lowerCaseDictionary.getWordIndex("ğ")) self.assertEqual(10, self.lowerCaseDictionary.getWordIndex("ı")) self.assertEqual(18, self.lowerCaseDictionary.getWordIndex("ö")) self.assertEqual(22, self.lowerCaseDictionary.getWordIndex("ş")) self.assertEqual(25, self.lowerCaseDictionary.getWordIndex("ü")) self.assertEqual(28, self.lowerCaseDictionary.getWordIndex("z")) self.assertTrue( self.mixedCaseDictionary.getWordIndex("A") == 0 or self.mixedCaseDictionary.getWordIndex("A") == 1) self.assertTrue( self.mixedCaseDictionary.getWordIndex("Ç") == 6 or self.mixedCaseDictionary.getWordIndex("Ç") == 7) self.assertTrue( self.mixedCaseDictionary.getWordIndex("Ğ") == 16 or self.mixedCaseDictionary.getWordIndex("Ğ") == 17) self.assertTrue( self.mixedCaseDictionary.getWordIndex("I") == 20 or self.mixedCaseDictionary.getWordIndex("I") == 21) self.assertTrue( self.mixedCaseDictionary.getWordIndex("İ") == 22 or self.mixedCaseDictionary.getWordIndex("İ") == 23) self.assertTrue( self.mixedCaseDictionary.getWordIndex("Ş") == 44 or self.mixedCaseDictionary.getWordIndex("Ş") == 45) self.assertTrue( self.mixedCaseDictionary.getWordIndex("Ü") == 50 or self.mixedCaseDictionary.getWordIndex("Ü") == 51) self.assertTrue( self.mixedCaseDictionary.getWordIndex("Z") == 56 or self.mixedCaseDictionary.getWordIndex("Z") == 57) def test_Size(self): self.assertEqual(29, self.lowerCaseDictionary.size()) self.assertEqual(58, self.mixedCaseDictionary.size()) self.assertEqual(62112, self.dictionary.size()) def test_GetWord(self): self.assertEqual("a", self.lowerCaseDictionary.getWordWithIndex(0).name) self.assertEqual("ç", self.lowerCaseDictionary.getWordWithIndex(3).name) self.assertEqual("ğ", self.lowerCaseDictionary.getWordWithIndex(8).name) self.assertEqual("ı", self.lowerCaseDictionary.getWordWithIndex(10).name) self.assertEqual("ö", self.lowerCaseDictionary.getWordWithIndex(18).name) self.assertEqual("ş", self.lowerCaseDictionary.getWordWithIndex(22).name) self.assertEqual("ü", self.lowerCaseDictionary.getWordWithIndex(25).name) self.assertEqual("z", self.lowerCaseDictionary.getWordWithIndex(28).name) for i in range(self.dictionary.size()): self.assertIsNotNone(self.dictionary.getWordWithIndex(i)) def test_LongestWordSize(self): self.assertEqual(1, self.lowerCaseDictionary.longestWordSize()) self.assertEqual(1, self.mixedCaseDictionary.longestWordSize()) self.assertEqual(21, self.dictionary.longestWordSize()) def test_GetWordStartingWith(self): self.assertEqual( 20, self.lowerCaseDictionary.getWordStartingWith("pırasa")) self.assertEqual(27, self.lowerCaseDictionary.getWordStartingWith("veli")) self.assertEqual( 40, self.mixedCaseDictionary.getWordStartingWith("Pırasa")) self.assertEqual(54, self.mixedCaseDictionary.getWordStartingWith("Veli"))
def setUp(self) -> None: self.dictionary = TxtDictionary("../../turkish_dictionary.txt", "../../turkish_misspellings.txt")
class TxtWordTest(unittest.TestCase): dictionary: TxtDictionary def setUp(self) -> None: self.dictionary = TxtDictionary("../../turkish_dictionary.txt", "../../turkish_misspellings.txt") def test_VerbType(self): verbs = {} for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) verbType = word.verbType() if verbType in verbs: verbs[verbType] = verbs[verbType] + 1 else: verbs[verbType] = 1 self.assertEqual(5, verbs["F2P1-NO-REF"]) self.assertEqual(1, verbs["F3P1-NO-REF"]) self.assertEqual(1, verbs["F4P1-NO-REF"]) self.assertEqual(14, verbs["F4PR-NO-REF"]) self.assertEqual(2, verbs["F4PL-NO-REF"]) self.assertEqual(67, verbs["F4PW-NO-REF"]) self.assertEqual(10, verbs["F5PL-NO-REF"]) self.assertEqual(111, verbs["F5PR-NO-REF"]) self.assertEqual(1, verbs["F5PW-NO-REF"]) self.assertEqual(2, verbs["F1P1"]) self.assertEqual(11, verbs["F2P1"]) self.assertEqual(4, verbs["F3P1"]) self.assertEqual(1, verbs["F4P1"]) self.assertEqual(1, verbs["F5P1"]) self.assertEqual(7, verbs["F6P1"]) self.assertEqual(2, verbs["F2PL"]) self.assertEqual(49, verbs["F4PL"]) self.assertEqual(18, verbs["F5PL"]) self.assertEqual(173, verbs["F4PR"]) self.assertEqual(808, verbs["F5PR"]) self.assertEqual(1396, verbs["F4PW"]) self.assertEqual(13, verbs["F5PW"]) def test_IsNominal(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isNominal(): count = count + 1 self.assertEqual(30593, count) def test_IsPassive(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPassive(): count = count + 1 self.assertEqual(10, count) def test_IsAbbreviation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isAbbreviation(): count = count + 1 self.assertEqual(102, count) def test_IsInterjection(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isInterjection(): count = count + 1 self.assertEqual(104, count) def test_IsDuplicate(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isInterjection(): count = count + 1 self.assertEqual(104, count) def test_IsAdjective(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isAdjective(): count = count + 1 self.assertEqual(9671, count) def test_IsPronoun(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPronoun(): count = count + 1 self.assertEqual(48, count) def test_IsQuestion(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isQuestion(): count = count + 1 self.assertEqual(4, count) def test_IsVerb(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isVerb(): count = count + 1 self.assertEqual(5041, count) def test_IsPortmanteau(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPortmanteau(): count = count + 1 self.assertEqual(1294, count) def test_IsDeterminer(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isDeterminer(): count = count + 1 self.assertEqual(13, count) def test_IsConjunction(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isConjunction(): count = count + 1 self.assertEqual(48, count) def test_IsAdverb(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isAdverb(): count = count + 1 self.assertEqual(1845, count) def test_IsPostP(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPostP(): count = count + 1 self.assertEqual(47, count) def test_IsPortmanteauEndingWithSI(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPortmanteauEndingWithSI(): count = count + 1 self.assertEqual(178, count) def test_IsPortmanteauFacedVowelEllipsis(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPortmanteauFacedVowelEllipsis(): count = count + 1 self.assertEqual(25, count) def test_IsPortmanteauFacedSoftening(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPortmanteauFacedSoftening(): count = count + 1 self.assertEqual(348, count) def test_IsSuffix(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isSuffix(): count = count + 1 self.assertEqual(3, count) def test_IsProperNoun(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isProperNoun(): count = count + 1 self.assertEqual(19011, count) def test_IsPlural(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isPlural(): count = count + 1 self.assertEqual(398, count) def test_IsNumeral(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isNumeral(): count = count + 1 self.assertEqual(33, count) def test_NotObeysVowelHarmonyDuringAgglutination(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.notObeysVowelHarmonyDuringAgglutination(): count = count + 1 self.assertEqual(315, count) def test_ObeysAndNotObeysVowelHarmonyDuringAgglutination(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.obeysAndNotObeysVowelHarmonyDuringAgglutination(): count = count + 1 self.assertEqual(5, count) def test_RootSoftenDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.rootSoftenDuringSuffixation(): count = count + 1 self.assertEqual(5529, count) def test_RootSoftenAndNotSoftenDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.rootSoftenAndNotSoftenDuringSuffixation(): count = count + 1 self.assertEqual(14, count) def test_VerbSoftenDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.verbSoftenDuringSuffixation(): count = count + 1 self.assertEqual(87, count) def test_NounSoftenDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.nounSoftenDuringSuffixation(): count = count + 1 self.assertEqual(5443, count) def test_EndingKChangesIntoG(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.endingKChangesIntoG(): count = count + 1 self.assertEqual(26, count) def test_IsExceptional(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.isExceptional(): count = count + 1 self.assertEqual(31, count) def test_DuplicatesDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.duplicatesDuringSuffixation(): count = count + 1 self.assertEqual(36, count) def test_DuplicatesAndNotDuplicatesDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.duplicatesAndNotDuplicatesDuringSuffixation(): count = count + 1 self.assertEqual(4, count) def test_LastIdropsDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.lastIdropsDuringSuffixation(): count = count + 1 self.assertEqual(167, count) def test_LastIDropsAndNotDropDuringSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.lastIDropsAndNotDropDuringSuffixation(): count = count + 1 self.assertEqual(4, count) def test_TakesRelativeSuffixKi(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.takesRelativeSuffixKi(): count = count + 1 self.assertEqual(16, count) def test_TakesRelativeSuffixKu(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.takesRelativeSuffixKu(): count = count + 1 self.assertEqual(4, count) def test_LastIdropsDuringPassiveSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.lastIdropsDuringPassiveSuffixation(): count = count + 1 self.assertEqual(11, count) def test_VowelAChangesToIDuringYSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.vowelAChangesToIDuringYSuffixation(): count = count + 1 self.assertEqual(1299, count) def test_VowelEChangesToIDuringYSuffixation(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.vowelEChangesToIDuringYSuffixation(): count = count + 1 self.assertEqual(2, count) def test_TakesSuffixIRAsAorist(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if not word.takesSuffixIRAsAorist(): count = count + 1 self.assertEqual(51, count) def test_TakesSuffixDIRAsFactitive(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if not word.takesSuffixDIRAsFactitive(): count = count + 1 self.assertEqual(197, count) def test_ShowsSuRegularities(self): count = 0 for i in range(self.dictionary.size()): word = self.dictionary.getWordWithIndex(i) if word.showsSuRegularities(): count = count + 1 self.assertEqual(5, count)
def setUp(self) -> None: self.dictionary = TxtDictionary()