public static Datum GetClosestDatum(Memory memory, Datum start, Relations.Relation relation) { // these are concepts we need to (or did) look up the data for List<Concept> processed = new List<Concept>(); Queue<Concept> pending = new Queue<Concept>(); pending.Enqueue(start.Left); pending.Enqueue(start.Right); while (pending.Count > 0) { Concept concept = pending.Dequeue(); if (concept.IsSpecial || processed.Contains(concept)) continue; processed.Add(concept); List<Datum> data = memory.GetData(concept); foreach (Datum datum in data) { if (datum.Relation == relation) return datum; pending.Enqueue(datum.Left); pending.Enqueue(datum.Right); } } return null; }
public Datum(Concept left, Relations.Relation relation, Concept right, double score) { this.left = left; this.relation = relation; this.right = right; this.score = score; }
public Datum Know(Concept left, Relations.Relation relation, IEnumerable<Concept> rights, double score) { Datum last = null; foreach (Concept right in rights) last = Know(new Datum(left, relation, right, score)); return last; }
public Datum Know(Concept left, Relations.Relation relation, Concept right, double score) { return Know(new Datum(left, relation, right, score)); }
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; }
public static void Know(Memory memory, Context context, Relations.Relation kind, IParsedPhrase phrase, double weight, ConceptTranslator produceTranslator) { Concept concept = produceTranslator.GetConcept(phrase); Datum datum = new Datum(null, kind, concept, weight); context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum); }
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; }
// refine should not be equality-- we could go in circles public double HasRelationTo(Memory memory, Concept find, Relations.Relation relation, Relations.Relation refine) { List<Datum> data = memory.GetData(this); BestScore<Datum> bestConnect = new BestScore<Datum>(0.0, null); foreach (Datum datum in data) { if (datum.Relation == relation && datum.Right == find) return datum.Score; if (datum.Relation == relation || datum.Relation == refine) bestConnect.Improve(datum.Right.HasRelationTo(memory, find, relation, refine) * datum.Score, datum); } return bestConnect.Score; }