Skip to content

Commit

Permalink
✨形容詞文に対応いたしましたわ❗ #12 (#68)
Browse files Browse the repository at this point in the history
* 形容詞文のためだけに関数を実装してたのを、汎用変換処理で変換するように変更

* テストケースを若干修正
  • Loading branch information
jiro4989 committed Jul 10, 2022
1 parent 1492318 commit a77582e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
11 changes: 11 additions & 0 deletions internal/converter/convert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,17 @@ var (
newRuleInterjection("うふふ", "おほほ"),
newRuleInterjection("う", "お"),
newRuleInterjection("ふふふ", "ほほほ"),

// 形容詞文。形容詞で文が終わる時に変換する
{
Conditions: ConvertConditions{
{Features: pos.AdjectivesSelfSupporting},
},
EnableWhenSentenceSeparation: true,
EnableKutenToExclamation: true,
AppendLongNote: true,
Value: "@1ですわ",
},
}
)

Expand Down
25 changes: 1 addition & 24 deletions ojosama.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ func Convert(src string, opt *ConvertOption) (string, error) {
var kutenToEx bool
buf, nounKeep, i, kutenToEx = convert(data, tokens, i, buf, nounKeep, opt)

// 形容詞、自立で文が終わった時は丁寧語ですわを追加する
if isAppendablePoliteWord(data, tokens, i) {
buf += politeWord
kutenToEx = true
}

if kutenToEx {
if ok, s, pos := randomKutenToExclamation(tokens, i, opt); ok {
buf += s
Expand Down Expand Up @@ -318,6 +312,7 @@ func convert(data tokenizer.TokenData, tokens []tokenizer.Token, i int, surface

result := c.Value
pos := i
result = strings.ReplaceAll(result, "@1", data.Surface)

// 波線伸ばしをランダムに追加する
if c.AppendLongNote {
Expand Down Expand Up @@ -428,24 +423,6 @@ func appendPrefix(data tokenizer.TokenData, tokens []tokenizer.Token, i int, sur
return "お" + surface, true
}

// isAppendablePoliteWord は丁寧語を追加する。
func isAppendablePoliteWord(data tokenizer.TokenData, tokens []tokenizer.Token, i int) bool {
if !tokendata.EqualsFeatures(data.Features, []string{"形容詞", "自立"}) {
return false
}

if len(tokens) <= i+1 {
return false
}

// 文の区切りのタイミングでは「ですわ」を差し込む
if isSentenceSeparation(tokenizer.NewTokenData(tokens[i+1])) {
return true
}

return false
}

// isSentenceSeparation は data が文の区切りに使われる token かどうかを判定する。
func isSentenceSeparation(data tokenizer.TokenData) bool {
return tokendata.ContainsFeatures([][]string{feat.Kuten, feat.Toten}, data.Features) ||
Expand Down
12 changes: 7 additions & 5 deletions ojosama_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ func TestConvert(t *testing.T) {

{
desc: "正常系: (動詞)ないはそのままですわ",
src: "限らない、飾らない、数えない、くだらない",
want: "限らない、飾らない、数えない、くだらない",
src: "限らない、飾らない、数えない",
want: "限らない、飾らない、数えない",
opt: opt,
wantErr: false,
},
Expand Down Expand Up @@ -562,9 +562,11 @@ func TestConvert(t *testing.T) {
wantErr: false,
},
{
desc: "正常系: 形容詞+自立の後に「ですわ」を付与する場合、「。」をランダムに!に変換いたしますわ",
src: "とても悲しい。",
want: "とても悲しいですわ❗",
// FIXME: 「幽霊が怖い」で終わるべきところを
// 「幽霊が怖」で終わった場合も変換されてしまう
desc: "正常系: 形容詞+自立の後に「ですわ」を付与する場合、「。」をランダムに!に変換いたしますわ。変換記号の@1を誤って変換したりはしませんわ",
src: "@1悲しいことはとても悲しい。幽霊が怖い。幽霊が怖。",
want: "@1悲しいことはとても悲しいですわ❗お幽霊が怖いですわ❗お幽霊が怖ですわ❗",
opt: &ConvertOption{
forceKutenToExclamation: true,
},
Expand Down

0 comments on commit a77582e

Please sign in to comment.