From 5d8350370348c3439da828c8afc587b5807b0bce Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 10:42:07 +0900 Subject: [PATCH 1/6] Add nuget package and add convertion from Hiragana or Katakana to romaji. --- .../Utils/JpStringUtilsTest.cs | 14 ++++++++++++++ osu.Game.Rulesets.Karaoke/Utils/JpStringUtils.cs | 6 ++++++ .../osu.Game.Rulesets.Karaoke.csproj | 2 ++ 3 files changed, 22 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Utils/JpStringUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Utils/JpStringUtilsTest.cs index a89101805..439922a60 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Utils/JpStringUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Utils/JpStringUtilsTest.cs @@ -26,5 +26,19 @@ public void TestToKatakana(string text, string actual) var katakana = JpStringUtils.ToKatakana(text); Assert.AreEqual(katakana, actual); } + + [TestCase("はなび", "hanabi")] + [TestCase("たいかい", "taikai")] + [TestCase("ハナビ", "hanabi")] + [TestCase("タイカイ", "taikai")] + [TestCase("花火大会", "花火大会")] // cannot convert kanji to romaji. + [TestCase("ハナビ wo miru", "hanabi wo miru")] + [TestCase("タイカイー☆", "taikaii☆")] // it's converted by package, let's skip this checking. + [TestCase("タイカイ ー☆", "taikai -☆")] // it's converted by package, let's skip this checking. + public void TestToRomaji(string text, string actual) + { + var romaji = JpStringUtils.ToRomaji(text); + Assert.AreEqual(romaji, actual); + } } } diff --git a/osu.Game.Rulesets.Karaoke/Utils/JpStringUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/JpStringUtils.cs index b7a5d7c87..d052bab44 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/JpStringUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/JpStringUtils.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using Zipangu; +using WanaKanaSharp; namespace osu.Game.Rulesets.Karaoke.Utils { @@ -16,5 +17,10 @@ public static string ToKatakana(string text) { return text.HiraganaToKatakana(); } + + public static string ToRomaji(string text) + { + return RomajiConverter.ToRomaji(text, false, null); + } } } diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index b2d4a273c..6b3dfce07 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -18,6 +18,7 @@ + @@ -48,6 +49,7 @@ + From e26cf38fa4892cd943d782e53a4633a9ea90b9a0 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 11:02:10 +0900 Subject: [PATCH 2/6] Add romaji tag generator --- .../RomajiTags/Ja/JaRomajiTagGenerator.cs | 76 +++++++++++++++++++ .../Ja/JaRomajiTagGeneratorConfig.cs | 13 ++++ .../RomajiTags/RomajiTagGenerator.cs | 19 +++++ .../RomajiTags/RomajiTagGeneratorConfig.cs | 9 +++ 4 files changed, 117 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorConfig.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGeneratorConfig.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs new file mode 100644 index 000000000..379217d8b --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs @@ -0,0 +1,76 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.IO; +using Lucene.Net.Analysis; +using Lucene.Net.Analysis.Ja; +using Lucene.Net.Analysis.TokenAttributes; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja +{ + public class JaRomajiTagGenerator : RomajiTagGenerator + { + private readonly Analyzer analyzer; + + public JaRomajiTagGenerator(JaRomajiTagGeneratorConfig config) + : base(config) + { + analyzer = Analyzer.NewAnonymous((fieldName, reader) => + { + Tokenizer tokenizer = new JapaneseTokenizer(reader, null, true, JapaneseTokenizerMode.SEARCH); + return new TokenStreamComponents(tokenizer, new JapaneseReadingFormFilter(tokenizer, false)); + }); + } + + public override RomajiTag[] CreateRubyTags(Lyric lyric) + { + var text = lyric.Text; + var tags = new List(); + + // Tokenize the text + var tokenStream = analyzer.GetTokenStream("dummy", new StringReader(text)); + + // Get result and offset + var result = tokenStream.GetAttribute(); + var offsetAtt = tokenStream.GetAttribute(); + + // Reset the stream and convert all result + tokenStream.Reset(); + + while (true) + { + // Read next token + tokenStream.ClearAttributes(); + tokenStream.IncrementToken(); + + // Get parsed result, result is Katakana. + var katakana = result.ToString(); + if (string.IsNullOrEmpty(katakana)) + break; + + // Convert to romaji. + var romaji = JpStringUtils.ToRomaji(katakana); + if (Config.Uppercase) + romaji = romaji.ToUpper(); + + + // Make tag + tags.Add(new RomajiTag + { + Text = romaji, + StartIndex = offsetAtt.StartOffset, + EndIndex = offsetAtt.EndOffset + }); + } + + // Dispose + tokenStream.End(); + tokenStream.Dispose(); + + return tags.ToArray(); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorConfig.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorConfig.cs new file mode 100644 index 000000000..bcca0e239 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorConfig.cs @@ -0,0 +1,13 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja +{ + public class JaRomajiTagGeneratorConfig : RomajiTagGeneratorConfig + { + /// + /// Generate romaji as uppercase. + /// + public bool Uppercase { get; set; } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs new file mode 100644 index 000000000..f3b6284c0 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs @@ -0,0 +1,19 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags +{ + public abstract class RomajiTagGenerator where T : RomajiTagGeneratorConfig + { + protected T Config { get; } + + protected RomajiTagGenerator(T config) + { + Config = config; + } + + public abstract RomajiTag[] CreateRubyTags(Lyric lyric); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGeneratorConfig.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGeneratorConfig.cs new file mode 100644 index 000000000..a8cdf6728 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGeneratorConfig.cs @@ -0,0 +1,9 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags +{ + public class RomajiTagGeneratorConfig + { + } +} From 16d4e92d9599605a7a5240ac9c546e8bc1540eb5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 11:08:27 +0900 Subject: [PATCH 3/6] Add base test case. --- .../RomajiTags/Ja/JaRomajiTagGeneratorTest.cs | 62 +++++++++++++++++++ .../RomajiTags/Ja/JaRomajiTagGenerator.cs | 2 +- .../RomajiTags/RomajiTagGenerator.cs | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs new file mode 100644 index 000000000..2141873de --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs @@ -0,0 +1,62 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using NUnit.Framework; +using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja; +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Tests.Edit.Generator.RomajiTags.Ja +{ + public class JaRomajiTagGeneratorTest + { + [TestCase("花火大会", new[] { "hanabi", "taikei" })] + [TestCase("はなび", new string[] { })] + public void TestCreateRomajiTags(string text, string[] romaji) + { + var config = generatorConfig(null); + RunRomajiCheckTest(text, romaji, config); + } + + #region test helper + + protected void RunRomajiCheckTest(string text, string[] romaji, JaRomajiTagGeneratorConfig config) + { + var generator = new JaRomajiTagGenerator(config); + + var lyric = new Lyric { Text = text }; + var romajiTags = generator.CreateRomajiTags(lyric); + + Assert.AreEqual(romajiTags.Length, romajiTags.Length); + + foreach (var romajiTag in romajiTags) + { + Assert.IsTrue(romaji.Contains(romajiTag.Text)); + } + } + + private JaRomajiTagGeneratorConfig generatorConfig(params string[] properties) + { + var config = new JaRomajiTagGeneratorConfig(); + if (properties == null) + return config; + + foreach (var propertyName in properties) + { + if (propertyName == null) + continue; + + var theMethod = config.GetType().GetProperty(propertyName); + if (theMethod == null) + throw new MissingMethodException("Config is not exist."); + + theMethod.SetValue(config, true); + } + + return config; + } + + #endregion + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs index 379217d8b..20a48cf99 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs @@ -25,7 +25,7 @@ public JaRomajiTagGenerator(JaRomajiTagGeneratorConfig config) }); } - public override RomajiTag[] CreateRubyTags(Lyric lyric) + public override RomajiTag[] CreateRomajiTags(Lyric lyric) { var text = lyric.Text; var tags = new List(); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs index f3b6284c0..32fdcf63e 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/RomajiTagGenerator.cs @@ -14,6 +14,6 @@ protected RomajiTagGenerator(T config) Config = config; } - public abstract RomajiTag[] CreateRubyTags(Lyric lyric); + public abstract RomajiTag[] CreateRomajiTags(Lyric lyric); } } From 928e3298550cbd894eb1d75b4ef03dbe1651f1db Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 22:09:23 +0900 Subject: [PATCH 4/6] Rewrite test source and also add uppercase test. --- .../RomajiTags/Ja/JaRomajiTagGeneratorTest.cs | 27 +++++++++++-------- .../RomajiTags/Ja/JaRomajiTagGenerator.cs | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs index 2141873de..915e441f9 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs @@ -6,34 +6,39 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Tests.Helper; namespace osu.Game.Rulesets.Karaoke.Tests.Edit.Generator.RomajiTags.Ja { public class JaRomajiTagGeneratorTest { - [TestCase("花火大会", new[] { "hanabi", "taikei" })] - [TestCase("はなび", new string[] { })] - public void TestCreateRomajiTags(string text, string[] romaji) + [TestCase("花火大会", new[] { "[0,2]:hanabi", "[2,4]:taikai" })] + [TestCase("はなび", new string[] { "[0,3]:hanabi" })] + public void TestCreateRomajiTags(string text, string[] actualRomaji) { var config = generatorConfig(null); - RunRomajiCheckTest(text, romaji, config); + RunRomajiCheckTest(text, actualRomaji, config); + } + + [TestCase("花火大会", new[] { "[0,2]:HANABI", "[2,4]:TAIKAI" })] + [TestCase("はなび", new string[] { "[0,3]:hanabi" })] + public void TestCreateRomajiTagsWithUppercase(string text, string[] actualRomaji) + { + var config = generatorConfig(nameof(JaRomajiTagGeneratorConfig.Uppercase)); + RunRomajiCheckTest(text, actualRomaji, config); } #region test helper - protected void RunRomajiCheckTest(string text, string[] romaji, JaRomajiTagGeneratorConfig config) + protected void RunRomajiCheckTest(string text, string[] actualRomaji, JaRomajiTagGeneratorConfig config) { var generator = new JaRomajiTagGenerator(config); var lyric = new Lyric { Text = text }; var romajiTags = generator.CreateRomajiTags(lyric); + var actualRomajiTags = TestCaseTagHelper.ParseRomajiTags(actualRomaji); - Assert.AreEqual(romajiTags.Length, romajiTags.Length); - - foreach (var romajiTag in romajiTags) - { - Assert.IsTrue(romaji.Contains(romajiTag.Text)); - } + Assert.AreEqual(romajiTags, actualRomajiTags); } private JaRomajiTagGeneratorConfig generatorConfig(params string[] properties) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs index 20a48cf99..838c08c22 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs @@ -56,7 +56,6 @@ public override RomajiTag[] CreateRomajiTags(Lyric lyric) if (Config.Uppercase) romaji = romaji.ToUpper(); - // Make tag tags.Add(new RomajiTag { From f849aa6129df31fe80633cd71be42ff5063b26d9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 22:44:29 +0900 Subject: [PATCH 5/6] Fix test case and generator. --- .../RomajiTags/Ja/JaRomajiTagGeneratorTest.cs | 2 +- .../RomajiTags/Ja/JaRomajiTagGenerator.cs | 48 ++++++++++++++++--- .../RubyTags/Ja/JaRubyTagGenerator.cs | 2 +- .../Utils/TextTagsUtils.cs | 12 +++++ 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs index 915e441f9..826e5009d 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs @@ -21,7 +21,7 @@ public void TestCreateRomajiTags(string text, string[] actualRomaji) } [TestCase("花火大会", new[] { "[0,2]:HANABI", "[2,4]:TAIKAI" })] - [TestCase("はなび", new string[] { "[0,3]:hanabi" })] + [TestCase("はなび", new string[] { "[0,3]:HANABI" })] public void TestCreateRomajiTagsWithUppercase(string text, string[] actualRomaji) { var config = generatorConfig(nameof(JaRomajiTagGeneratorConfig.Uppercase)); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs index 838c08c22..caaf3f951 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using Lucene.Net.Analysis; using Lucene.Net.Analysis.Ja; using Lucene.Net.Analysis.TokenAttributes; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Utils; @@ -28,7 +30,7 @@ public JaRomajiTagGenerator(JaRomajiTagGeneratorConfig config) public override RomajiTag[] CreateRomajiTags(Lyric lyric) { var text = lyric.Text; - var tags = new List(); + var processingTags = new List(); // Tokenize the text var tokenStream = analyzer.GetTokenStream("dummy", new StringReader(text)); @@ -51,17 +53,24 @@ public override RomajiTag[] CreateRomajiTags(Lyric lyric) if (string.IsNullOrEmpty(katakana)) break; + var parentText = text[offsetAtt.StartOffset..offsetAtt.EndOffset]; + var fromKanji = JpStringUtils.ToKatakana(katakana) != JpStringUtils.ToKatakana(parentText); + // Convert to romaji. var romaji = JpStringUtils.ToRomaji(katakana); if (Config.Uppercase) romaji = romaji.ToUpper(); // Make tag - tags.Add(new RomajiTag + processingTags.Add(new RomajiTagGeneratorPatameter { - Text = romaji, - StartIndex = offsetAtt.StartOffset, - EndIndex = offsetAtt.EndOffset + FromKanji = fromKanji, + RomajiTag = new RomajiTag + { + Text = romaji, + StartIndex = offsetAtt.StartOffset, + EndIndex = offsetAtt.EndOffset + } }); } @@ -69,7 +78,34 @@ public override RomajiTag[] CreateRomajiTags(Lyric lyric) tokenStream.End(); tokenStream.Dispose(); - return tags.ToArray(); + var romajiTags = new List(); + + foreach (var processingTag in processingTags) + { + // conbine romajies of they are not from kanji. + var previousProcessingTag = processingTags.GetPrevious(processingTag); + var fromKanji = processingTag.FromKanji; + var previousFromKanji = previousProcessingTag?.FromKanji ?? true; + if (!fromKanji && !previousFromKanji) + { + var combinedRomajiTag = TextTagsUtils.Combine(previousProcessingTag.RomajiTag, processingTag.RomajiTag); + romajiTags.Remove(previousProcessingTag.RomajiTag); + romajiTags.Add(combinedRomajiTag); + } + else + { + romajiTags.Add(processingTag.RomajiTag); + } + } + + return romajiTags.ToArray(); + } + + internal class RomajiTagGeneratorPatameter + { + public bool FromKanji { get; set; } + + public RomajiTag RomajiTag { get; set; } } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RubyTags/Ja/JaRubyTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RubyTags/Ja/JaRubyTagGenerator.cs index e0b24b95d..7b46bc664 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RubyTags/Ja/JaRubyTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RubyTags/Ja/JaRubyTagGenerator.cs @@ -57,7 +57,7 @@ public override RubyTag[] CreateRubyTags(Lyric lyric) if (!Config.EnableDuplicatedRuby) { // Not add duplicated ruby if same as parent. - var parentText = text.Substring(offsetAtt.StartOffset, offsetAtt.EndOffset - offsetAtt.StartOffset); + var parentText = text[offsetAtt.StartOffset..offsetAtt.EndOffset]; if (parentText == katakana || parentText == hiragana) continue; } diff --git a/osu.Game.Rulesets.Karaoke/Utils/TextTagsUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/TextTagsUtils.cs index c7a88889b..7fd5013e5 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/TextTagsUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/TextTagsUtils.cs @@ -67,6 +67,7 @@ public static T[] FindInvalid(T[] textTags, string lyric, Sorting sorting = S return Sort(invalidList.Distinct().ToArray()); } + // todo : might think about better way for lyric merging ruby or romaji using. public static T Shifting(T textTag, int shifting) where T : ITextTag, new() { return new T @@ -77,6 +78,17 @@ public static T[] FindInvalid(T[] textTags, string lyric, Sorting sorting = S }; } + public static T Combine(T textTagA, T textTagB) where T : ITextTag, new() + { + var sortinValue = Sort(new[] { textTagA, textTagB }); + return new T + { + StartIndex = sortinValue[0].StartIndex, + EndIndex = sortinValue[1].EndIndex, + Text = sortinValue[0].Text + sortinValue[1].Text + }; + } + public enum Sorting { /// From e9828794893b5ea767e4f4f0a0063377f84d4c27 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 21 Dec 2020 23:22:21 +0900 Subject: [PATCH 6/6] Change algorithm to let romaji more understandable. --- .../Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs | 2 +- .../Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs index 826e5009d..3eca7eaa3 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/Generator/RomajiTags/Ja/JaRomajiTagGeneratorTest.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Linq; using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja; using osu.Game.Rulesets.Karaoke.Objects; @@ -14,6 +13,7 @@ public class JaRomajiTagGeneratorTest { [TestCase("花火大会", new[] { "[0,2]:hanabi", "[2,4]:taikai" })] [TestCase("はなび", new string[] { "[0,3]:hanabi" })] + [TestCase("枯れた世界に輝く", new[] { "[0,3]:kareta", "[3,6]:sekaini", "[6,8]:kagayaku" })] public void TestCreateRomajiTags(string text, string[] actualRomaji) { var config = generatorConfig(null); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs index caaf3f951..dab043993 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/RomajiTags/Ja/JaRomajiTagGenerator.cs @@ -85,8 +85,7 @@ public override RomajiTag[] CreateRomajiTags(Lyric lyric) // conbine romajies of they are not from kanji. var previousProcessingTag = processingTags.GetPrevious(processingTag); var fromKanji = processingTag.FromKanji; - var previousFromKanji = previousProcessingTag?.FromKanji ?? true; - if (!fromKanji && !previousFromKanji) + if (previousProcessingTag != null && !fromKanji) { var combinedRomajiTag = TextTagsUtils.Combine(previousProcessingTag.RomajiTag, processingTag.RomajiTag); romajiTags.Remove(previousProcessingTag.RomajiTag);