From 5df63d1a05dcebb1ce685a5d6e7e64a1defbbb38 Mon Sep 17 00:00:00 2001 From: chez-shanpu Date: Sat, 22 Aug 2020 20:58:12 +0900 Subject: [PATCH] Fix oinori word list --- cmd/run.go | 4 ++-- pkg/email/classifier.go | 26 +++++++++++++++++++------- pkg/email/classifier_test.go | 27 +++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index f745c6e..d5e5d17 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -57,11 +57,11 @@ func runServer() { for { ec := <-ecChan - if !email.ClassifyMail(ec.Subject) { + if !email.ClassifyMailBySubj(ec.Subject) { log.Printf("[INFO] Ignored email subject: %s", ec.Subject) continue } - if !email.ClassifyMail(ec.Body) { + if !email.ClassifyMailByBody(ec.Body) { log.Printf("[INFO] Ignored email Body: %s", ec.Body) continue } diff --git a/pkg/email/classifier.go b/pkg/email/classifier.go index 58ab66e..e29a5cf 100644 --- a/pkg/email/classifier.go +++ b/pkg/email/classifier.go @@ -2,17 +2,29 @@ package email import "strings" -var oinoriWords = []string{ +var oinoriWordsSubj = []string{ "選考結果", - "残念ながら", +} +var oinoriWordsBody = []string{ + "残念", "貴殿の今後のご活躍を", - "期待に添えない", - "慎重に選考", + "期待に添", + "誠に申し訳ございません", +} + +// Classify if it's a "oinori" email using its subject +func ClassifyMailBySubj(subj string) bool { + for _, word := range oinoriWordsSubj { + if strings.Contains(subj, word) { + return true + } + } + return false } -// Classify if it's a "oinori" email -func ClassifyMail(body string) bool { - for _, word := range oinoriWords { +// Classify if it's a "oinori" email using its body +func ClassifyMailByBody(body string) bool { + for _, word := range oinoriWordsBody { if strings.Contains(body, word) { return true } diff --git a/pkg/email/classifier_test.go b/pkg/email/classifier_test.go index ab2aa30..1538201 100644 --- a/pkg/email/classifier_test.go +++ b/pkg/email/classifier_test.go @@ -8,17 +8,36 @@ import ( var _ = Describe("Classifier", func() { Context("email.ClassifyMail()", func() { - When("the email has come", func() { + When("the email subject is looked", func() { It("returns true", func() { testCases := []string{ "選考結果", + } + for _, s := range testCases { + res := email.ClassifyMailBySubj(s) + Expect(res).To(Equal(true)) + } + }) + It("returns false", func() { + testCases := []string{ + "先日はお忙しい中、xxxの面接にご参加いただきまして誠にありがとうございました。", + } + for _, s := range testCases { + res := email.ClassifyMailBySubj(s) + Expect(res).To(Equal(false)) + } + }) + }) + When("the email body is looked", func() { + It("returns true", func() { + testCases := []string{ "この度は弊社の面接にご参加頂き、誠にありがとうございました。誠に残念ながら、今回は貴意に添いかねる結果となりました。", "この度はご期待に添えない結果となりました。", "貴殿の今後のご活躍を心よりお祈り申し上げます。", - "慎重に選考を進めた結果,", + "誠に申し訳ございませんか", } for _, s := range testCases { - res := email.ClassifyMail(s) + res := email.ClassifyMailByBody(s) Expect(res).To(Equal(true)) } }) @@ -27,7 +46,7 @@ var _ = Describe("Classifier", func() { "先日はお忙しい中、xxxの面接にご参加いただきまして誠にありがとうございました。", } for _, s := range testCases { - res := email.ClassifyMail(s) + res := email.ClassifyMailByBody(s) Expect(res).To(Equal(false)) } })