Esempio n. 1
0
        /**
         * <summary>The addWordWhenRootSoften is used to add word to Trie whose last consonant will be soften.
         * For instance, in the case of Dative Case Suffix, the word is 'müzik' when '-e' is added to the word, the last
         * char is drooped and root became 'müzi' and by changing 'k' into 'ğ' the word transformed into 'müziğe' as in the
         * example of 'Herkes müziğe doğru geldi'.
         * In the case of accusative, possessive of third person and a derivative suffix, the word is 'kanat' when '-i' is
         * added to word, last char is dropped, root became 'kana' then 't' transformed into 'd' and added to Trie. The word is
         * changed into 'kanadı' as in the case of 'Kuşun kırık kanadı'.</summary>
         *
         * <param name="trie">the name of the Trie to add the word.</param>
         * <param name="last">the last char of the word to be soften.</param>
         * <param name="root">the substring of the word whose last one or two chars are omitted from the word to bo softed.</param>
         * <param name="word">the original word.</param>
         */
        private void AddWordWhenRootSoften(Trie.Trie trie, char last, string root, TxtWord word)
        {
            switch (last)
            {
            case 'p':
                trie.AddWord(root + 'b', word);
                break;

            case '\u00e7':     //ç
                trie.AddWord(root + 'c', word);
                break;

            case 't':
                trie.AddWord(root + 'd', word);
                break;

            case 'k':
            case 'g':
                trie.AddWord(root + '\u011f', word);     //ğ
                break;
            }
        }
Esempio n. 2
0
        /**
         * <summary>The prepareTrie method is used to create a Trie with the given dictionary. First, it gets the word from dictionary,
         * then checks some exceptions like 'ben' which does not fit in the consonant softening rule and transforms into 'bana',
         * and later on it generates a root by removing the last char from the word however if the length of the word is greater
         * than 1, it also generates the root by removing the last two chars from the word.
         * Then, it gets the last char of the root and adds root and word to the result Trie. There are also special cases such as;
         * lastIdropsDuringSuffixation condition, if it is true then addWordWhenRootSoften method will be used rather than addWord.
         * Ex : metin + i = metni
         * isPortmanteauEndingWithSI condition, if it is true then addWord method with rootWithoutLastTwo will be used.
         * Ex : ademelması + lar = ademelmaları
         * isPortmanteau condition, if it is true then addWord method with rootWithoutLast will be used.
         * Ex : mısıryağı + lar = mısıryağları
         * vowelEChangesToIDuringYSuffixation condition, if it is then addWord method with rootWithoutLast will be used
         * depending on the last char whether it is 'e' or 'a'.
         * Ex : ye + iniz - yiyiniz
         * endingKChangesIntoG condition, if it is true then addWord method with rootWithoutLast will be used with added 'g'.
         * Ex : ahenk + i = ahengi</summary>
         *
         * <returns>the resulting Trie.</returns>
         */
        public Trie.Trie PrepareTrie()
        {
            Trie.Trie result = new Trie.Trie();
            String    root, rootWithoutLast, rootWithoutLastTwo;
            char      last, lastBefore = ' ';
            int       length;

            for (int i = 0; i < Size(); i++)
            {
                TxtWord word = (TxtWord)GetWord(i);
                root   = word.GetName();
                length = root.Length;
                if (root == "ben")
                {
                    result.AddWord("bana", word);
                }

                if (root == "sen")
                {
                    result.AddWord("sana", word);
                }

                rootWithoutLast = root.Substring(0, length - 1);
                if (length > 1)
                {
                    rootWithoutLastTwo = root.Substring(0, length - 2);
                }
                else
                {
                    rootWithoutLastTwo = "";
                }

                if (length > 1)
                {
                    lastBefore = root[length - 2];
                }

                last = root[length - 1];
                result.AddWord(root, word);
                if (word.LastIdropsDuringSuffixation() || word.LastIdropsDuringPassiveSuffixation())
                {
                    if (word.RootSoftenDuringSuffixation())
                    {
                        AddWordWhenRootSoften(result, last, rootWithoutLastTwo, word);
                    }
                    else
                    {
                        result.AddWord(rootWithoutLastTwo + last, word);
                    }
                }

                // NominalRootNoPossessive
                if (word.IsPortmanteauEndingWithSI())
                {
                    result.AddWord(rootWithoutLastTwo, word);
                }

                if (word.RootSoftenDuringSuffixation())
                {
                    AddWordWhenRootSoften(result, last, rootWithoutLast, word);
                }

                if (word.IsPortmanteau())
                {
                    if (word.IsPortmanteauFacedVowelEllipsis())
                    {
                        result.AddWord(rootWithoutLastTwo + last + lastBefore, word);
                    }
                    else
                    {
                        if (word.IsPortmanteauFacedSoftening())
                        {
                            switch (lastBefore)
                            {
                            case 'b':
                                result.AddWord(rootWithoutLastTwo + 'p', word);
                                break;

                            case 'c':
                                result.AddWord(rootWithoutLastTwo + 'ç', word);
                                break;

                            case 'd':
                                result.AddWord(rootWithoutLastTwo + 't', word);
                                break;

                            case 'ğ':
                                result.AddWord(rootWithoutLastTwo + 'k', word);
                                break;
                            }
                        }
                        else
                        {
                            result.AddWord(rootWithoutLast, word);
                        }
                    }
                }

                if (word.VowelEChangesToIDuringYSuffixation() || word.VowelAChangesToIDuringYSuffixation())
                {
                    switch (last)
                    {
                    case 'e':
                        result.AddWord(rootWithoutLast, word);
                        break;

                    case 'a':
                        result.AddWord(rootWithoutLast, word);
                        break;
                    }
                }

                if (word.EndingKChangesIntoG())
                {
                    result.AddWord(rootWithoutLast + 'g', word);
                }
            }

            return(result);
        }