Exemple #1
0
func ElicitAction(d dynamics.Dwimmer, context *term.SettingT, setting *term.Setting) dynamics.Transition {
	for {
		Q := FallThrough.T(represent.Setting(setting))
		result := dynamics.SubRun(d, Q, context)
		switch result.Head() {
		case TakeTransition:
			transition, err := represent.ToTransition(d, result.Values()[0])
			if err == nil {
				return transition
			}
		case core.OK:
		default:
			result, err := d.Answer(TransitionGiven.T(result, Q))
			if err == nil {
				transition, err := represent.ToTransition(d, result)
				if err == nil {
					return transition
				}
			}
		}
	}
}
Exemple #2
0
//TODO only do this sometimes, or control better the length, or something...
func GetHints(d dynamics.Dwimmer, context *term.SettingT, s *term.SettingS, n int) []string {
	suggestions, err := d.Answer(similarity.SuggestedActions.T(
		represent.Setting(s.Setting),
		represent.Int(n),
	), context)
	if err != nil {
		return []string{}
	}
	suggestionList, err := represent.ToList(d, suggestions)
	if err != nil {
		return []string{}
	}
	result := []string{}
	for _, suggestion := range suggestionList {
		actionC, err := represent.ToActionC(d, suggestion)
		if err != nil {
			continue
		}
		actionS := actionC.Uninstantiate(s.Names)
		result = append(result, actionS.String())
	}
	reverseHints(result)
	return result
}