示例#1
0
        // Try to determine if this is any kind of given name
        public ProbableStrength IsGivenName(IWordLookup informer, string word)
        {
            word = word.ToLower();

            // Try to look it up in me
            string nametype = null;

            if (TryGetValue(word, out nametype))
            {
                return(ProbableStrength.Full);
            }

            double weight = informer.GetWeight(word, false);

            return(new ProbableStrength(weight * weight, 0.5));
        }
示例#2
0
        public static ProbableStrength SeemsReferee(InformedPhrase phrase, IWordLookup informer, ProbableStrength anaphora)
        {
            List <string> words = phrase.Generate();

            double weight = 0;

            foreach (string word in words)
            {
                weight += informer.GetWeight(word, false);
            }

            /* words weight result
             * 1     0      0
             * 1     1      1
             * 2     0      0
             * 2     .5     .4
             * 2     1      2/3
             * 2     1.5    .86
             * 2     2      1
             * 3     .5     .3
             * 3     1      .5
             * 3     2      .8
             */
            double myweight = 2.0 * weight / (words.Count + weight);

            if (words.Count == 1)
            {
                myweight /= 2.0;    // down-score 1-word answers
            }
            if (words.Count > 2)
            {
                myweight /= Math.Log(words.Count);
            }

            ProbableStrength notanaphora = anaphora.InverseProbability();

            return(new ProbableStrength(Math.Sqrt(myweight * notanaphora.strength), notanaphora.weight + .5 - notanaphora.weight * .5));
        }
示例#3
0
        // Given a noun phrase sense
        public void GenderInform(PhraseSense sense, IWordLookup informer)
        {
            // Drill down to the first noun word, looking for a current attribute
            PhraseSense     first  = sense;
            GenderAttribute bypart = (GenderAttribute)first.FindAttribute(typeof(GenderAttribute));

            while (bypart == null)
            {
                // Find a noun sub-phrase
                PhraseSense next = null;
                foreach (InformedPhrase subfirst in first.Phrases)
                {
                    foreach (KeyValuePair <PhraseSense, double> firstsense in subfirst.Senses)
                    {
                        if (nounparts.Contains(firstsense.Key.SpeechPart()))
                        {
                            next = firstsense.Key;
                            break;
                        }
                    }
                    if (next != null)
                    {
                        break;
                    }
                }
                if (next == null)
                {
                    break;
                }
                bypart = (GenderAttribute)next.FindAttribute(typeof(GenderAttribute));

                if (next.Phrases.Count == 0)
                {
                    break;
                }
                first = next;
            }

            if (first.SpeechPart() != SpeechPart.ProperNoun)
            {
                if (bypart != null && bypart.Strength.weight > 0.5)
                {
                    return;  // we seem to know!
                }
                List <string> words;
                if (first.Phrases.Count > 0)
                {
                    words = first.Phrases[0].Generate();
                }
                else
                {
                    words = new List <string>();
                    words.Add(first.Name());
                }
                if (informer.GetWeight(words[0], false) < 0.5)
                {
                    return;  // not worth the lookup
                }
                if (bypart == null)
                {
                    GenderAttribute dummy = new GenderAttribute();
                    bypart = (GenderAttribute)dummy.Guess(sense.Phrases[0]);
                }
            }

            // Now guess using the given name
            InformedPhrase tocheck;

            if (first.Phrases.Count > 0)
            {
                tocheck = first.Phrases[0];
            }
            else
            {
                List <KeyValuePair <PhraseSense, double> > senses = new List <KeyValuePair <PhraseSense, double> >();
                senses.Add(new KeyValuePair <PhraseSense, double>(first, 1.0));
                tocheck = new InformedPhrase(sense.Name(), senses);
            }
            GenderAttribute gender = GuessGender(tocheck, informer);

            if (bypart != null)
            {
                gender = MergeGenderAttributes(gender, bypart);
            }

            // Update relevant gender attributes
            sense.AddOrUpdateAttribute(gender);
            if (sense != first)
            {
                first.AddOrUpdateAttribute(gender);
            }
        }
        public static ProbableStrength SeemsReferee(InformedPhrase phrase, IWordLookup informer, ProbableStrength anaphora)
        {
            List<string> words = phrase.Generate();

            double weight = 0;
            foreach (string word in words)
                weight += informer.GetWeight(word, false);
            /* words weight result
             * 1     0      0
             * 1     1      1
             * 2     0      0
             * 2     .5     .4
             * 2     1      2/3
             * 2     1.5    .86
             * 2     2      1
             * 3     .5     .3
             * 3     1      .5
             * 3     2      .8
             */
            double myweight = 2.0 * weight / (words.Count + weight);
            if (words.Count == 1)
                myweight /= 2.0;    // down-score 1-word answers
            if (words.Count > 2)
                myweight /= Math.Log(words.Count);

            ProbableStrength notanaphora = anaphora.InverseProbability();

            return new ProbableStrength(Math.Sqrt(myweight * notanaphora.strength), notanaphora.weight + .5 - notanaphora.weight * .5);
        }