private IEnumerable <NodeReference> evaluate(StructuredInterpretation interpretation, QuestionEvidence question) { HashSet <NodeReference> inputSet = null; for (var i = 0; i < _generalFeatureNodes.Length; ++i) { var generalNode = _generalFeatureNodes[i]; var featureNode = question.GetFeatureNode(generalNode, Graph); var constraint = interpretation.GetGeneralConstraint(i); if (inputSet == null) { inputSet = constraint.FindSet(featureNode, Graph); } else { inputSet.IntersectWith(constraint.FindSet(featureNode, Graph)); } } var pool = new ContextPool(Graph); pool.Insert(inputSet.ToArray()); foreach (var distinguishConstraint in interpretation.DisambiguationConstraints) { distinguishConstraint.Execute(pool); } return(pool.ActiveNodes); }
internal IEnumerable <NodeReference> Evaluate(string question, StructuredInterpretation structuredInterpretation) { var matchingCover = getMatchingCover(question, structuredInterpretation.FeatureKey); var constraints = structuredInterpretation.GeneralConstraints.Zip(matchingCover.GetInstanceNodes (Graph), Tuple.Create); HashSet <NodeReference> topicNodes = null; foreach (var constraint in constraints) { var constraintSet = constraint.Item1.FindSet(constraint.Item2, Graph); if (topicNodes == null) { topicNodes = constraintSet; } else { topicNodes.IntersectWith(constraintSet); } } var pool = new ContextPool(Graph); pool.Insert(topicNodes.ToArray()); foreach (var constraint in structuredInterpretation.DisambiguationConstraints) { constraint.Execute(pool); } return(pool.ActiveNodes); }
private HashSet <NodeReference> findRemainingNodes(ConstraintPoolRule rule) { var pool = new ContextPool(Graph); //TODO optimize filling the pool pool.Insert(_originalRemainingNodes.ToArray()); rule.Execute(pool); //take only those remaining nodes which have been selected var remainingNodes = new HashSet <NodeReference>(pool.ActiveNodes); return(remainingNodes); }
private double generalizationScore(StructuredInterpretation interpretation) { HashSet <NodeReference> topicNodes = null; for (var i = 0; i < _generalFeatureNodes.Length; ++i) { var generalNode = _generalFeatureNodes[i]; var constraint = interpretation.GetGeneralConstraint(i); var nodeDomain = getInstanceDomain(generalNode); var topicalizedDomain = getConstrainedLayer(nodeDomain, constraint); if (topicNodes == null) { topicNodes = new HashSet <NodeReference>(); } else { topicNodes.IntersectWith(nodeDomain); } } var pool = new ContextPool(Graph); pool.Insert(topicNodes.ToArray()); foreach (var constraint in interpretation.DisambiguationConstraints) { constraint.Execute(pool); } var topicNodesCount = topicNodes.Count + 1; var generalizationBonus = 1.0 * pool.ActiveCount / topicNodesCount; var generalizationRatio = 1 - 1.0 / topicNodesCount; return(generalizationRatio * generalizationBonus); }
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); }
public void Run(ContextPool context) { context.ClearAccumulator(); context.Insert(Node); }
/// <inheritdoc/> protected override void execute(ContextPool pool) { pool.ClearAccumulator(); pool.Insert(_insertedNode); }