protected override IEnumerable <string> execute(BeamGenerator generator) { var definedConcepts = new HashSet <Concept2>(generator.GetDefinedConcepts()); var conceptWithAssignedProperty = Get <PropertySetEvent>((s) => hasExtraInformation(s, definedConcepts, generator)); if (conceptWithAssignedProperty == null) { yield break; } var target = conceptWithAssignedProperty.Target; var rememberValue = RememberPropertyValue.Create(generator, target, conceptWithAssignedProperty.SubstitutedValue); YesNoPrompt.Generate(generator, rememberValue, new ConceptInstance(Concept2.Nothing)); yield return($"You think that {singular(target.Instance)} has {singular(conceptWithAssignedProperty.SubstitutedValue)} {singular(target.Property)}?"); }
protected override IEnumerable <string> execute(BeamGenerator generator) { var unknownPhrases = GetUnknownPhrases(generator); if (!PreviousPolicy <RequestRefinement>(out var refinementPolicy) || unknownPhrases.Count() != 1) { yield break; } var instanceToRefine = generator.GetValue(refinementPolicy.Tag, Concept2.Target); var unknown = unknownPhrases.First(); var assignUnknownProperty = AssignUnknownProperty.Create(instanceToRefine, unknown, generator); YesNoPrompt.Generate(generator, assignUnknownProperty, instanceToRefine); yield return($"I suppose, you would like to find {plural(instanceToRefine)} which are {unknown}?"); }
protected override IEnumerable <string> execute(BeamGenerator generator) { var evt = Get <InstanceOutputEvent>(); if (evt?.Instance.Concept != Concept2.NeedsRefinement) { yield break; } var instanceToRefine = generator.GetValue(evt.Instance, Concept2.Subject); var activationTarget = generator.GetValue(evt.Instance, Concept2.Target); var prefixesForRefine = generator.GetPrefixingUnknowns(instanceToRefine); if (!prefixesForRefine.TryGetValue(instanceToRefine, out var propertyUnknownRaw)) { //nothing to ask for yield break; } var propertyUnknown = toMeaningfulPhrase(propertyUnknownRaw); if (propertyUnknown == "") { yield break; } /* * //TODO feature based questions * * //ACTION SEQUENCE * //Do you want X which is UNKNOWN ? * Prompt * //-yes: what property UNKNOWN is ? * yes -> expect (properties) * //-- expect property * * //-no: So which X you want ? * no -> ? * //--standard refinement * * * yield return $"I know many {plural(instanceToRefine)} which one would you like?";*/ var assignUnknownProperty = AssignUnknownProperty.Create(instanceToRefine, propertyUnknown, generator); YesNoPrompt.Generate(generator, assignUnknownProperty, instanceToRefine); yield return($"So, you would like to find {plural(instanceToRefine)} which are {propertyUnknown}?"); }
protected override IEnumerable <string> execute(BeamGenerator generator) { var evt = Get <InstanceOutputEvent>(i => i.Instance.Concept == Concept2.LearnNewConcept); if (evt == null) { yield break; } var collection = evt.Instance; var answer = generator.GetValue(collection, Concept2.Answer); var unknown = generator.GetValue(collection, Concept2.Unknown); var rememberDescription = RememberConceptDescription.Create(generator, answer.Concept, unknown.Concept.Name); YesNoPrompt.Generate(generator, rememberDescription, new ConceptInstance(Concept2.Nothing)); yield return($"So you think {singular(unknown)} is {singular(answer)} ?"); }
protected override IEnumerable <string> execute(BeamGenerator generator) { var unknownPhrases = GetUnknownPhrases(generator).ToArray(); var substitutionRequest = Get <IncompleteRelationEvent>(p => !p.IsFilled, searchInsideTurnOnly: false); if (PreviousPolicy <LearnNewPhrase>(out _) || unknownPhrases.Count() != 1 || substitutionRequest == null || substitutionRequest.Subject == null) { yield break; } var unknownPhrase = unknownPhrases.FirstOrDefault(); var unknownPropertyCandidate = new ConceptInstance(Concept2.From(unknownPhrase)); var newPropertyAssignment = Find <PropertySetEvent>(p => p.Target.Property == Concept2.HasProperty && p.SubstitutedValue?.Concept == substitutionRequest.Property, precedingTurns: 1); if (newPropertyAssignment != null) { //in the previous turn, new property was registered - this might be its value var remember = RememberPropertyValue.Create(generator, new PropertySetTarget(substitutionRequest.Subject, substitutionRequest.Property), unknownPropertyCandidate); YesNoPrompt.Generate(generator, remember, new ConceptInstance(Concept2.Nothing)); yield return($"So, you think {singular(substitutionRequest.Subject)} {singular(substitutionRequest.Property)} {unknownPhrase} ?"); yield break; } /*// Unknown value when substitution is required was observed * // TODO detect whether request is for parameter (then nothing to do here) * // or try to learn new property value * * var assignUnknownProperty = new ConceptInstance(Concept2.AssignUnknownProperty); * generator.SetValue(assignUnknownProperty, Concept2.Subject, unknownPropertyCandidate); * * //TODO incorporate target property * generator.SetValue(assignUnknownProperty, Concept2.Target, substitutionRequest.Subject); * generator.Push(new InstanceActivationRequestEvent(assignUnknownProperty)); * * yield return $"What does {unknownPhrase} mean?";*/ }
protected override IEnumerable <string> execute(BeamGenerator generator) { var fullRelation = Get <PropertySetEvent>(p => IsDefined(p.SubstitutedValue.Concept) && IsDefined(p.Target.Instance?.Concept)); if (fullRelation == null) { yield break; } var targetInstance = fullRelation.Target.Instance; if (targetInstance == null) { yield break; } var children = generator.GetInverseConceptValues(Concept2.InstanceOf, targetInstance); if (children.Any()) { //TODO add learning for classes yield break; } var parameters = generator.GetParameterDefinitions(targetInstance); if (parameters.Any(p => p.Property == fullRelation.Target.Property)) { //don't learn argument values yield break; } generator.Push(new StaticScoreEvent(0.1)); var remember = RememberPropertyValue.Create(generator, fullRelation.Target, fullRelation.SubstitutedValue); YesNoPrompt.Generate(generator, remember, new ConceptInstance(Concept2.Nothing)); yield return($"So you think, {singularWithProperty(fullRelation.Target.Instance)} ?"); }
protected override IEnumerable <string> execute(BeamGenerator generator) { var askedForLearning = PreviousPolicy <LearnNewPhrase>(out var policyTag) || PreviousPolicy <UnknownAnsweredToLearnNewPhrase>(out policyTag); if (!askedForLearning) { yield break; } var instances = FindTurnInstances().ToArray(); if (!instances.Any()) { yield break; } var unknown = generator.GetValue(policyTag.Tag, Concept2.Unknown); var hypothesis = instances.Last(); generator.Push(new StaticScoreEvent(0.1)); YesNoPrompt.Generate(generator, RememberConceptDescription.Create(generator, hypothesis.Concept, unknown.Concept.Name), new ConceptInstance(Concept2.Nothing)); yield return($"So, you think that {singular(unknown)} means {singular(hypothesis)} ?"); }