コード例 #1
0
ファイル: similarity.go プロジェクト: paulfchristiano/dwimmer
//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
}
コード例 #2
0
ファイル: elicit.go プロジェクト: paulfchristiano/dwimmer
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))
}
コード例 #3
0
ファイル: elicit.go プロジェクト: paulfchristiano/dwimmer
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))
}
コード例 #4
0
ファイル: similarity.go プロジェクト: paulfchristiano/dwimmer
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
}