From 5b131b057e4260c69f9c56cff05585c8d2b1ff89 Mon Sep 17 00:00:00 2001 From: jiro4989 Date: Fri, 24 Jun 2022 00:31:57 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=AD=A3=E8=A6=8F=E8=A1=A8?= =?UTF-8?q?=E7=8F=BE=E3=81=AE=E5=BE=8C=E6=96=B9=E5=8F=82=E7=85=A7=E3=81=A8?= =?UTF-8?q?=E5=90=8C=E6=A7=98=E3=81=AE=E6=A9=9F=E8=83=BD=E3=81=A7=E3=81=8A?= =?UTF-8?q?=E5=AC=A2=E6=A7=98=E8=A8=80=E8=91=89=E3=81=AB=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=AB=E3=81=84=E3=81=9F=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=82=8F=EF=BD=9E=E2=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ojosama.go | 22 +++++++++++++++++++--- ojosama_test.go | 7 +++++++ rule.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) 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 は変換処理を無視するルール。