Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

おいのりワードのリストを修正 #13

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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