Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 5, 2024
1 parent beedf9a commit d4e81cf
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 77 deletions.
33 changes: 16 additions & 17 deletions JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrequencyRecord>? alternativeSpellingFreqResults))
{
if (freq.Contents.TryGetValue(
JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]),
out IList<FrequencyRecord>? 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;
}
}
}
Expand Down Expand Up @@ -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)
Expand Down
95 changes: 46 additions & 49 deletions JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrequencyRecord>? alternativeSpellingFreqResults))
{
if (freq.Contents.TryGetValue(
JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]),
out IList<FrequencyRecord>? 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<FrequencyRecord>? readingFreqResults))
{
if (freq.Contents.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading),
out IList<FrequencyRecord>? 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;
}
}
}
Expand Down Expand Up @@ -133,45 +131,44 @@ public int GetFrequencyFromDB(Dictionary<string, List<FrequencyRecord>> 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<FrequencyRecord>? alternativeSpellingFreqResults))
{
if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(AlternativeSpellings[i]), out List<FrequencyRecord>? 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
&& freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List<FrequencyRecord>? readingFreqResults))
{
if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List<FrequencyRecord>? 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;
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,18 @@ public int GetFrequencyFromDB(Dictionary<string, List<FrequencyRecord>> freqDict
}
}

else if (Reading is not null)
else if (Reading is not null
&& freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List<FrequencyRecord>? readingFreqResults))
{
if (freqDict.TryGetValue(JapaneseUtils.KatakanaToHiragana(Reading), out List<FrequencyRecord>? 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;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion JL.Core/Freqs/FreqDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ WHERE rsk.search_key IN (@1
}

return results;

}

public static List<FrequencyRecord>? GetRecordsFromDB(string dbName, string term)
Expand Down

0 comments on commit d4e81cf

Please sign in to comment.