public static void Main(string[] args)
        {
            PluginEnvironment plugenv = new PluginEnvironment(new MainClass());
            string plugbase = "/Users/jrising/projects/virsona/plugins/data";
            plugenv.Initialize(plugbase + "/config.xml", plugbase, new NameValueCollection());

            // Test 1: POS Tagging
            POSTagger tagger = new POSTagger(plugenv);
            List<KeyValuePair<string, string>> tagged = tagger.TagList(StringUtilities.SplitWords("This is a test.", false));
            foreach (KeyValuePair<string, string> kvp in tagged)
                Console.WriteLine(kvp.Key + ": " + kvp.Value);

            // Test 2: Grammar parsing
            GrammarParser parser = new GrammarParser(plugenv);
            IParsedPhrase before = parser.Parse("This is a rug and a keyboard.");
            Console.WriteLine(before.ToString());

            // Test 3: Paraphrasing
            Random randgen = new Random();
            IParsedPhrase after = parser.Paraphrase(before, null, null, randgen.NextDouble());
            Console.WriteLine(after.Text);

            // Test 4: Look up some indices
            WordNetAccess wordnet = new WordNetAccess(plugenv);
            Console.WriteLine("Synonyms: " + string.Join(", ", wordnet.GetExactSynonyms("rug", WordNetAccess.PartOfSpeech.Noun).ToArray()));

            // Test 5: Pluralize nouns and conjugate verbs
            Nouns nouns = new Nouns(plugenv);
            Console.WriteLine("person becomes " + nouns.Pluralize("person"));
            Verbs verbs = new Verbs(plugenv);
            Console.WriteLine("goes becomes " + verbs.ComposePast("goes"));
        }
        public Phrase SynonymParaphrase(WordNetAccess.PartOfSpeech part, Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
        {
            if (word == "not" || word == "non")
                return null;    // we don't replace these!

            // Can we use a synonym?
            List<string> synonyms = wordnet.GetExactSynonyms(word, part);
            if (synonyms != null) {
                synonyms.Remove(word);
                synonyms.Remove(word.ToLower());
                // remove any synonyms more than twice as long, or half as long as the original
                List<string> onlygoods = new List<string>();
                foreach (string synonym in synonyms)
                    if (synonym.Length <= 2 * word.Length && synonym.Length >= word.Length / 2)
                        onlygoods.Add(synonym);
                synonyms = onlygoods;

                if (synonyms.Count > 0 && RemoveUnemphasizedImprobability(.75, emphasizes, this, ref prob))
                {
                    string newword = synonyms[ImprobabilityToInt(synonyms.Count, ref prob)];
                    if (IsStart(options))
                        newword = nouns.StartCap(newword);

                    POSPhrase clone = (POSPhrase) MemberwiseClone();
                    clone.word = newword;

                    return clone;
                }
            }

            return null;
        }
 public Phrase ParaphraseAsSubject(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
 {
     string asSubject = Nouns.AsSubject(Text);
     if (asSubject == Text)
         return Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
     else
         return new NounPhrase(new Noun(asSubject));
 }
 public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
 {
     Phrase synonym = SynonymParaphrase(WordNetAccess.PartOfSpeech.Adv, verbs, nouns, wordnet, options, emphasizes, ref prob);
     if (synonym == null)
         return base.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
     else
         return synonym;
 }
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
        {
            Paragraph paragraph = new Paragraph();

            foreach (Phrase constituent in constituents)
                paragraph.constituents.Add(constituent.Parapharse(verbs, nouns, wordnet, options | GrammarParser.ParaphraseOptions.IsStayingStart, emphasizes, ref prob));

            return paragraph;
        }
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
        {
            POSPhrase phrase = (POSPhrase) MemberwiseClone();
            if ((options & GrammarParser.ParaphraseOptions.MoveToStart) != GrammarParser.ParaphraseOptions.NoOptions)
                phrase.word = nouns.StartCap(phrase.word);
            else if ((options & GrammarParser.ParaphraseOptions.MoveOffStart) != GrammarParser.ParaphraseOptions.NoOptions)
                phrase.word = nouns.UnStartCap(phrase.word);

            return phrase;
        }
Exemple #7
0
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
        {
            if (this is PronounPersonal)
            {
                if (word == "I")
                    return new PronounPersonal("I");
                else
                    return base.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
            }

            Phrase synonym = SynonymParaphrase(WordNetAccess.PartOfSpeech.Noun, verbs, nouns, wordnet, options, emphasizes, ref prob);
            if (synonym == null)
                return base.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
            else
                return synonym;
        }
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double prob)
        {
            if (IsComposed(typeof(NounPhrase), typeof(Conjunction), typeof(NounPhrase)))
            {
                if (RemoveImprobability(.5, ref prob))
                {
                    Phrase first = constituents[2].Parapharse(verbs, nouns, wordnet, SubMoveToFront(options), emphasizes, ref prob);
                    Phrase and = constituents[1].Parapharse(verbs, nouns, wordnet, SubNotMoved(options), emphasizes, ref prob);
                    Phrase second = constituents[0].Parapharse(verbs, nouns, wordnet, SubMoveOffFront(options), emphasizes, ref prob);

                    return new NounPhrase(first, and, second);
                }
            }

            return base.Parapharse(verbs, nouns, wordnet, options, emphasizes, ref prob);
        }
        public ParaphraseHandler(PluginEnvironment plugenv)
            : base("Paraphrase an IParsedPhrase",
                   "Construct a new IParsedPhrase which means roughly the same thing.",
			       new string[] { "input", "prob", "opts", "emph" },
				   new string[] { "Phrase Input", "Paraphrase Improbability", "Options", "Words to Emphasize" },
				   new IArgumentType[] { GrammarParser.GrammarParseResultType,
										 new RangedArgumentType<double>(0, 1.0, .75),
										 new SelectableArgumentType(new object[] { GrammarParser.ParaphraseOptions.NoOptions, GrammarParser.ParaphraseOptions.MoveToStart, GrammarParser.ParaphraseOptions.MoveOffStart, GrammarParser.ParaphraseOptions.IsStayingStart }),
										 new EnumerableArgumentType(int.MaxValue, new StringArgumentType(4, ".+", "buffalo")) },
				   new string[] { null, null, null, null },
				   new bool[] { true, true, false, false },
                   LanguageNet.Grammarian.GrammarParser.ParaphrasingResultType, 120)
        {
            nouns = new Nouns(plugenv);
            verbs = new Verbs(plugenv);
            wordnet = new WordNetAccess(plugenv);
        }
Exemple #10
0
        // inflect a verb, appropriate to a given person for irregulars
        public string ComposePersonable(string verb, Verbs.Person person, Verbs.Convert convert)
        {
            if (Verbs.IsToBe(verb))
            {
                return(Verbs.ComposeToBe(person, convert));
            }
            if (Verbs.IsToDo(verb))
            {
                return(Verbs.ComposeToDo(person, convert));
            }
            if (Verbs.IsToHave(verb))
            {
                return(Verbs.ComposeToHave(person, convert));
            }

            if (convert == Verbs.Convert.ext_Vs && person != Verbs.Person.ThirdSingle)
            {
                return(InflectVerb(verb, Verbs.Convert.ext_V));
            }
            else
            {
                return(InflectVerb(verb, convert));
            }
        }
Exemple #11
0
        public string Represent(Memory memory, Concept within, Verbs verbs, Nouns nouns)
        {
            string[] sentence = new string[] { };
            switch (relation)
            {
                case Relations.Relation.InLocation:
                    sentence = new string[] { left.Name, RepresentToBe(memory, left, within, verbs, nouns), "in", right.Name, " ." };
                    break;
                case Relations.Relation.HasA:
                    sentence = new string[] { left.Name, RepresentToHave(memory, left, within, verbs, nouns), right.Name, " ." };
                    break;
                case Relations.Relation.HasProperty:
                    sentence = new string[] { left.Name, RepresentToBe(memory, left, within, verbs, nouns), right.Name, " ." };
                    break;
                case Relations.Relation.IsA:
                    sentence = new string[] { left.Name, RepresentToBe(memory, left, within, verbs, nouns), right.Name, " ." };
                    break;
            }

            return StringUtilities.JoinWords(new List<string>(sentence));
        }
 public VerbSubVariable(string name, Verbs verbs, string pos, Verbs.Convert inflection)
     : base(name)
 {
     this.verbs = verbs;
     this.pos = pos;
     this.inflection = inflection;
 }
 public VerbVariable(Verbs verbs)
     : base("%verb")
 {
     this.verbs = verbs;
 }
        // input is converted to base form
        Verbs.VerbType CheckVerb(ref string input, out Verbs.Convert convert)
        {
            // look it up in the verb table first
            TwoTuple<string, string> convinfo;

            if (verbsData.base_past.TryGetValue(input, out convinfo))
            {
                convert = Verbs.Convert.ext_Vs;
                if (convinfo.two == "I")
                    return Verbs.VerbType.VI;
                else if (convinfo.two == "T")
                    return Verbs.VerbType.VT;
                else
                    return Verbs.VerbType.VE;
            }

            if (input.EndsWith("s"))
            {
                convert = Verbs.Convert.ext_Vs;
                if (verbsData.verb_S.TryGetValue(input, out convinfo))
                {
                    input = convinfo.one;
                    if (convinfo.two == "I")
                        return Verbs.VerbType.VI;
                    else if (convinfo.two == "T")
                        return Verbs.VerbType.VT;
                    else
                        return Verbs.VerbType.VE;
                }
                else
                {
                    input = conjugator.SItBase(input);
                    if (verbsData.intransitive.ContainsKey(input))
                        return Verbs.VerbType.VI;
                    else if (verbsData.transitive.ContainsKey(input))
                        return Verbs.VerbType.VT;
                    else if (verbsData.either.ContainsKey(input))
                        return Verbs.VerbType.VE;
                }
            }
            else if (input.EndsWith("ing"))
            {
                convert = Verbs.Convert.ext_Ving;
                if (verbsData.verb_ING.TryGetValue(input, out convinfo))
                {
                    input = convinfo.one;
                    if (convinfo.two == "I")
                        return Verbs.VerbType.VI_ING;
                    else if (convinfo.two == "T")
                        return Verbs.VerbType.VT_ING;
                    else
                        return Verbs.VerbType.VE_ING;
                }
                else
                {
                    input = conjugator.GItBase(input);
                    if (verbsData.intransitive.ContainsKey(input))
                        return Verbs.VerbType.VI_ING;
                    else if (verbsData.transitive.ContainsKey(input))
                        return Verbs.VerbType.VT_ING;
                    else if (verbsData.either.ContainsKey(input))
                        return Verbs.VerbType.VE_ING;
                }
            }
            else
            {
                if (verbsData.past_base.TryGetValue(input, out convinfo))
                {
                    convert = Verbs.Convert.ext_Ven;
                    input = convinfo.one;
                    if (convinfo.two == "I")
                        return Verbs.VerbType.VI_EN;
                    else if (convinfo.two == "T")
                        return Verbs.VerbType.VT_EN;
                    else
                        return Verbs.VerbType.VE_EN;
                }

                if (verbsData.verb_ED.TryGetValue(input, out convinfo))
                {
                    convert = Verbs.Convert.ext_Ven;
                    input = convinfo.one;

                    if (convinfo.two == "I")
                        return Verbs.VerbType.VI_EN;
                    else if (convinfo.two == "T")
                        return Verbs.VerbType.VT_EN;
                    else
                        return Verbs.VerbType.VE_EN;
                }
                else
                {
                    if (input.EndsWith("ed") && input != "need")
                    {
                        string alt = "";
                        CheckEDVerb(ref input, out alt);

                        convert = Verbs.Convert.ext_Ven;
                        if (verbsData.intransitive.ContainsKey(input))
                            return Verbs.VerbType.VI_EN;
                        else if (verbsData.transitive.ContainsKey(input))
                            return Verbs.VerbType.VT_EN;
                        else if (verbsData.either.ContainsKey(input))
                            return Verbs.VerbType.VE_EN;

                        // first one didn't work but do we have an alternative?
                        if (alt.Length > 0)
                        {
                            if (verbsData.intransitive.ContainsKey(input))
                            {
                                input = alt;
                                return Verbs.VerbType.VI_EN;
                            }
                            else if (verbsData.transitive.ContainsKey(input))
                            {
                                input = alt;
                                return Verbs.VerbType.VT_EN;
                            }
                            else if (verbsData.either.ContainsKey(input))
                            {
                                input = alt;
                                return Verbs.VerbType.VE_EN;
                            }
                        }
                    }
                    else
                    {
                        convert = Verbs.Convert.ext_Vs;

                        if (verbsData.intransitive.ContainsKey(input))
                            return Verbs.VerbType.VI;
                        else if (verbsData.transitive.ContainsKey(input))
                            return Verbs.VerbType.VT;
                        else if (verbsData.either.ContainsKey(input))
                            return Verbs.VerbType.VE;
                    }
                }
            }

            return Verbs.VerbType.NotVerb;
        }
        //  compse a conjugation of the verb to be
        public static string ComposeToBe(Verbs.Person person, Verbs.Convert convert)
        {
            if (convert == Verbs.Convert.ext_Ved)
                return (person == Verbs.Person.FirstSingle || person == Verbs.Person.ThirdSingle) ? "was" : "were";
            if (convert == Verbs.Convert.ext_Vs)
                return person == Verbs.Person.FirstSingle ? "am" : (person == Verbs.Person.ThirdSingle ? "is" : "are");
            if (convert == Verbs.Convert.ext_Ving)
                return "being";
            if (convert == Verbs.Convert.ext_Ven)
                return "been";

            return "be";
        }
        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 VerbChoiceVariable(string name, List<string> options, PluginEnvironment plugenv, WordComparer comparer)
            : base(name, 100.0, new POSTagger(plugenv), new GrammarParser(plugenv))
        {
            this.options = options;
            this.verbs = new Verbs(plugenv);
            this.comparer = comparer;

            this.bases = new List<string>();
            foreach (string option in options)
                bases.Add(verbs.InputToBase(option));
        }
        public static Datum ConceptNetReverseTranslate(Memory memory, Verbs verbs, Concept right, Assertion assertion)
        {
            double score = 1.0 - 1.0 / (assertion.Score + 1);

            if (assertion.Type == Associator.AtLocation)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.InLocation, right, score);
            if (assertion.Type == Associator.CapableOf)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.CapableOf, right, score);
            if (assertion.Type == Associator.Causes)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.Cause, right, score);
            if (assertion.Type == Associator.CausesDesire)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.CausesDesire, right, score);
            if (assertion.Type == Associator.CreatedBy)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.CreatedBy, right, score);
            if (assertion.Type == Associator.DefinedAs)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, right.RawKind), Relation.Means, right, score);
            if (assertion.Type == Associator.Desires)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.Desires, right, score);
            if (assertion.Type == Associator.HasFirstSubevent)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.HasFirstSubevent, right, score);
            if (assertion.Type == Associator.HasLastSubevent)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.HasLastSubevent, right, score);
            if (assertion.Type == Associator.HasPainCharacter)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.HasPainCharacter, right, score);
            if (assertion.Type == Associator.HasPainIntensity)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.HasPainIntensity, right, score);
            if (assertion.Type == Associator.HasPrerequisite)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.Condition, right, score);
            if (assertion.Type == Associator.HasProperty)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.HasProperty, right, score);
            if (assertion.Type == Associator.HasSubevent)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Event), Relation.HasSubevent, right, score);
            if (assertion.Type == Associator.IsA)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, right.RawKind), Relation.IsA, right, score);
            if (assertion.Type == Associator.MadeOf)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.SubstanceMeronym, right, score);
            if (assertion.Type == Associator.MotivatedByGoal)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.MotivatedByGoal, right, score);
            if (assertion.Type == Associator.PartOf)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.PartMeronym, right, score);
            if (assertion.Type == Associator.ReceivesAction)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.ReceivesAction, right, score);
            if (assertion.Type == Associator.UsedFor)
                return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.UsedFor, right, score);

            //throw new ArgumentException("Unknown assertion type: " + assertion.Type.ToString());
            return new Datum(ConceptNetGetConcept(memory, verbs, assertion.Left, Concept.Kind.Entity), Relation.Unknown, right, score);
        }
 public static Concept ConceptNetGetConcept(Memory memory, Verbs verbs, Notion notion, Concept.Kind kind)
 {
     if (kind == Concept.Kind.Event)
         return memory.NewConcept(verbs.InputToBase(notion.Canonical), kind);
     else
         return memory.NewConcept(notion.Canonical, kind);
 }
        public static void LoadVariables(Context context, double salience, Memory memory, ConceptTranslator produceTranslator, Verbs verbs, Nouns nouns, PluginEnvironment plugenv)
        {
            POSTagger tagger = new POSTagger(plugenv);
            GrammarParser parser = new GrammarParser(plugenv);

            context.Map.Add("@know", new KnowRule(salience, memory, tagger, parser));
            context.Map.Add("@event", new EventRule(salience, memory, tagger, parser));

            context.Map.Add("@Subject", new SimpleDatumRule(salience, Relations.Relation.Subject, memory, produceTranslator, tagger, parser));
            context.Map.Add("@Object", new SimpleDatumRule(salience, Relations.Relation.Object, memory, produceTranslator, tagger, parser));
            context.Map.Add("@Indirect", new SimpleDatumRule(salience, Relations.Relation.Indirect, memory, produceTranslator, tagger, parser));
            context.Map.Add("@IsA", new SimpleDatumRule(salience, Relations.Relation.IsA, memory, produceTranslator, tagger, parser));
            context.Map.Add("@HasProperty", new SimpleDatumRule(salience, Relations.Relation.HasProperty, memory, produceTranslator, tagger, parser));
            context.Map.Add("@Means", new SimpleDatumRule(salience, Relations.Relation.Means, memory, produceTranslator, tagger, parser));
            context.Map.Add("@Condition", new SimpleDatumRule(salience, Relations.Relation.Condition, memory, produceTranslator, tagger, parser));
            context.Map.Add("@MotivatedBy", new SimpleDatumRule(salience, Relations.Relation.MotivatedByGoal, memory, produceTranslator, tagger, parser));
            context.Map.Add("@Exists", new SimpleDatumRule(salience, Relations.Relation.Exists, memory, produceTranslator, tagger, parser));
            context.Map.Add("@UsedFor", new SimpleDatumRule(salience, Relations.Relation.UsedFor, memory, produceTranslator, tagger, parser));
            context.Map.Add("@AtTime", new AtTimeRule(salience, memory, tagger, parser));
            context.Map.Add("@InLocation", new InLocationRule(salience, memory, verbs, tagger, parser));

            //context.Map.Add("@ActiveObjects", new AllObjectsRule(salience, true, memory, produceTranslator, tagger, parser));
            //context.Map.Add("@PassiveObjects", new AllObjectsRule(salience, false, memory, produceTranslator, tagger, parser));

            context.Map.Add("@EntityPrep", new EntityPrepRule(salience, memory, verbs, tagger, parser));
            context.Map.Add("@SubjectTense", new TenseRule(salience, Relations.Relation.Subject, memory, verbs, nouns, tagger, parser));

            context.Map.Add("%unknown", new UnknownConceptVariable("%unknown", null));
            context.Map.Add("%unevent", new UnknownConceptVariable("%unevent", Concept.Kind.Event));
            context.Map.Add("%unthing", new UnknownConceptVariable("%unthing", Concept.Kind.Entity));
            context.Map.Add("%unquality", new UnknownConceptVariable("%unquality", Concept.Kind.Attribute));
        }
        public string Handle(string verb, Verbs.Convert convert)
        {
            verb = InputToBase(verb);

            if (verb == "shall" || verb == "should" || verb == "will" ||
                verb == "would" || verb == "may" || verb == "might" ||
                verb == "can" || verb == "could" || verb == "must")
                return verb;

            switch (convert)
            {
                case Verbs.Convert.ext_V:
                    return verb;

                case Verbs.Convert.ext_Vs:
                    return ComposePresent(verb);

                case Verbs.Convert.ext_Ving:
                    return ComposePrespart(verb);

                case Verbs.Convert.ext_Ved:
                    return ComposePast(verb);

                case Verbs.Convert.ext_Ven:
                    return ComposePastpart(verb);
            }

            return verb;
        }
        // inflect a verb, appropriate to a given person for irregulars
        public string ComposePersonable(string verb, Verbs.Person person, Verbs.Convert convert)
        {
            if (Verbs.IsToBe(verb))
                return Verbs.ComposeToBe(person, convert);
            if (Verbs.IsToDo(verb))
                return Verbs.ComposeToDo(person, convert);
            if (Verbs.IsToHave(verb))
                return Verbs.ComposeToHave(person, convert);

            if (convert == Verbs.Convert.ext_Vs && person != Verbs.Person.ThirdSingle)
                return InflectVerb(verb, Verbs.Convert.ext_V);
            else
                return InflectVerb(verb, convert);
        }
        // compase a conjugation of the verb to have
        public static string ComposeToHave(Verbs.Person person, Verbs.Convert convert)
        {
            if (convert == Verbs.Convert.ext_Ved)
                return "had";
            if (convert == Verbs.Convert.ext_Vs)
                return (person == Verbs.Person.ThirdSingle) ? "has" : "have";
            if (convert == Verbs.Convert.ext_Ving)
                return "having";
            if (convert == Verbs.Convert.ext_Ven)
                return "had";

            return "have";
        }
        // compose a conjugation of the verb to do
        public static string ComposeToDo(Verbs.Person person, Verbs.Convert convert)
        {
            if (convert == Verbs.Convert.ext_Ved)
                return "did";
            if (convert == Verbs.Convert.ext_Vs)
                return person == Verbs.Person.ThirdSingle ? "does" : "do";
            if (convert == Verbs.Convert.ext_Ving)
                return "doing";
            if (convert == Verbs.Convert.ext_Ven)
                return "done";

            return "do";
        }
