public override bool IsMatch(IParsedPhrase check)
        {
            if (check.Part == pos)
            {
                return(true);
            }

            if (check.Part.StartsWith("VB"))
            {
                return(!Verbs.IsToBe(check.Text) && verbs.GetInflection(check.Text) == inflection);
            }
            else
            {
                return(false);
            }
        }
        public override bool IsMatch(Concept concept)
        {
            // Is this a time?  If so, we can work with it!
            if (concept.IsSpecial && (concept == memory.past || concept == memory.now || concept == memory.future))
            {
                return(true);
            }

            List <string> parts = StringUtilities.SplitWords(concept.Name, true);

            foreach (string part in parts)
            {
                if (!(part == "en" || part == "ing" || Verbs.IsModal(part) || Verbs.IsToBe(part) || Verbs.IsToDo(part) || Verbs.IsToHave(part)))
                {
                    return(false);
                }
            }

            return(true);
        }
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List <Phrase> emphasizes, ref double prob)
        {
            // Can we change to passive voice?
            VerbPhrase verbphrase = FindConsituent <VerbPhrase>();
            NounPhrase subjphrase = FindConsituent <NounPhrase>();

            if (verbphrase != null && subjphrase != null)
            {
                Verb verb = verbphrase.FindConsituent <Verb>();
                if (verb.Word == "had" || verb.Word == "have" || verb.Word == "has")
                {
                    verb = null;    // never do passive transformations to this
                }
                if (verb != null && verbs.IsTransitive(verb.Word))
                {
                    bool isToBe = Verbs.IsToBe(verb.Word);
                    if (!isToBe && verbphrase.IsComposed(typeof(Verb), typeof(NounPhrase)))
                    {  // Like "The dog ate the bone."
                        if (RemoveEmphasizedImprobability(.75, emphasizes, subjphrase, ref prob))
                        {
                            NounPhrase objphrase     = verbphrase.FindConsituent <NounPhrase>();
                            Phrase     newobjphrase  = subjphrase.ParaphraseAsObject(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);
                            Phrase     newsubjphrase = objphrase.ParaphraseAsSubject(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);

                            return(new SimpleDeclarativePhrase(newsubjphrase, new VerbPhrase(new Verb(Verbs.ComposeToBe(nouns.GetPerson(objphrase.Text), verbs.GetInflection(verb.Word))), new VerbPastParticiple(verbs.InflectVerb(verb.Word, Verbs.Convert.ext_Ven)), new PrepositionalPhrase(new Preposition("by"), newobjphrase)), new Period(" .")));
                        }
                    }
                    else if (!isToBe && verbphrase.IsComposed(typeof(Verb), typeof(NounPhrase), typeof(PrepositionalPhrase)))
                    { // Like "Joe gave a ring to Mary."
                        if (RemoveEmphasizedImprobability(.75, emphasizes, subjphrase, ref prob))
                        {
                            NounPhrase dirobjphrase    = verbphrase.FindConsituent <NounPhrase>();
                            Phrase     newsubjphrase   = dirobjphrase.ParaphraseAsSubject(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);
                            Phrase     newdirobjphrase = subjphrase.ParaphraseAsObject(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);

                            PrepositionalPhrase indobjphrase = verbphrase.FindConsituent <PrepositionalPhrase>();
                            Phrase newindobjphrase           = indobjphrase.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);

                            return(new SimpleDeclarativePhrase(newsubjphrase, new VerbPhrase(new Verb(Verbs.ComposeToBe(nouns.GetPerson(dirobjphrase.Text), verbs.GetInflection(verb.Word))), new VerbPastParticiple(verbs.InflectVerb(verb.Word, Verbs.Convert.ext_Ven)), newindobjphrase, new PrepositionalPhrase(new Preposition("by"), newdirobjphrase)), new Period(" .")));
                        }
                    }
                    else if (!isToBe && verbphrase.IsComposed(typeof(Verb), typeof(VerbPastParticiple), typeof(PrepositionalPhrase)))
                    { // Like "The bone was eaten by the dog."
                        PrepositionalPhrase byphrase = verbphrase.FindConsituent <PrepositionalPhrase>();
                        if (byphrase.IsComposed(typeof(Preposition), typeof(NounPhrase)) && byphrase.Constituents[0].Text == "by")
                        {
                            if (RemoveEmphasizedImprobability(.4, emphasizes, subjphrase, ref prob))
                            {
                                Phrase             newsubjphrase = byphrase.FindConsituent <NounPhrase>().ParaphraseAsSubject(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);
                                Phrase             newobjphrase  = subjphrase.ParaphraseAsObject(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);
                                VerbPastParticiple oldverb       = verbphrase.FindConsituent <VerbPastParticiple>();
                                Verb newverb = new Verb(verbs.InflectVerb(oldverb.Word, verbs.GetInflection(verb.Word)));

                                return(new SimpleDeclarativePhrase(newsubjphrase, new VerbPhrase(newverb, newobjphrase), new Period(" .")));
                            }
                        }
                    }
                    else if (!isToBe && verbphrase.IsComposed(typeof(Verb), typeof(VerbPastParticiple), typeof(PrepositionalPhrase), typeof(PrepositionalPhrase)))
                    { // Like "A ring was given to Mary by Joe."
                        PrepositionalPhrase indobjphrase = verbphrase.FindConsituent <PrepositionalPhrase>(0);
                        PrepositionalPhrase byphrase     = verbphrase.FindConsituent <PrepositionalPhrase>(1);
                        if (byphrase.IsComposed(typeof(Preposition), typeof(NounPhrase)) && byphrase.Constituents[0].Text == "by")
                        {
                            if (RemoveEmphasizedImprobability(.4, emphasizes, subjphrase, ref prob))
                            {
                                Phrase             newsubjphrase = byphrase.FindConsituent <NounPhrase>().ParaphraseAsSubject(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);
                                Phrase             newobjphrase  = subjphrase.ParaphraseAsObject(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);
                                VerbPastParticiple oldverb       = verbphrase.FindConsituent <VerbPastParticiple>();
                                Verb newverb = new Verb(verbs.InflectVerb(oldverb.Word, verbs.GetInflection(verb.Word)));

                                return(new SimpleDeclarativePhrase(newsubjphrase, new VerbPhrase(newverb, newobjphrase, indobjphrase), new Period(" .")));
                            }
                        }
                    }
                    else if (isToBe && verbphrase.IsComposed(typeof(Verb), typeof(PrepositionalPhrase)))
                    { // Like "The fly is on the wall."
                        if (RemoveEmphasizedImprobability(.6, emphasizes, subjphrase, ref prob))
                        {
                            Phrase newobjphrase  = subjphrase.ParaphraseAsObject(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);
                            Phrase newprepphrase = verbphrase.FindConsituent <PrepositionalPhrase>().Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
                            return(new SimpleDeclarativePhrase(new ExistentialThere("There"), new VerbPhrase(verb, newobjphrase, newprepphrase), new Period(" .")));
                        }
                    }
                }
            }

            ExistentialThere there = FindConsituent <ExistentialThere>();

            if (verbphrase != null && there != null)
            {
                Verb verb = verbphrase.FindConsituent <Verb>();
                if (Verbs.IsToBe(verb.Word) && verbphrase.IsComposed(typeof(Verb), typeof(NounPhrase), typeof(PrepositionalPhrase)))
                { // Like "There is a fly on the wall."
                    if (RemoveUnemphasizedImprobability(.4, emphasizes, verbphrase.Constituents[1], ref prob))
                    {
                        Phrase newsubjphrase = verbphrase.FindConsituent <NounPhrase>().ParaphraseAsSubject(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);
                        Phrase newprepphrase = verbphrase.FindConsituent <PrepositionalPhrase>().Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
                        return(new SimpleDeclarativePhrase(newsubjphrase, new VerbPhrase(verb, newprepphrase), new Period(" .")));
                    }
                }
            }

            return(base.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob));
        }
 public override bool IsMatch(IParsedPhrase check)
 {
     return(check.Part.StartsWith("VB") && !Verbs.IsToBe(check.Text));
 }
