示例#1
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);
        }
        protected static PairResult MatchOneRow(T todo, object objshr)
        {
            MatchShared   shared     = (MatchShared)objshr;
            BestScore <T> one_to_all = new BestScore <T>();

            // start by looking at all results for one's row
            foreach (T two in shared.twos)
            {
                double score = shared.comparisons.Evaluate(new TwoTuple <T, T>(todo, two), shared);
                one_to_all.Improve(score, two);
            }

            if (one_to_all.payload == null || one_to_all.payload.Equals(default(T)))
            {
                // no more results!  Return empty match.
                shared.ones = new SkipEnumerable <T>(shared.ones, todo);
                return(new PairResult(double.NegativeInfinity, todo, default(T)));
            }

            // Now look at all other entries in that column
            BestScore <T> match_to_others = new BestScore <T>(one_to_all.score, todo);

            foreach (T one in shared.ones)
            {
                if (!one.Equals(todo))
                {
                    double score = shared.comparisons.Evaluate(new TwoTuple <T, T>(one, one_to_all.payload), shared);
                    match_to_others.Improve(score, one);
                }
            }

            if (match_to_others.payload.Equals(todo))
            {
                // remove this row and column
                shared.ones = new SkipEnumerable <T>(shared.ones, todo);
                shared.twos = new SkipEnumerable <T>(shared.twos, one_to_all.payload);
                return(new PairResult(one_to_all.score, todo, one_to_all.payload));
            }
            else
            {
                // First do the row we found!
                shared.matches.Evaluate(match_to_others.payload, shared);
                // Then do this one again!
                return(MatchOneRow(todo, shared));
            }
        }
        // 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);
        }