예제 #1
0
        private void ApplyPersianDeclensionRules(PersianPartOfSpeech[] baseTags, double[] baseWeights, string suffix, out PersianPartOfSpeech[] targetTags, out double[] targetWeights)
        {
            Dictionary <PersianPartOfSpeech, double> results = new Dictionary <PersianPartOfSpeech, double>();
            PersianSuffixesCategory suffixCat = InflectionAnalyser.SuffixCategory(suffix);

            for (int i = 0; i < baseTags.Length; i++)
            {
                foreach (PersianSuffixesCategory cat in Enum.GetValues(typeof(PersianSuffixesCategory)))
                {
                    if ((suffixCat & cat) == cat)
                    {
                        PersianPartOfSpeech pos = ApplyDeclension(baseTags[i], cat);
                        if (pos == (PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Comparative) && suffix.Equals("ترین"))
                        {
                            pos = PersianPartOfSpeech.Adjective | PersianPartOfSpeech.Superlative;
                        }
                        if (!results.ContainsKey(pos))
                        {
                            results.Add(pos, baseWeights[i]);
                        }
                        else
                        {
                            results[pos] = Math.Max(baseWeights[i], results[pos]);
                        }
                    }
                }
            }
            double sum = results.Values.Sum();

            targetTags    = (from result in results orderby result.Value descending select result.Key).ToArray();
            targetWeights = (from result in results orderby result.Value descending select result.Value / sum).ToArray();
        }
예제 #2
0
        /// <summary>
        /// Add a correct word to dictionary
        /// </summary>
        /// <param name="userSelectedWord">Form of word which user select to add to dictionary</param>
        /// <param name="originalWord">Original word without lemmatization</param>
        ///<returns>True if word is successfully added, otherwise False</returns>
        private void AddToDictionary(string userSelectedWord, string originalWord)
        {
            string suffix = originalWord.Remove(0, userSelectedWord.Length);

            PersianPOSTag extractedPOSTag = PersianPOSTag.UserPOS;

            if (suffix.Length > 0)
            {
                PersianSuffixesCategory suffixCategory = InflectionAnalyser.SuffixCategory(suffix);
                extractedPOSTag = InflectionAnalyser.AcceptingPOS(suffixCategory);

                extractedPOSTag = extractedPOSTag.Set(PersianPOSTag.UserPOS);
            }

            AddWordToFinalList(userSelectedWord, m_wordList[userSelectedWord], extractedPOSTag);
        }