Exemple #5
0
        public override bool Transform(Sentence sentence)
        {
            if (!sentence.phrases.Contains(this))
            {
                return(false);
            }

            bool success = false;
            KeyValuePair <string, string> nks = NeighborKinds(sentence);

            Phrase verbphr = FindConsituent <Verb>();
            string verb    = (verbphr == null ? "" : verbphr.Text);

            if (nks.Key == "ADVP")
            {
                sentence.AbsorbPrevious(this);
                success = true;
            }
            else if (nks.Value == "VBN")
            { // is considered
                sentence.AbsorbNext(this);
                success = true;
            }
            else if (nks.Value == "ADVP")
            {
                sentence.AbsorbNext(this);
                success = true;
            }
            else if (nks.Value == "NP")
            {
                sentence.AbsorbNext(this);
                success = true;
            }
            else if (nks.Value == "ADJP" && Verbs.IsToBe(verb))
            {
                sentence.AbsorbNext(this);
                success = true;
            }

            else if (nks.Value == "PP")
            {
                sentence.AbsorbNext(this);
                success = true;
            }

            else if (nks.Key == "TO")
            {
                List <Phrase> us = new List <Phrase>();
                us.Add(sentence.PhraseBefore(this));
                us.Add(this);
                sentence.Combine(us, new PrepositionalPhrase());
                success = true;
            }

            else if (nks.Key == "WHNP" || nks.Key == "WRB")
            {
                string trial = sentence.PhraseBefore(this).ToString() + ";" + ToString() + ";SBARQ";
                if (!triedBefore.ContainsKey(trial))
                {
                    List <Phrase> phrases = new List <Phrase>();
                    phrases.Add(sentence.PhraseBefore(this));
                    phrases.Add(this);
                    sentence.Combine(phrases, new SimpleQuestion());
                    triedBefore.Add(trial, true);
                    success = true;
                }
            }

            else if (nks.Key == "NP" || nks.Key == "EX")
            {
                string trial = sentence.PhraseBefore(this).ToString() + ";" + ToString() + ";S";
                if (!triedBefore.ContainsKey(trial))
                {
                    List <Phrase> phrases = new List <Phrase>();
                    phrases.Add(sentence.PhraseBefore(this));
                    phrases.Add(this);
                    sentence.Combine(phrases, new SimpleDeclarativePhrase());
                    triedBefore.Add(trial, true);
                    success = true;
                }
            }

            return(success);
        }
Exemple #6
0
        public override bool?IsMatch(IParsedPhrase check)
        {
            string verb;

            if (check.IsLeaf || !check.Text.Contains(" "))
            {
                verb = check.Text;

                if (Verbs.IsToHave(verb))
                {
                    if (bases.Contains("have"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (Verbs.IsToBe(verb))
                {
                    if (bases.Contains("be"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (Verbs.IsToDo(verb))
                {
                    if (bases.Contains("do"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (verb == "will" || verb == "shall")
                {
                    return(null);                    // not sure yet
                }
            }
            else
            {
                GroupPhrase groupPhrase = new GroupPhrase(check);
                if (groupPhrase.Count > 2)
                {
                    return(false);
                }

                string helper = groupPhrase.GetBranch(0).Text.ToLower();
                verb = groupPhrase.GetBranch(1).Text.ToLower();

                if (!Verbs.IsToHave(helper) && !Verbs.IsToBe(helper) && !Verbs.IsToDo(helper) &&
                    helper != "will" && helper != "shall")
                {
                    return(false);
                }
            }

            string baseverb = verbs.InputToBase(verb);

            return(comparer.MatchAny(verb, options) || comparer.MatchAny(verb, bases) ||
                   comparer.MatchAny(baseverb, bases));
        }