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"));
        }
        // Resolve all unknown (i.e., ??) part of speech typed words in the parsed phrases
        public List <KeyValuePair <string, string> > ResolveUnknowns(List <IParsedPhrase> phrases)
        {
            if (plugenv != null)
            {
                IEnumerable <string> parts = (IEnumerable <string>)plugenv.ImmediateConvertTo(phrases, TagEnumerationResultType, 2, 1000 * phrases.Count);

                List <string> words = new List <string>();
                foreach (IParsedPhrase phrase in phrases)
                {
                    words.AddRange(GrammarParser.GetWords(phrase));
                }

                List <KeyValuePair <string, string> > tokens = new List <KeyValuePair <string, string> >();
                int ii = 0;
                foreach (string part in parts)
                {
                    tokens.Add(new KeyValuePair <string, string>(words[ii++], part));
                }

                return(tokens);
            }

            // no plugin environment?  do nothing
            return(GetLowestLevel(phrases));
        }
 public CorrectSpellingsRescueMatch(TryToRescueMatch fallback, SpellingBeeWordComparer comparer, GrammarParser parser, double weight)
 {
     this.fallback = fallback;
     this.comparer = comparer;
     this.parser = parser;
     this.weight = weight;
 }
Example #4
0
        public virtual IParsedPhrase ConceptToPhrase(Context context, Concept concept, POSTagger tagger, GrammarParser parser)
        {
            if (concept.IsUnknown)
                return null;

            return concept.ToPhrase(tagger, parser);
        }
        public static string ContentsCode(Context context, POSTagger tagger, GrammarParser parser)
        {
            StringBuilder result = new StringBuilder();
            foreach (IContent content in context.Contents)
            {
                string name = content.Name;

                if (content is Variable)
                {
                    IParsedPhrase phrase = ((Variable)content).Produce(context, tagger, parser);
                    if (phrase != null)
                        name = phrase.Text;
                }

                if (name[0] == ' ')
                    result.Append(name.Substring(1));
                else
                {
                    if (result.Length > 0)
                        result.Append(" ");
                    result.Append(name);
                }
            }

            return result.ToString();
        }
 public MatchProduceAgent(ArgumentMode argmode, double salience, int space, int time, POSTagger tagger, GrammarParser parser)
     : base(argmode, salience, space, time)
 {
     this.tagger = tagger;
     this.parser = parser;
     this.breakpointCall = false;
 }
        public static List<IContent> Produced(Context context, POSTagger tagger, GrammarParser parser)
        {
            List<IContent> result = new List<IContent>();
            foreach (IContent content in context.Contents)
            {
                if (content is Word)
                    result.Add(content);
                else if (content is Special && (content.Name.StartsWith("*") || content.Name.StartsWith("_")))
                {
                    List<IContent> words = GetStarValue(context, content.Name);
                    result.AddRange(words);
                }
                else if (content is Variable)
                {
                    IParsedPhrase phrase = ((Variable)content).Produce(context, tagger, parser);
                    if (phrase == null)
                        return null;    // we failed!  don't use it!

                    List<string> words = GroupPhrase.PhraseToTexts(phrase);
                    foreach (string word in words)
                        result.Add(new Word(word));
                }
                else
                    result.Add(content);
            }

            return result;
        }
        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));
 }
Example #10
0
 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;
 }
Example #11
0
        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 static bool PrintContents(Context context, IContinuation succ, IFailure fail, params object[] args)
        {
            PluginEnvironment plugenv = (PluginEnvironment) args[0];
            POSTagger tagger = new POSTagger(plugenv);
            GrammarParser parser = new GrammarParser(plugenv);

            Console.WriteLine(StarUtilities.ProducedCode(context, tagger, parser));
            succ.Continue(new Context(context, new List<IContent>()), fail);
            return true;
        }
Example #13
0
        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;
        }
        public ConceptRelation(double salience, PluginEnvironment plugenv, string relation, POSTagger tagger, GrammarParser parser)
            : base(ArgumentMode.ManyArguments, salience, 4, 100)
        {
            this.relation = relation;
            this.tagger = tagger;
            this.parser = parser;

            // Look up the datasources for ConceptNet
            principleSource = plugenv.GetDataSource<string, Notion>(ConceptNetUtilities.PrincipleSourceName);
            assertionSource = plugenv.GetDataSource<KeyValuePair<Notion, string>, List<Assertion>>(ConceptNetUtilities.AssertionSourceName);
        }
        public Phrase Handle(Phrase input, GrammarParser.ParaphraseOptions? opts, List<string> emph, double prob)
        {
            if (opts == null)
                opts = GrammarParser.ParaphraseOptions.NoOptions;

            List<Phrase> emphasizes = new List<Phrase>();
            if (emph != null) {
                foreach (string word in emph)
                    emphasizes.AddRange(input.FindPhrases(word));
            }

            return input.Parapharse(verbs, nouns, wordnet, opts.Value, emphasizes, ref prob);
        }
