Skip to content

Commit

Permalink
修复疑问句无法识别的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TsaoLun committed Aug 16, 2023
1 parent 2904990 commit 04e14e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 0 additions & 1 deletion bot/adapters/logic/closestmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func generator(match *closestMatch, text string) mr.GenerateFunc {
if match.verbose {
printMatches(keys)
}

chunks := splitStrings(keys, chunkSize)
for _, chunk := range chunks {
source <- sourceAndTargets{
Expand Down
2 changes: 1 addition & 1 deletion bot/adapters/storage/memorystorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
idfFile = path.Join(dir, idfFile)
stopWordsFile = path.Join(dir, stopWordsFile)
generatedStopWordsFile = path.Join(dir, generatedStopWordsFile)
log.Printf("dictFile: %s idfFile %s stopWordsFile %s genratedStopWordsFile %s\n", dictFile, idfFile, stopWordsFile, generatedStopWordsFile)
log.Printf("DictFile: %s \nIdfFile: %s \nStopWordsFile: %s \nGenratedStopWordsFile: %s\n", dictFile, idfFile, stopWordsFile, generatedStopWordsFile)
}

type (
Expand Down
5 changes: 2 additions & 3 deletions bot/adapters/storage/separatedmemorystorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ func (storage *separatedMemoryStorage) Find(sentence string) (map[string]int, bo

func (storage *separatedMemoryStorage) Search(sentence string) []string {
if nlp.IsQuestion(sentence) {
return storage.questionStorage.Search(sentence)
} else {
return storage.declarativeStorage.Search(sentence)
sentence = nlp.RemoveAllQuestionMark(sentence)
}
return storage.declarativeStorage.Search(sentence)
}

func (storage *separatedMemoryStorage) Remove(sentence string) {
Expand Down
23 changes: 23 additions & 0 deletions bot/nlp/sentencedetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ func IsQuestion(sentence string) bool {
return false
}

func RemoveAllQuestionMark(sentence string) string {
chars := []rune(strings.TrimSpace(sentence))
if len(chars) == 0 {
return sentence
}

if _, ok := endQuestionChars[chars[len(chars)-1]]; ok {
sentence = string(chars[:len(chars)-1])
}
// remove embededQuestionMarks
for _, key := range embededQuestionMarks {
if strings.Contains(sentence, key) {
sentence = strings.ReplaceAll(sentence, key, "")
chars = []rune(strings.TrimSpace(sentence))
if len(chars) == 0 {
return sentence
}
}
}

return sentence
}

func createSet(items []rune) map[rune]lang.PlaceholderType {
ret := make(map[rune]lang.PlaceholderType)
for _, item := range items {
Expand Down

0 comments on commit 04e14e3

Please sign in to comment.