diff --git a/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs b/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs index af622809..ae40e86b 100644 --- a/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs +++ b/JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs @@ -104,24 +104,26 @@ public int GetFrequency(Freq freq) } } - if (frequency is int.MaxValue && AlternativeSpellings is not null) + if (frequency is not int.MaxValue || AlternativeSpellings is null) { - for (int i = 0; i < AlternativeSpellings.Length; i++) + return frequency; + } + + for (int i = 0; i < AlternativeSpellings.Length; i++) + { + if (freq.Contents.TryGetValue( + JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), + out IList? alternativeSpellingFreqResults)) { - if (freq.Contents.TryGetValue( - JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), - out IList? alternativeSpellingFreqResults)) + int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; + for (int j = 0; j < alternativeSpellingFreqResultCount; j++) { - int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; - for (int j = 0; j < alternativeSpellingFreqResultCount; j++) + FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; + if (Readings?.Contains(alternativeSpellingFreqResult.Spelling) ?? false) { - FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; - if (Readings?.Contains(alternativeSpellingFreqResult.Spelling) ?? false) + if (frequency > alternativeSpellingFreqResult.Frequency) { - if (frequency > alternativeSpellingFreqResult.Frequency) - { - frequency = alternativeSpellingFreqResult.Frequency; - } + frequency = alternativeSpellingFreqResult.Frequency; } } } @@ -244,10 +246,7 @@ public override int GetHashCode() { unchecked { - int hash = 17; - - hash = (hash * 37) + PrimarySpelling.GetHashCode(StringComparison.Ordinal); - + int hash = (17 * 37) + PrimarySpelling.GetHashCode(StringComparison.Ordinal); if (AlternativeSpellings is not null) { foreach (string alternativeSpelling in AlternativeSpellings) diff --git a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs index d8b7ab1b..c0044ddc 100644 --- a/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs +++ b/JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs @@ -65,47 +65,45 @@ public int GetFrequency(Freq freq) } } - if (frequency is int.MaxValue && AlternativeSpellings is not null) + if (frequency is not int.MaxValue || AlternativeSpellings is null) { - for (int i = 0; i < AlternativeSpellings.Length; i++) + return frequency; + } + + for (int i = 0; i < AlternativeSpellings.Length; i++) + { + if (freq.Contents.TryGetValue( + JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), + out IList? alternativeSpellingFreqResults)) { - if (freq.Contents.TryGetValue( - JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), - out IList? alternativeSpellingFreqResults)) + int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; + for (int j = 0; j < alternativeSpellingFreqResultCount; j++) { - int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; - for (int j = 0; j < alternativeSpellingFreqResultCount; j++) + FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; + if (Reading == alternativeSpellingFreqResult.Spelling) { - FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; - if (Reading == alternativeSpellingFreqResult.Spelling) + if (frequency > alternativeSpellingFreqResult.Frequency) { - if (frequency > alternativeSpellingFreqResult.Frequency) - { - frequency = alternativeSpellingFreqResult.Frequency; - } + frequency = alternativeSpellingFreqResult.Frequency; } } } } } } - - else if (Reading is not null) + else if (Reading is not null + && freq.Contents.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out IList? readingFreqResults)) { - if (freq.Contents.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), - out IList? readingFreqResults)) + int readingFreqResultCount = readingFreqResults.Count; + for (int i = 0; i < readingFreqResultCount; i++) { - int readingFreqResultCount = readingFreqResults.Count; - for (int i = 0; i < readingFreqResultCount; i++) + FrequencyRecord readingFreqResult = readingFreqResults[i]; + if ((Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) + || (AlternativeSpellings?.Contains(readingFreqResult.Spelling) ?? false)) { - FrequencyRecord readingFreqResult = readingFreqResults[i]; - if ((Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) - || (AlternativeSpellings?.Contains(readingFreqResult.Spelling) ?? false)) + if (frequency > readingFreqResult.Frequency) { - if (frequency > readingFreqResult.Frequency) - { - frequency = readingFreqResult.Frequency; - } + frequency = readingFreqResult.Frequency; } } } @@ -133,22 +131,24 @@ public int GetFrequencyFromDB(Dictionary> freqDict } } - if (frequency is int.MaxValue && AlternativeSpellings is not null) + if (frequency is not int.MaxValue || AlternativeSpellings is null) { - for (int i = 0; i < AlternativeSpellings.Length; i++) + return frequency; + } + + for (int i = 0; i < AlternativeSpellings.Length; i++) + { + if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), out List? alternativeSpellingFreqResults)) { - if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), out List? alternativeSpellingFreqResults)) + int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; + for (int j = 0; j < alternativeSpellingFreqResultCount; j++) { - int alternativeSpellingFreqResultCount = alternativeSpellingFreqResults.Count; - for (int j = 0; j < alternativeSpellingFreqResultCount; j++) + FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; + if (Reading == alternativeSpellingFreqResult.Spelling) { - FrequencyRecord alternativeSpellingFreqResult = alternativeSpellingFreqResults[j]; - if (Reading == alternativeSpellingFreqResult.Spelling) + if (frequency > alternativeSpellingFreqResult.Frequency) { - if (frequency > alternativeSpellingFreqResult.Frequency) - { - frequency = alternativeSpellingFreqResult.Frequency; - } + frequency = alternativeSpellingFreqResult.Frequency; } } } @@ -156,22 +156,19 @@ public int GetFrequencyFromDB(Dictionary> freqDict } } - else if (Reading is not null) + else if (Reading is not null + && freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List? readingFreqResults)) { - if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List? readingFreqResults)) + int readingFreqResultCount = readingFreqResults.Count; + for (int i = 0; i < readingFreqResultCount; i++) { - int readingFreqResultCount = readingFreqResults.Count; - for (int i = 0; i < readingFreqResultCount; i++) + FrequencyRecord readingFreqResult = readingFreqResults[i]; + if ((Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) + || (AlternativeSpellings?.Contains(readingFreqResult.Spelling) ?? false)) { - FrequencyRecord readingFreqResult = readingFreqResults[i]; - - if ((Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) - || (AlternativeSpellings?.Contains(readingFreqResult.Spelling) ?? false)) + if (frequency > readingFreqResult.Frequency) { - if (frequency > readingFreqResult.Frequency) - { - frequency = readingFreqResult.Frequency; - } + frequency = readingFreqResult.Frequency; } } } diff --git a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs index 1a9106e9..4512e797 100644 --- a/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs +++ b/JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs @@ -130,20 +130,18 @@ public int GetFrequencyFromDB(Dictionary> freqDict } } - else if (Reading is not null) + else if (Reading is not null + && freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List? readingFreqResults)) { - if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List? readingFreqResults)) + int readingFreqResultCount = readingFreqResults.Count; + for (int i = 0; i < readingFreqResultCount; i++) { - int readingFreqResultCount = readingFreqResults.Count; - for (int i = 0; i < readingFreqResultCount; i++) + FrequencyRecord readingFreqResult = readingFreqResults[i]; + if (Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) { - FrequencyRecord readingFreqResult = readingFreqResults[i]; - if (Reading == readingFreqResult.Spelling && JapaneseUtils.IsKatakana(Reading[0])) + if (frequency > readingFreqResult.Frequency) { - if (frequency > readingFreqResult.Frequency) - { - frequency = readingFreqResult.Frequency; - } + frequency = readingFreqResult.Frequency; } } } diff --git a/JL.Core/Freqs/FreqDBManager.cs b/JL.Core/Freqs/FreqDBManager.cs index 3e82afdf..2e0276d3 100644 --- a/JL.Core/Freqs/FreqDBManager.cs +++ b/JL.Core/Freqs/FreqDBManager.cs @@ -162,7 +162,6 @@ WHERE rsk.search_key IN (@1 } return results; - } public static List? GetRecordsFromDB(string dbName, string term)