Example #1
0
        public static bool LastWordIsPluralNoun(string phase, string strNounFile
            , string strTokens, string strTags, StringTools.NounTool.MethodType nounMethodType)
        {
            string[] words = phase.Split(' ');
            if (words.Length == 0)
            {
                return false;
            }

            string lastword = StringTools.TrimPunc(words[words.Length - 1]);
            string[] Tokens = strTokens.Split(' ');
            string[] Tags = strTags.Split(' ');
            if (Tokens.Length != Tags.Length)
            {
                return NounTool.IsPluralNoun(lastword, strNounFile, nounMethodType) || NounTool.IsUncountableNoun(lastword, strNounFile, nounMethodType);
            }
            Dictionary<string, string> tok_tag = new Dictionary<string, string>();
            for (int i = Tokens.Length - 1; i >= 0; i--)
            {
                if (!tok_tag.ContainsKey(Tokens[i]))
                {
                    tok_tag.Add(Tokens[i], Tags[i]);
                }
                else
                {
                    tok_tag[Tokens[i]] = Tags[i];
                }
            }
            if (tok_tag.ContainsKey(lastword) && ((tok_tag[lastword] == "NNS") || (tok_tag[lastword] == "NNPS")))
            {
                return true;
            }
            else
            {
                return NounTool.IsPluralNoun(lastword, strNounFile, nounMethodType) || NounTool.IsUncountableNoun(lastword, strNounFile, nounMethodType);
            }
        }
Example #2
0
        public static int CountPluralNounsInWordPhase(string phase, string strNounFile
            , StringTools.NounTool.MethodType nounMethodType)
        {
            string[] words = phase.Split(' ');
            int iRet =0;
            if (words.Length == 0)
            {
                return iRet;
            }

            for (int idx = 0; idx < words.Length; idx++)
            {
                string word = StringTools.TrimPunc(words[idx]);
                if (NounTool.IsPluralNoun(word, strNounFile, nounMethodType) ||
                    NounTool.IsUncountableNoun(word, strNounFile, nounMethodType))
                {
                    iRet++;
                }
            }
            return iRet;
        }