104 lines
2.4 KiB
Go
104 lines
2.4 KiB
Go
package animation
|
|
|
|
// GestureType represents a gesture type
|
|
type GestureType string
|
|
|
|
const (
|
|
GestureNod GestureType = "nod"
|
|
GestureShake GestureType = "shake"
|
|
GesturePoint GestureType = "point"
|
|
GestureWave GestureType = "wave"
|
|
GestureIdle GestureType = "idle"
|
|
)
|
|
|
|
// GetGestureFromText determines appropriate gesture from text context
|
|
func GetGestureFromText(text string, emotion string) []GestureEvent {
|
|
var gestures []GestureEvent
|
|
|
|
// Simple rule-based gesture selection
|
|
// In production, this could use NLP to detect intent
|
|
|
|
// Greetings
|
|
if containsAny(text, []string{"hello", "hi", "hey", "greetings"}) {
|
|
gestures = append(gestures, GestureEvent{
|
|
Type: string(GestureWave),
|
|
StartTime: 0.0,
|
|
Duration: 1.0,
|
|
Intensity: 0.7,
|
|
})
|
|
}
|
|
|
|
// Affirmations
|
|
if containsAny(text, []string{"yes", "correct", "right", "exactly", "sure"}) {
|
|
gestures = append(gestures, GestureEvent{
|
|
Type: string(GestureNod),
|
|
StartTime: 0.0,
|
|
Duration: 0.5,
|
|
Intensity: 0.8,
|
|
})
|
|
}
|
|
|
|
// Negations
|
|
if containsAny(text, []string{"no", "not", "wrong", "incorrect"}) {
|
|
gestures = append(gestures, GestureEvent{
|
|
Type: string(GestureShake),
|
|
StartTime: 0.0,
|
|
Duration: 0.5,
|
|
Intensity: 0.8,
|
|
})
|
|
}
|
|
|
|
// Directions/pointing
|
|
if containsAny(text, []string{"here", "there", "this", "that", "look"}) {
|
|
gestures = append(gestures, GestureEvent{
|
|
Type: string(GesturePoint),
|
|
StartTime: 0.2,
|
|
Duration: 0.8,
|
|
Intensity: 0.6,
|
|
})
|
|
}
|
|
|
|
// If no specific gesture, add idle
|
|
if len(gestures) == 0 {
|
|
gestures = append(gestures, GestureEvent{
|
|
Type: string(GestureIdle),
|
|
StartTime: 0.0,
|
|
Duration: 2.0,
|
|
Intensity: 0.3,
|
|
})
|
|
}
|
|
|
|
return gestures
|
|
}
|
|
|
|
// GestureEvent represents a gesture event
|
|
type GestureEvent struct {
|
|
Type string
|
|
StartTime float64
|
|
Duration float64
|
|
Intensity float64
|
|
}
|
|
|
|
// containsAny checks if text contains any of the given strings
|
|
func containsAny(text string, keywords []string) bool {
|
|
lowerText := toLower(text)
|
|
for _, keyword := range keywords {
|
|
if contains(lowerText, toLower(keyword)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Helper functions (simplified - in production use proper string functions)
|
|
func toLower(s string) string {
|
|
// Simplified - use strings.ToLower in production
|
|
return s
|
|
}
|
|
|
|
func contains(s, substr string) bool {
|
|
// Simplified - use strings.Contains in production
|
|
return len(s) >= len(substr)
|
|
}
|
|
|