Skip to content

Commit

Permalink
Merge pull request #13 from StudioAquatan/fix/mail-classify
Browse files Browse the repository at this point in the history
おいのりワードのリストを修正
  • Loading branch information
ocucraqp authored Aug 22, 2020
2 parents c3dda9e + 5df63d1 commit d952b6c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 19 additions & 7 deletions pkg/email/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
27 changes: 23 additions & 4 deletions pkg/email/classifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
Expand All @@ -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))
}
})
Expand Down

0 comments on commit d952b6c

Please sign in to comment.