• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang dynamics.Dwimmer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/paulfchristiano/dwimmer/dynamics.Dwimmer的典型用法代码示例。如果您正苦于以下问题:Golang Dwimmer类的具体用法?Golang Dwimmer怎么用?Golang Dwimmer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Dwimmer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: analogies

//TODO the algorithms part could be more efficient, but I don't really care
func analogies(d dynamics.Dwimmer, s *term.Setting, n int) ([]*term.Setting, []float32) {
	if s.Size == 1 {
		return contenders(d, s.Last, n)
	}

	previousSetting := s.Previous
	lastLine := s.Last
	previousAnalogies, previousPriorities := analogies(d, previousSetting, n+1)

	possibilities, possiblePriorities := []*term.Setting{}, new(indexHeap)
	i := 0
	for j, priority := range previousPriorities {
		analogy := previousAnalogies[j]
		for _, setting := range d.Continuations(analogy) {
			fit, canMatch := match(setting.Last, lastLine)
			if canMatch {
				possiblePriorities.Push(prioritized{
					index:    i,
					priority: priority * fit,
				})
				i++
				possibilities = append(possibilities, setting)
			}
		}
	}
	heap.Init(possiblePriorities)
	result := make([]*term.Setting, 0)
	priorities := make([]float32, 0)
	for i := 0; i < n && possiblePriorities.Len() > 0; i++ {
		next := heap.Pop(possiblePriorities).(prioritized)
		priorities = append(priorities, next.priority)
		result = append(result, possibilities[next.index])
	}
	return result, priorities
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:36,代码来源:similarity.go


示例2: getInput

func getInput(d dynamics.Dwimmer, context *term.SettingT, hintstrings, toolmap term.T) term.T {
	quotedHints, err := represent.ToList(d, hintstrings)
	if err != nil {
		return represent.ConversionError.T(hintstrings, err)
	}
	hints := make([]string, len(quotedHints))
	for i, quoted := range quotedHints {
		hints[i], err = represent.ToStr(d, quoted)
		if err != nil {
			return represent.ConversionError.T(quoted, err)
		}
	}
	tools := make(map[rune]string)
	for toolmap.Head() != maps.Empty {
		switch toolmap.Head() {
		case maps.Cons:
			vs := toolmap.Values()
			c, err := represent.ToRune(d, vs[0])
			if err != nil {
				return represent.ConversionError.T(vs[0], err)
			}
			s, err := represent.ToStr(d, vs[1])
			if err != nil {
				return represent.ConversionError.T(vs[1], err)
			}
			tools[c] = s
			toolmap = vs[2]
		default:
			context.AppendTerm(UnrecognizedDictionary.T())
			return nil
		}
	}
	input := d.Readln(" < ", hints, tools)
	return core.Answer.T(represent.Str(input))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:35,代码来源:elicit.go


示例3: run

func run(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
	setting, err := represent.ToSettingT(d, quotedSetting)
	if err != nil {
		return represent.ConversionError.T(quotedSetting, err)
	}
	result := d.Run(setting)
	if result == nil {
		return NoOutput.T(represent.SettingT(setting))
	}
	return Result.T(represent.T(result), represent.SettingT(setting))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:11,代码来源:main.go


示例4: getTransition

func getTransition(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
	setting, err := represent.ToSetting(d, quotedSetting)
	if err != nil {
		return term.Make("asked to get a transition in setting [], "+
			"but while converting to a setting received []").T(quotedSetting, err)
	}
	result, ok := d.Get(setting)
	if !ok {
		return NoCompiledAction.T()
	}
	return core.Answer.T(represent.Transition(result))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:12,代码来源:elicit.go


示例5: fallThrough

func fallThrough(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
	settingT, err := represent.ToSettingT(d, quotedSetting)
	if err != nil {
		return term.Make("asked to decide what to do in setting [], "+
			"but while converting to a setting received []").T(quotedSetting, err)
	}
	transition := ElicitAction(d, s, settingT.Setting)
	if shouldSave(transition) {
		d.Save(settingT.Setting, transition)
	}
	return TakeTransition.T(represent.Transition(transition))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:12,代码来源:elicit.go


示例6: allSettings

func allSettings(d dynamics.Dwimmer, s *term.SettingT) term.T {
	queue := []*term.Setting{term.Init()}
	for k := 0; k < len(queue); k++ {
		top := queue[k]
		queue = append(queue, d.Continuations(top)...)
	}
	result := make([]term.T, len(queue))
	for i, setting := range queue {
		result[i] = represent.Setting(setting)
	}
	return core.Answer.T(represent.List(result))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:12,代码来源:elicit.go


示例7: getContinuations

func getContinuations(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
	setting, err := represent.ToSetting(d, quotedSetting)
	if err != nil {
		return term.Make("asked to return the continuations from a setting, " +
			"but while converting to a setting received []").T(err)
	}
	continuations := d.Continuations(setting)
	result := make([]term.T, len(continuations))
	for i, c := range continuations {
		result[i] = represent.Setting(c)
	}
	return core.Answer.T(represent.List(result))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:13,代码来源:elicit.go


示例8: findAction

func findAction(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
	setting, err := represent.ToSetting(d, quotedSetting)
	if err != nil {
		return term.Make("asked to decide what to do in setting [], "+
			"but while converting to a setting received []").T(quotedSetting, err)
	}
	transition, ok := d.Get(setting)
	if !ok {
		transition := ElicitAction(d, s, setting)
		d.Save(setting, transition)
	}
	return core.Answer.T(represent.Transition(transition))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:13,代码来源:elicit.go


示例9: nativeSetCursor

func nativeSetCursor(d dynamics.Dwimmer, s *term.SettingT, xt, yt term.T) term.T {
	x, err := represent.ToInt(d, xt)
	if err != nil {
		return term.Make("asked to move cursor, but received [] "+
			"while converting coordinate [] to an integer").T(err, xt)
	}
	y, err := represent.ToInt(d, yt)
	if err != nil {
		return term.Make("asked to move cursor, but received [] "+
			"while converting coordinate [] to an integer").T(err, yt)
	}
	d.SetCursor(x, y)
	return core.OK.T()
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:14,代码来源:ui.go


示例10: setTransition

func setTransition(d dynamics.Dwimmer, s *term.SettingT, quotedTransition, quotedSetting term.T) term.T {
	transition, err := represent.ToTransition(d, quotedTransition)
	if err != nil {
		return term.Make("asked to set a setting to transition [], "+
			"but while converting to a transition received []").T(quotedTransition, err)
	}
	setting, err := represent.ToSetting(d, quotedSetting)
	if err != nil {
		return term.Make("asked to set a transition in setting [], "+
			"but while converting to a setting received []").T(quotedSetting, err)
	}
	d.Save(setting, transition)
	return core.OK.T()
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:14,代码来源:elicit.go


示例11: displayTemplate

func displayTemplate(d dynamics.Dwimmer, context *term.SettingT, quotedSetting term.T) term.T {
	setting, err := represent.ToSetting(d, quotedSetting)
	if err != nil {
		return represent.ConversionError.T(quotedSetting, err)
	}
	settingS := addNames(setting)
	ShowSettingS(d, settingS)
	d.Println("")
	d.Println("")
	quotedNames := make([]term.T, len(settingS.Names))
	for i, name := range settingS.Names {
		quotedNames[i] = represent.Str(name)
	}
	return Names.T(represent.List(quotedNames))
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:15,代码来源:elicit.go


示例12: nativePutChar

func nativePutChar(d dynamics.Dwimmer, s *term.SettingT, char, xt, yt term.T) term.T {
	c, err := represent.ToRune(d, char)
	if err != nil {
		return term.Make("asked to write character, but received [] " +
			"while converting to a character").T(err)
	}
	x, err := represent.ToInt(d, xt)
	if err != nil {
		return term.Make("asked to write character, but received [] "+
			"while converting coordinate [] to an integer").T(err, xt)
	}
	y, err := represent.ToInt(d, yt)
	if err != nil {
		return term.Make("asked to write character, but received [] "+
			"while converting coordinate [] to an integer").T(err, yt)
	}
	d.SetCursor(x, y)
	d.PrintCh(c)
	return core.OK.T()
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:20,代码来源:ui.go


示例13: Suggestions

func Suggestions(d dynamics.Dwimmer, s *term.Setting, n int) ([]term.ActionC, []float32) {
	settings, settingPriorities := analogies(d, s, n)
	result := []term.ActionC{}
	priorities := []float32{}
buildingResult:
	for i, other := range settings {
		t, _ := d.Get(other)
		simple, isSimple := t.(dynamics.SimpleTransition)
		if isSimple {
			action := simple.Action
			for _, otherAction := range result {
				if action.ID() == otherAction.ID() {
					continue buildingResult
				}
			}
			result = append(result, action)
			priorities = append(priorities, settingPriorities[i])
		}
	}
	return result, priorities
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:21,代码来源:similarity.go


示例14: ElicitAction

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
				}
			}
		}
	}
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:22,代码来源:elicit.go


示例15: GetHints

//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
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:25,代码来源:elicit.go


示例16: contenders

func contenders(d dynamics.Dwimmer, l term.SettingLine, n int) ([]*term.Setting, []float32) {
	allSettings := d.Continuations(term.Init())
	result, priorities := Top(l, allSettings, n)
	return result, priorities
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:5,代码来源:similarity.go


示例17: DoC

func DoC(d dynamics.Dwimmer, a term.ActionC, s *term.SettingT) term.T {
	return d.Do(a.Instantiate(s.Args), s)
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:3,代码来源:dwimmer.go


示例18: setState

func setState(d dynamics.Dwimmer, s *term.SettingT, t term.T) term.T {
	d.SetStorage(t)
	return core.OK.T()
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:4,代码来源:store.go


示例19: getState

func getState(d dynamics.Dwimmer, s *term.SettingT) term.T {
	return core.Answer.T(d.GetStorage())
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:3,代码来源:store.go


示例20: ShowSettingS

func ShowSettingS(d dynamics.Dwimmer, settingS *term.SettingS) {
	d.Clear()
	for _, line := range settingS.Lines() {
		d.Println(line)
	}
}
开发者ID:paulfchristiano,项目名称:dwimmer,代码行数:6,代码来源:elicit.go



注:本文中的github.com/paulfchristiano/dwimmer/dynamics.Dwimmer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang term.Make函数代码示例发布时间:2022-05-28
下一篇:
Golang mango.Stack类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap