diff --git a/JL.Core/Mining/JLField.cs b/JL.Core/Mining/JLField.cs index 80ed0d2d..2e916c14 100644 --- a/JL.Core/Mining/JLField.cs +++ b/JL.Core/Mining/JLField.cs @@ -19,6 +19,7 @@ public enum JLField [Description("Local Time")] LocalTime, Frequencies, [Description("Raw Frequencies")] RawFrequencies, + [Description("Pitch Accents (Numeric)")] NumericPitchAccents, // JMdict, JMnedict, KANJIDIC2 [Description("EDICT ID")] EdictId, diff --git a/JL.Core/Mining/JLFieldUtils.cs b/JL.Core/Mining/JLFieldUtils.cs index cd28b21e..499bcaf2 100644 --- a/JL.Core/Mining/JLFieldUtils.cs +++ b/JL.Core/Mining/JLFieldUtils.cs @@ -22,6 +22,7 @@ public static class JLFieldUtils JLField.DeconjugationProcess, JLField.Frequencies, JLField.RawFrequencies, + JLField.NumericPitchAccents, JLField.EdictId, JLField.LocalTime }; @@ -46,6 +47,7 @@ public static class JLFieldUtils JLField.Sentence, JLField.Frequencies, JLField.RawFrequencies, + JLField.NumericPitchAccents, JLField.EdictId, JLField.LocalTime }; @@ -62,6 +64,7 @@ public static class JLFieldUtils JLField.Image, JLField.SourceText, JLField.Sentence, + JLField.NumericPitchAccents, JLField.EdictId, JLField.LocalTime }; diff --git a/JL.Core/Mining/MiningUtils.cs b/JL.Core/Mining/MiningUtils.cs index a54c0f34..4c454388 100644 --- a/JL.Core/Mining/MiningUtils.cs +++ b/JL.Core/Mining/MiningUtils.cs @@ -2,6 +2,7 @@ using System.Text; using JL.Core.Audio; using JL.Core.Dicts; +using JL.Core.Dicts.PitchAccent; using JL.Core.Lookup; using JL.Core.Mining.Anki; using JL.Core.Network; @@ -131,9 +132,96 @@ private static Dictionary GetMiningParameters(LookupResult look miningParams[JLField.RadicalNames] = string.Join(", ", lookupResult.RadicalNames); } + if (DictUtils.SingleDictTypeDicts.TryGetValue(DictType.PitchAccentYomichan, out Dict? pitchDict)) + { + if (pitchDict.Active) + { + List>? pitchAccents = GetPitchAccents(lookupResult.PitchAccentDict ?? pitchDict.Contents, lookupResult); + if (pitchAccents is not null) + { + StringBuilder numericPitchAccentBuilder = new(); + for (int i = 0; i < pitchAccents.Count; i++) + { + KeyValuePair pitchAccent = pitchAccents[i]; + _ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{pitchAccent.Key}: {pitchAccent.Value}, "); + } + + _ = numericPitchAccentBuilder.Remove(numericPitchAccentBuilder.Length - 2, 2); + miningParams[JLField.NumericPitchAccents] = numericPitchAccentBuilder.ToString(); + } + } + } + return miningParams; } + private static List>? GetPitchAccents(Dictionary> pitchDict, LookupResult lookupResult) + { + List> pitchAccents = new(); + + if (lookupResult.Readings is not null) + { + for (int i = 0; i < lookupResult.Readings.Length; i++) + { + string reading = lookupResult.Readings[i]; + string readingInHiragana = JapaneseUtils.KatakanaToHiragana(reading); + + if (pitchDict.TryGetValue(readingInHiragana, out IList? pitchResult)) + { + foreach (IDictRecord dictRecord in pitchResult) + { + PitchAccentRecord pitchAccentRecord = (PitchAccentRecord)dictRecord; + if (lookupResult.PrimarySpelling == pitchAccentRecord.Spelling + || (lookupResult.AlternativeSpellings?.Contains(pitchAccentRecord.Spelling) ?? false)) + { + pitchAccents.Add(KeyValuePair.Create(reading, pitchAccentRecord.Position)); + break; + } + } + } + } + } + + else + { + string primarySpellingInHiragana = JapaneseUtils.KatakanaToHiragana(lookupResult.PrimarySpelling); + if (pitchDict.TryGetValue(primarySpellingInHiragana, out IList? pitchResult)) + { + foreach (IDictRecord dictRecord in pitchResult) + { + PitchAccentRecord pitchAccentRecord = (PitchAccentRecord)dictRecord; + if (pitchAccentRecord.Reading is null) + { + pitchAccents.Add(KeyValuePair.Create(lookupResult.PrimarySpelling, pitchAccentRecord.Position)); + break; + } + } + } + + else if (lookupResult.AlternativeSpellings is not null) + { + for (int i = 0; i < lookupResult.AlternativeSpellings.Length; i++) + { + string alternativeSpellingInHiragana = JapaneseUtils.KatakanaToHiragana(lookupResult.AlternativeSpellings[i]); + if (pitchDict.TryGetValue(alternativeSpellingInHiragana, out pitchResult)) + { + foreach (IDictRecord dictRecord in pitchResult) + { + PitchAccentRecord pitchAccentRecord = (PitchAccentRecord)dictRecord; + if (pitchAccentRecord.Reading is null) + { + pitchAccents.Add(KeyValuePair.Create(lookupResult.PrimarySpelling, pitchAccentRecord.Position)); + break; + } + } + } + } + } + } + + return pitchAccents.Count > 0 ? pitchAccents : null; + } + public static async Task MineToFile(LookupResult lookupResult, string currentText, string? selectedDefinitions, int currentCharPosition) { string filePath; diff --git a/JL.Windows/GUI/PreferencesWindow.xaml.cs b/JL.Windows/GUI/PreferencesWindow.xaml.cs index f304febd..0c2880be 100644 --- a/JL.Windows/GUI/PreferencesWindow.xaml.cs +++ b/JL.Windows/GUI/PreferencesWindow.xaml.cs @@ -63,6 +63,7 @@ public static bool IsItVisible() • Deconjugation Process: Deconjugation path from the "Matched Text" to "Deconjugated Matched Text". • Frequencies: Frequency info for the mined word, e.g., "VN: 77, jpdb: 666". • Raw Frequencies: Raw frequency info for the mined word, e.g., "77, 666". + • Pitch Accents (Numeric): Pitch accents for the mined word in numeric form, e.g., おんな: 3, おみな: 0, おうな: 1 • EDICT ID: JMDict entry ID. • Local Time: Mining date and time expressed in local timezone. """; @@ -84,6 +85,7 @@ public static bool IsItVisible() • Sentence: Sentence in which the mined kanji appears in. • Frequencies: Frequency info for the kanji, e.g., "KANJIDIC2: 77, jpdb: 666". • Raw Frequencies: Raw frequency info for the mined word, e.g., "77, 666". + • Pitch Accents (Numeric): Pitch accents for the mined word in numeric form, e.g., おんな: 3, おみな: 0, おうな: 1 • EDICT ID: KANJIDIC2 entry ID. • Local Time: Mining date and time expressed in local timezone. """; @@ -97,6 +99,7 @@ public static bool IsItVisible() • Dictionary Name: Name of the dictionary, e.g., "JMnedict". • Source Text: Whole text in which the mined name appears in. • Sentence: Sentence in which the mined name appears in. + • Pitch Accents (Numeric): Pitch accents for the mined word in numeric form, e.g., おんな: 3, おみな: 0, おうな: 1 • EDICT ID: JMnedict entry ID. • Local Time: Mining date and time expressed in local timezone. """;