示例#1
0
        public string GetTagForWord(string word, TagDictionary markovChains)
        {
            ProbabilityDictionary <string> possibleTags = null;

            try
            {
                possibleTags = dict[word];
            } catch {  }

            if (possibleTags != null)
            {
                if (possibleTags.Count == 1)
                {
                    //Only one tag is possbile. Return that one.
                    return(possibleTags.GetRandomItem());
                }
                else
                {
                    //Multiple tags could be possible.
                    //Use markov chains and tag probability to nominate a tag.
                }
            }
            else
            {
                //Any tag could be possible. Rely on markov chains only.
            }

            return("{{ goddamit steve }}");
        }
示例#2
0
        public String TagForWord(string word, String previousTag = null)
        {
            ProbabilityDictionary <string> possibleTags = null;

            try
            {
                possibleTags = tagsForWords.GetProbabilityDictionaryFor(word);
            } catch {}


            try
            {
                if (possibleTags != null)
                {
                    if (possibleTags.Count == 1)
                    {
                        //Only one tag is possible for this word. Return that.
                        return(possibleTags.GetRandomItem());
                    }
                    else
                    {
                        //Multiple possible tags. Choose with help of markov chains.
                        try
                        {
                            return(markovChains.GetProbabilityDictionaryFor(previousTag).GetItemWithHighestProbablity());
                        }
                        catch
                        {
                            return(possibleTags.GetItemWithHighestProbablity());
                        }
                    }
                }
                else
                {
                    //No possible tags known. Rely on markov chains only.
                    //Console.WriteLine(markovChains.GetProbabilityDictionaryFor(previousTag));
                    return(markovChains.GetProbabilityDictionaryFor(previousTag).GetItemWithHighestProbablity());
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.StackTrace);
                return(null);
            }
        }