Example #16
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 static void LoadVariables(Context context, PluginEnvironment plugenv, double basesal, POSTagger tagger)
 {
     GrammarParser parser = new GrammarParser(plugenv);
     context.Map.Add("%AtLocation", new ConceptRelation(basesal, plugenv, "AtLocation", tagger, parser));
     context.Map.Add("%DefinedAs", new ConceptRelation(basesal, plugenv, "DefinedAs", tagger, parser));
 }
 public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List<Phrase> emphasizes, ref double inprob)
 {
     return (Phrase) MemberwiseClone();
 }
Example #20
0
        public void Initialize(string config)
        {
            plugenv = new PluginEnvironment(this);
            if (!File.Exists(config)) {
                Console.WriteLine("Cannot find configuration file at " + config);
                return;
            }

            plugenv.Initialize(config, new NameValueCollection());

            tagger = new POSTagger(plugenv);
            parser = new GrammarParser(plugenv);

            coderack = new ZippyCoderack(this, 10000000);
            memory = new Memory();

            basectx = new Context(coderack);
            GrammarVariables.LoadVariables(basectx, 100.0, memory, plugenv);
            OutputVariables.LoadVariables(basectx, 100.0, plugenv);
            ProgramVariables.LoadVariables(basectx, 100.0, plugenv);
            basectx.Map.Add("$Compare", new WordComparer());

            initialized = true;
        }
 public EventRule(double salience, Memory memory, POSTagger tagger, GrammarParser parser)
     : base(salience, memory, tagger, parser)
 {
 }
 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 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 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 static IParsedPhrase ProducedPhrase(Context context, POSTagger tagger, GrammarParser parser)
        {
            List<IParsedPhrase> phrases = new List<IParsedPhrase>();
            foreach (IContent content in context.Contents)
            {
                if (content is Word)
                    phrases.Add(new WordPhrase(content.Name));
                else if (content is Special && (content.Name.StartsWith("*") || content.Name.StartsWith("_")))
                {
                    List<IContent> words = GetStarValue(context, content.Name);
                    foreach (IContent word in words)
                        phrases.Add(new WordPhrase(content.Name));
                }
                else if (content is Variable) {
                    IParsedPhrase phrase = ((Variable)content).Produce(context, tagger, parser);
                    if (phrase == null)
                        return null;    // failed!
                    phrases.Add(phrase);
                }
                else if (content is Concept)
                    phrases.Add(new WordPhrase(((Concept)content).Name));
                else
                    phrases.Add(new WordPhrase(content.Name));
            }

            if (phrases.Count == 0)
                return null;

            List<KeyValuePair<string, string>> tokens = tagger.ResolveUnknowns(phrases);
            return parser.Parse(tokens);
        }
        public static string ProducedCode(Context context, POSTagger tagger, GrammarParser parser)
        {
            List<IContent> produced = Produced(context, tagger, parser);
            if (produced == null)
                return null;

            return ContentsCode(new Context(context, produced), tagger, parser);
        }
 public KnowRule(double salience, Memory memory, POSTagger tagger, GrammarParser parser)
     : base(ArgumentMode.ManyArguments, salience, 2 * 4, 3, tagger, parser)
 {
     this.memory = memory;
     this.tagger = tagger;
 }
 public SimpleDatumRule(double salience, Relations.Relation kind, Memory memory, ConceptTranslator produceTranslator, POSTagger tagger, GrammarParser parser)
     : base(ArgumentMode.ManyArguments, salience, 3 * 4, 10, tagger, parser)
 {
     this.kind = kind;
     this.memory = memory;
     this.produceTranslator = produceTranslator;
     this.tagger = tagger;
 }
        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;
        }
Example #30
0
        public virtual IParsedPhrase Produce(Context env, POSTagger tagger, GrammarParser parser)
        {
            object var = env.LookupDefaulted<object>("$p$" + name, null);
            if (var is ThreeTuple<GetValue, object, object[]>)
            {
                ThreeTuple<GetValue, object, object[]> tuple = (ThreeTuple<GetValue, object, object[]>)var;
                var = tuple.one(tuple.two, tuple.three);
            }

            if (var is IParsedPhrase)
                return (IParsedPhrase)var;
            else if (var is Concept)
                return ConceptToPhrase(env, (Concept)var, tagger, parser);

            return null;    // don't produce anything!
        }
 public ProgressiveVariableAgent(string name, double salience, POSTagger tagger, GrammarParser parser)
     : base(ArgumentMode.NoArugments, salience, 10, 10, tagger, parser)
 {
     this.name = name;
 }