diff --git a/ojosama.go b/ojosama.go index e562b44..73c0f25 100644 --- a/ojosama.go +++ b/ojosama.go @@ -195,6 +195,14 @@ func convertContinuousConditions(tokens []tokenizer.Token, tokenPos int, opt *Co n := tokenPos + len(mc.Conditions) - 1 result := mc.Value + + // FIXME: 書き方が汚い + data := tokenizer.NewTokenData(tokens[tokenPos]) + surface := data.Surface + if appendablePrefix(data) { + surface = "お" + surface + } + result = strings.ReplaceAll(result, "@1", surface) if mc.AppendLongNote { result, n = appendLongNote(result, tokens, n, opt) } @@ -293,14 +301,22 @@ func convert(data tokenizer.TokenData, tokens []tokenizer.Token, i int, surface return result, nounKeep, i } -// appendPrefix は surface の前に「お」を付ける。 -func appendPrefix(data tokenizer.TokenData, tokens []tokenizer.Token, i int, surface string, nounKeep bool) (string, bool) { +func appendablePrefix(data tokenizer.TokenData) bool { if !equalsFeatures(data.Features, []string{"名詞", "一般"}) && !equalsFeatures(data.Features[:2], []string{"名詞", "固有名詞"}) { - return surface, false + return false } // 丁寧語の場合は「お」を付けない if isPoliteWord(data) { + return false + } + + return true +} + +// appendPrefix は surface の前に「お」を付ける。 +func appendPrefix(data tokenizer.TokenData, tokens []tokenizer.Token, i int, surface string, nounKeep bool) (string, bool) { + if !appendablePrefix(data) { return surface, false } diff --git a/ojosama_test.go b/ojosama_test.go index a8a800a..2ea9f50 100644 --- a/ojosama_test.go +++ b/ojosama_test.go @@ -536,6 +536,13 @@ func TestConvert(t *testing.T) { opt: nil, wantErr: false, }, + { + desc: "正常系: ", + src: "アホだ。カラスや。バナナじゃ。", + want: "おアホですの。おカラスですの。おバナナですの。", + opt: nil, + wantErr: false, + }, } for _, tt := range tests { diff --git a/rule.go b/rule.go index eb14f38..9cae408 100644 --- a/rule.go +++ b/rule.go @@ -197,6 +197,50 @@ var ( newCond(assistantParallel, "や"), }, }, + + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: nounsGeneral}}, + newCond(auxiliaryVerb, "じゃ"), + }, + }, + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: nounsGeneral}}, + newCond(auxiliaryVerb, "だ"), + }, + }, + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: nounsGeneral}}, + newCond(auxiliaryVerb, "や"), + }, + }, + + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: pronounGeneral}}, + newCond(auxiliaryVerb, "じゃ"), + }, + }, + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: pronounGeneral}}, + newCond(auxiliaryVerb, "だ"), + }, + }, + { + Value: "@1ですの", + Conditions: []convertConditions{ + {{Type: convertTypeFeatures, Value: pronounGeneral}}, + newCond(auxiliaryVerb, "や"), + }, + }, } // excludeRules は変換処理を無視するルール。