From 32f9f84e110b1b233f597ed8d26a236f7d517dd9 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 30 Oct 2021 20:21:30 +0800 Subject: [PATCH] ci: add golangci --- .github/workflows/golangci-lint.yml | 4 +-- bot/adapters/storage/memorystorage.go | 37 +++++++-------------------- bot/nlp/comparisons.go | 7 ----- bot/trainers.go | 4 ++- 4 files changed, 13 insertions(+), 39 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6b4a093..8df7b85 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -9,8 +9,6 @@ on: pull_request: permissions: contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read jobs: golangci: name: lint @@ -18,4 +16,4 @@ jobs: steps: - uses: actions/checkout@v2 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 \ No newline at end of file + uses: golangci/golangci-lint-action@v2 diff --git a/bot/adapters/storage/memorystorage.go b/bot/adapters/storage/memorystorage.go index 830c92a..2dc4d0a 100644 --- a/bot/adapters/storage/memorystorage.go +++ b/bot/adapters/storage/memorystorage.go @@ -8,6 +8,7 @@ import ( "sort" "github.com/tal-tech/go-zero/core/lang" + "github.com/tal-tech/go-zero/core/logx" "github.com/tal-tech/go-zero/core/mr" "github.com/wangbin/jiebago" "github.com/wangbin/jiebago/analyse" @@ -43,11 +44,11 @@ type ( func RestoreMemoryStorage(decoder *gob.Decoder) (*memoryStorage, error) { var segmenter jiebago.Segmenter - segmenter.LoadDictionary(dictFile) + logx.Must(segmenter.LoadDictionary(dictFile)) var extracter analyse.TagExtracter - extracter.LoadDictionary(dictFile) - extracter.LoadIdf(idfFile) - extracter.LoadStopWords(stopWordsFile) + logx.Must(extracter.LoadDictionary(dictFile)) + logx.Must(extracter.LoadIdf(idfFile)) + logx.Must(extracter.LoadStopWords(stopWordsFile)) var keys []string responses := make(map[string]map[string]int) @@ -76,11 +77,11 @@ func RestoreMemoryStorage(decoder *gob.Decoder) (*memoryStorage, error) { func NewMemoryStorage() *memoryStorage { var segmenter jiebago.Segmenter - segmenter.LoadDictionary(dictFile) + logx.Must(segmenter.LoadDictionary(dictFile)) var extracter analyse.TagExtracter - extracter.LoadDictionary(dictFile) - extracter.LoadIdf(idfFile) - extracter.LoadStopWords(stopWordsFile) + logx.Must(extracter.LoadDictionary(dictFile)) + logx.Must(extracter.LoadIdf(idfFile)) + logx.Must(extracter.LoadStopWords(stopWordsFile)) return &memoryStorage{ segmenter: &segmenter, @@ -382,23 +383,3 @@ func splitStrings(slice []string, size int) []*keyChunk { return result } - -func (storage *memoryStorage) print() { - fmt.Println("Questions:") - for _, key := range storage.keys { - fmt.Printf("\t%s\n", key) - } - - fmt.Println("Responses:") - for key, value := range storage.responses { - fmt.Printf("\t%s:\n", key) - for text, occurrence := range value { - fmt.Printf("\t\t%s:\t%d\n", text, occurrence) - } - } - - fmt.Println("Indexes:") - for key, ids := range storage.indexes { - fmt.Printf("\t%s: %v\n", key, ids) - } -} diff --git a/bot/nlp/comparisons.go b/bot/nlp/comparisons.go index 979fbd9..4f08c4f 100644 --- a/bot/nlp/comparisons.go +++ b/bot/nlp/comparisons.go @@ -106,10 +106,3 @@ func min(a int, b int) int { } return a } - -func max(a int, b int) int { - if b > a { - return b - } - return a -} diff --git a/bot/trainers.go b/bot/trainers.go index 4546a37..9baf0c8 100644 --- a/bot/trainers.go +++ b/bot/trainers.go @@ -86,7 +86,9 @@ func (trainer *CorpusTrainer) Train(data interface{}) error { for _, convs := range corpora { for _, conv := range convs { - convTrainer.Train(conv) + if err := convTrainer.Train(conv); err != nil { + return err + } } }