Example #1
0
 public Datum(Datum parent)
 {
     left = parent.left;
     relation = parent.relation;
     right = parent.right;
     score = parent.score;
 }
        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 static List<Datum> GetConnectedStructure(Memory memory, Datum start)
        {
            List<Datum> structure = new List<Datum>();
            structure.Add(start);

            // 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 (!structure.Contains(datum))
                    {
                        structure.Add(datum);

                        pending.Enqueue(datum.Left);
                        pending.Enqueue(datum.Right);
                    }
                }
            }

            return structure;
        }
Example #4
0
 public Thinker(double salience, Memory memory, List<Relations.Relation> kinds, Datum check, IContinuation succ)
     : base(salience, 4 * 7, timeEach, succ)
 {
     this.memory = memory;
     this.kinds = kinds;
     directchecks = new List<Datum>();
     directchecks.Add(check);
     parentchecks = new Queue<Concept>();
     parentchecks.Enqueue(check.Left);
     parentchecks.Enqueue(check.Right);
 }
        public static bool KnowPhrase(IParsedPhrase phrase, Context context, Memory memory)
        {
            GroupPhrase groupPhrase = new GroupPhrase(phrase);
            IParsedPhrase datetime = groupPhrase.GetBranch(1);

            Datum datum = new Datum(null, Relations.Relation.AtTime, memory.NewConcept(datetime), context.Weight);

            context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);

            return true;
        }
        public override bool Produce(Context context, IContinuation succ, IFailure fail)
        {
            string word = StarUtilities.ProducedCode(context, tagger, parser);
            Datum datum;

            if (word == "past")
                datum = new Datum(null, Relations.Relation.Tense, memory.past, context.Weight);
            else if (word.Contains(" "))
                datum = new Datum(null, Relations.Relation.Tense, memory.NewConcept(word, Concept.Kind.Entity), context.Weight);
            else
            {
                bool isPast = verbs.GetInflection(word) == Verbs.Convert.ext_Ved;
                if (isPast)
                    datum = new Datum(null, Relations.Relation.Tense, memory.past, context.Weight);
                else
                    datum = new Datum(null, Relations.Relation.Tense, memory.now, context.Weight);
            }

            context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);

            succ.Continue(new Context(context, new List<IContent>()), fail);
            return true;
        }
Example #7
0
 public static void SearchForMatch(double salience, Memory memory, List<Relations.Relation> kinds, Datum check, Context context, IContinuation succ, IFailure fail)
 {
     Thinker thinker = new Thinker(salience, memory, kinds, check, succ);
     thinker.Continue(context, fail);
 }
Example #8
0
        public Datum Know(Datum datum)
        {
            data[datum.Left].Add(datum);
            data[datum.Right].Add(datum);

            center = datum;
            return datum;
        }
Example #9
0
 public Datum Know(Concept left, Datum partial)
 {
     return Know(new Datum(left, partial.Relation, partial.Right, partial.Score));
 }
Example #10
0
        public Datum IsKnown(Datum datum)
        {
            // Is this datum represented?
            BestScore<Datum> match = new BestScore<Datum>();
            foreach (Datum check in GetData(datum.Left))
                if (datum.Relation == check.Relation)
                    match.Improve(datum.Right.SeemsSimilar(check.Right).ToDouble(1.0), check);

            return match.Payload;
        }
Example #11
0
 public static void SearchForMatch(double salience, Memory memory, List<Relations.Relation> kinds, Datum check, Context context, IContinuation succ, IFailure fail, Variable.GetValue propfunc, params object[] propargs)
 {
     Thinker thinker = new Thinker(salience, memory, kinds, check, succ, propfunc, propargs);
     thinker.Continue(context, fail);
 }
Example #12
0
        // Merge and remove old
        public void Merge(Datum old, Memory memory)
        {
            if (old.score > score)
                ChangeScore(old.score);

            List<Datum> dataLeft = memory.GetData(old.left);
            if (dataLeft != null)
                dataLeft.Remove(old);
            List<Datum> dataRight = memory.GetData(old.right);
            if (dataRight != null)
                dataRight.Remove(old);
            // Make this datum reflect other (in case we're in the middle of a save)
            old.left = left;
            old.right = right;
        }
Example #13
0
        public double IsSameUnder(Datum datum, Concept before, Concept after)
        {
            if ((left == datum.left || (left == before && datum.left == after)) &&
                (right == datum.right || (right == before && datum.right == after)) &&
                (relation == datum.relation))
                return 1.0 - Math.Abs(score - datum.score) / (score + datum.score);

            return 0.0;
        }
Example #14
0
 public Thinker(double salience, Memory memory, List<Relations.Relation> kinds, Datum check, IContinuation succ, Variable.GetValue propfunc, params object[] propargs)
     : this(salience, memory, kinds, check, succ)
 {
     this.propfunc = propfunc;
     this.propargs = propargs;
 }
        public override bool Produce(Context context, IContinuation succ, IFailure fail)
        {
            IParsedPhrase other = StarUtilities.ProducedPhrase(context, tagger, parser);
            if (other == null)
            {
                succ.Continue(new Context(context, new List<IContent>()), fail);
                return true; // cannot do!
            }

            Concept concept = produceTranslator.GetConcept(other);

            Datum datum = new Datum(null, kind, concept, context.Weight);

            context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);

            succ.Continue(new Context(context, new List<IContent>()), fail);
            return true;
        }
        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 static bool KnowPhrase(IParsedPhrase phrase, Context context, Memory memory)
        {
            if (phrase.Part == "PP")
            {
                Datum datum = new Datum(null, Relations.Relation.InLocation, memory.NewConcept(phrase), context.Weight);

                context.LookupAndAdd<List<Datum>>("$knowPartials", new List<Datum>()).Add(datum);

                return true;
            }

            return false;
        }