public virtual ProbableStrength Describes(PhraseSense sense)
        {
            ProbableStrength total          = new ProbableStrength(0, 0);
            double           strengthFactor = total.ImproveStrengthStart();

            foreach (PhraseAttribute attribute in sense.Attributes)
            {
                total.ImproveStrength(Match(attribute), ref strengthFactor);
            }

            if (strengthFactor == 0)
            {
                // do we match subphrases then?
                foreach (InformedPhrase subphrase in sense.Phrases)
                {
                    total.ImproveStrength(Describes(subphrase).DownWeight(1.0 / sense.Phrases.Count), ref strengthFactor);
                }
            }

            if (strengthFactor == 0)
            {
                // We never found an appropriate attribute-- so guess!
                List <KeyValuePair <PhraseSense, double> > senses = new List <KeyValuePair <PhraseSense, double> >();
                senses.Add(new KeyValuePair <PhraseSense, double>(sense, 1.0));
                InformedPhrase   dummy  = new InformedPhrase(sense.Name(), senses);
                ProbableStrength result = Match(Guess(dummy));
                total.ImproveStrength(result, ref strengthFactor);
            }

            total.ImproveStrengthFinish(strengthFactor);
            return(total);
        }
        public virtual ProbableStrength Describes(PhraseSense sense)
        {
            ProbableStrength total = new ProbableStrength(0, 0);
            double strengthFactor = total.ImproveStrengthStart();

            foreach (PhraseAttribute attribute in sense.Attributes)
                total.ImproveStrength(Match(attribute), ref strengthFactor);

            if (strengthFactor == 0)
            {
                // do we match subphrases then?
                foreach (InformedPhrase subphrase in sense.Phrases)
                    total.ImproveStrength(Describes(subphrase).DownWeight(1.0 / sense.Phrases.Count), ref strengthFactor);
            }

            if (strengthFactor == 0)
            {
                // We never found an appropriate attribute-- so guess!
                List<KeyValuePair<PhraseSense, double>> senses = new List<KeyValuePair<PhraseSense, double>>();
                senses.Add(new KeyValuePair<PhraseSense,double>(sense, 1.0));
                InformedPhrase dummy = new InformedPhrase(sense.Name(), senses);
                ProbableStrength result = Match(Guess(dummy));
                total.ImproveStrength(result, ref strengthFactor);
            }

            total.ImproveStrengthFinish(strengthFactor);
            return total;
        }
Beispiel #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);
            }
        }