Skip to content

Commit

Permalink
🐛 「ー」の手前に「お」がついてしまう不具合を修正いたしましたわ (close #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiro4989 committed Jun 23, 2022
1 parent f5f41eb commit 1706003
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ojosama_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ func TestConvert(t *testing.T) {
opt: nil,
wantErr: false,
},
{
desc: "正常系: 「ー」の前に「お」は付きませんの",
src: "しようぜー。しようぜーー。しようぜ~。しようぜ~~。しようぜー~。",
want: "しようぜー。しようぜーー。しようぜ~。しようぜ~~。しようぜー~。",
opt: nil,
wantErr: false,
},
}

for _, tt := range tests {
Expand Down
39 changes: 36 additions & 3 deletions rule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ojosama

import "github.com/ikawaha/kagome/v2/tokenizer"
import (
"regexp"

"github.com/ikawaha/kagome/v2/tokenizer"
)

// convertRule は 単独のTokenに対して、Conditionsがすべてマッチしたときに変換するルール。
//
Expand Down Expand Up @@ -32,8 +36,9 @@ type convertType int

// convertCondition は変換に使う条件。
type convertCondition struct {
Type convertType
Value []string
Type convertType
Value []string
ValueRegexp *regexp.Regexp // オプション。設定されてる時だけ使う
}

// meaningType は言葉の意味分類。
Expand Down Expand Up @@ -187,6 +192,9 @@ var (
},
},
},
{
Conditions: newCondRe(nounsGeneral, regexp.MustCompile(`^(ー+|~+)$`)),
},
}

// convertRules は 単独のTokenに対して、Conditionsがすべてマッチしたときに変換するルール。
Expand Down Expand Up @@ -608,10 +616,16 @@ func (c *convertCondition) equalsTokenData(data tokenizer.TokenData) bool {
return true
}
case convertTypeSurface:
if c.ValueRegexp != nil {
return c.ValueRegexp.MatchString(data.Surface)
}
if data.Surface == c.Value[0] {
return true
}
case convertTypeBaseForm:
if c.ValueRegexp != nil {
return c.ValueRegexp.MatchString(data.BaseForm)
}
if data.BaseForm == c.Value[0] {
return true
}
Expand All @@ -626,10 +640,16 @@ func (c *convertCondition) notEqualsTokenData(data tokenizer.TokenData) bool {
return true
}
case convertTypeSurface:
if c.ValueRegexp != nil {
return !c.ValueRegexp.MatchString(data.Surface)
}
if data.Surface != c.Value[0] {
return true
}
case convertTypeBaseForm:
if c.ValueRegexp != nil {
return !c.ValueRegexp.MatchString(data.BaseForm)
}
if data.BaseForm != c.Value[0] {
return true
}
Expand Down Expand Up @@ -692,6 +712,19 @@ func newCond(features []string, surface string) convertConditions {
}
}

func newCondRe(features []string, re *regexp.Regexp) convertConditions {
return convertConditions{
{
Type: convertTypeFeatures,
Value: features,
},
{
Type: convertTypeSurface,
ValueRegexp: re,
},
}
}

func newCondSentenceEndingParticle(surface string) convertConditions {
return convertConditions{
{
Expand Down

0 comments on commit 1706003

Please sign in to comment.