Exemple #25
0
 public static string RepresentToHave(Memory memory, Concept concept, Concept within, Verbs verbs, Nouns nouns)
 {
     return Verbs.ComposeToHave(nouns.GetPerson(concept.Name), GetTense(concept, within, memory));
 }
 public VerbSubDeclination(Verbs verbs, string pos, Verbs.Convert inflection)
 {
     this.verbs = verbs;
     this.pos = pos;
     this.inflection = inflection;
 }
        public static IParsedPhrase ConjugateToPhrase(Memory memory, IrregularVerbVariable.ConjugateVerb conjugate, Verbs.Person person, Concept right)
        {
            if (right == memory.past)
                return new WordPhrase(conjugate(person, Verbs.Convert.ext_Ved), "VBD");
            else if (right == memory.now)
                return new WordPhrase(conjugate(person, Verbs.Convert.ext_Vs), "VBZ");
            else if (right == memory.future)
                return new WordPhrase("will " + conjugate(person, Verbs.Convert.ext_V), "VB");

            List<string> parts = StringUtilities.SplitWords(right.Name, true);
            bool usedverb = false;
            for (int ii = 0; ii < parts.Count; ii++)
            {
                if (parts[ii] == "en")
                {
                    parts[ii] = conjugate(person, Verbs.Convert.ext_Ven);
                    usedverb = true;
                }
                else if (parts[ii] == "ing")
                {
                    parts[ii] = conjugate(person, Verbs.Convert.ext_Ving);
                    usedverb = true;
                }
            }
            if (!usedverb)
                parts.Add(conjugate(person, Verbs.Convert.ext_V));

            List<IParsedPhrase> branches = new List<IParsedPhrase>();
            branches.Add(new WordPhrase(StringUtilities.JoinWords(parts), "VB"));
            return new GroupPhrase("VP", branches);
        }
        public static string ConjugateToTense(Memory memory, string verb, Verbs.Person person, Concept right, Verbs verbs)
        {
            if (right == memory.past)
                return verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ved);
            if (right == memory.now)
                return verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Vs);
            if (right == memory.future)
                return "will " + verbs.ComposePersonable(verb, person, Verbs.Convert.ext_V);

            List<string> parts = StringUtilities.SplitWords(right.Name, true);
            bool usedverb = false;
            for (int ii = 0; ii < parts.Count; ii++)
            {
                if (parts[ii] == "en") {
                    parts[ii] = verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ven);
                    usedverb = true;
                }
                else if (parts[ii] == "ing") {
                    parts[ii] = verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ving);
                    usedverb = true;
                }
            }
            if (!usedverb)
                parts.Add(verbs.InputToBase(verb));
            return StringUtilities.JoinWords(parts);
        }
 public InLocationRule(double salience, Memory memory, Verbs verbs, POSTagger tagger, GrammarParser parser)
     : base(ArgumentMode.ManyArguments, salience, 3 * 4, 10, tagger, parser)
 {
     this.memory = memory;
     this.verbs = verbs;
     this.tagger = tagger;
 }
 public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double inprob)
 {
     return (Phrase) MemberwiseClone();
 }
        public TenseRule(double salience, Relations.Relation nounrel, Memory memory, Verbs verbs, Nouns nouns, POSTagger tagger, GrammarParser parser)
            : base(ArgumentMode.ManyArguments, salience, 2 * 4, 10, tagger, parser)
        {
            this.nounrel = nounrel;

            this.memory = memory;
            this.verbs = verbs;
            this.nouns = nouns;
        }