Skip to content

Commit

Permalink
LSTM algorithm added
Browse files Browse the repository at this point in the history
  • Loading branch information
simplyYan authored Jun 14, 2024
1 parent bec9727 commit f91ebdf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/GalaktaGlareLSTM/GalaktaGlareLSTM.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package GalaktaGlareLSTM

import (
"strings"
)

type LSTM struct {
knowledge map[string]string
}

func New() *LSTM {
return &LSTM{
knowledge: make(map[string]string),
}
}

func (l *LSTM) Train(data string) {
lines := strings.Split(data, "\n")
for _, line := range lines {
if line == "" {
continue
}
parts := strings.Split(line, "=")
if len(parts) == 2 {
question := strings.TrimSpace(parts[0])
answer := strings.TrimSpace(parts[1])
question = strings.Trim(question, "{}")
answer = strings.Trim(answer, `[]"`)
l.knowledge[question] = answer
}
}
}

func (l *LSTM) Run(question string) string {
if answer, exists := l.knowledge[question]; exists {
return answer
}
return "I don't know the answer to that."
}
3 changes: 3 additions & 0 deletions src/GalaktaGlareLSTM/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/simplyYan/GalaktaGlare/src/GalaktaGlareLSTM

go 1.22.4

0 comments on commit f91ebdf

Please sign in to comment.