public Ranked <IEnumerable <NodeReference> > GetRankedAnswer(string question, ContextPool pool)
        {
            //keep original pool non-modified
            pool = pool.Clone();

            var parsedQuestion = UtteranceParser.Parse(question);
            var covers         = FeatureCover.GetFeatureCovers(parsedQuestion, Graph);

            var interpretations = _mapping.GetRankedInterpretations(covers);
            var bestMatch       = interpretations.BestMatch;

            if (bestMatch.Value == null)
            {
                //no interpretation has been found
                return(new Ranked <IEnumerable <NodeReference> >(new NodeReference[0], 0.0));
            }

            var bestInterpretation         = bestMatch.Value.Item2.Interpretation;
            var bestCover                  = bestMatch.Value.Item1;
            var instantiatedInterpretation = bestInterpretation.InstantiateBy(bestCover, Graph);

            //run the interpretation on the pool
            Console.WriteLine("\n");
            foreach (var rule in instantiatedInterpretation.Rules)
            {
                rule.Execute(pool);
                Console.WriteLine(rule);
                Console.WriteLine("POOL: " + string.Join(" ", pool.ActiveNodes));
            }

            return(new Ranked <IEnumerable <NodeReference> >(pool.ActiveNodes, bestMatch.Rank));
        }
        internal void AdviceAnswer(string question, NodeReference answer)
        {
            var parsedQuestion = UtteranceParser.Parse(question);

            foreach (var featureCover in FeatureCover.GetFeatureCovers(parsedQuestion, Graph))
            {
                register(featureCover, answer);
            }
        }
Esempio n. 3
0
        internal NodeReference GetAnswer(ParsedUtterance expression)
        {
            var covers = FeatureCover.GetFeatureCovers(expression, Graph);

            var allRankedMappings = new List <Ranked <ContextRuleMapping> >();

            foreach (var cover in covers)
            {
                var rankedMappings = _mapping.GetRankedMappings(cover);
                allRankedMappings.AddRange(rankedMappings);
            }

            throw new NotImplementedException();
        }
Esempio n. 4
0
        protected override bool adviceAnswer(string question, bool isBasedOnContext, NodeReference correctAnswerNode, IEnumerable <NodeReference> context)
        {
            var parsedQuestion = UtteranceParser.Parse(question);

            var interpretationsFactory = getInterpretationsFactory(parsedQuestion, isBasedOnContext, correctAnswerNode, context);

            var covers = FeatureCover.GetFeatureCovers(parsedQuestion, Graph);

            _mapping.Add(interpretationsFactory, covers);

            //TODO decide whether it would be benefitial to report that
            //the advice is taken into account, however we don't believe it much.
            return(true);
        }
        private FeatureCover getMatchingCover(string question, FeatureKey key)
        {
            var parsedQuestion = UtteranceParser.Parse(question);

            foreach (var cover in FeatureCover.GetFeatureCovers(parsedQuestion, Graph))
            {
                if (key.Equals(cover.FeatureKey))
                {
                    return(cover);
                }
            }

            return(null);
        }
        internal IEnumerable <FeatureEvidence> GetEvidences(string question)
        {
            var result         = new List <FeatureEvidence>();
            var parsedQuestion = UtteranceParser.Parse(question);

            foreach (var featureCover in FeatureCover.GetFeatureCovers(parsedQuestion, Graph))
            {
                if (_featureEvidences.ContainsKey(featureCover.FeatureKey))
                {
                    result.Add(_featureEvidences[featureCover.FeatureKey]);
                }
            }

            return(result);
        }
        protected override bool adviceAnswer(string question, bool isBasedOnContext, NodeReference correctAnswerNode, IEnumerable <NodeReference> context)
        {
            var parsedQuestion = UtteranceParser.Parse(question);
            var covers         = FeatureCover.GetFeatureCovers(parsedQuestion, Graph);

            //setup interpretation generator
            var factory = new InterpretationsFactory(parsedQuestion, isBasedOnContext, correctAnswerNode);

            var contextPool = new ContextPool(Graph);

            contextPool.Insert(context.ToArray());

            var generator = new InterpretationGenerator(covers, factory, contextPool, this);

            //!!!!!!!!!!!!!!TODOOOOOOOOOOOOO!!!!!!!!!!!!!!
            //We have to check compatibility of the generator with all known interpretations
            _interpretationGenerators.Add(generator);

            //register covers according to its feature keys
            foreach (var cover in generator.Covers)
            {
                List <Tuple <InterpretationGenerator, FeatureCover> > generators;
                if (!_keyToGeneratorCovers.TryGetValue(cover.FeatureKey, out generators))
                {
                    _keyToGeneratorCovers[cover.FeatureKey] = generators = new List <Tuple <InterpretationGenerator, FeatureCover> >();
                }

                generators.Add(Tuple.Create(generator, cover));
            }

            //TODO decide whether it would be benefitial to report that
            //the advice is taken into account, however we don't believe it much.

            //TODO initialize with first interpretation?
            return(true);
        }