Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 14, 2024
1 parent 94b38fb commit 322259e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
15 changes: 6 additions & 9 deletions JL.Core/Lookup/LookupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,24 +1158,21 @@ private static List<LookupResult> BuildJmnedictResult(

private static List<LookupResult> BuildKanjidicResult(IDictionary<string, IntermediaryResult> kanjiResults, bool useDBForPitchDict, Dict? pitchDict, List<Freq> kanjiFreqs)
{
KeyValuePair<string, IntermediaryResult> dictResult = kanjiResults.First();
(string kanji, IntermediaryResult intermediaryResult) = kanjiResults.First();

Dictionary<string, IList<IDictRecord>>? pitchAccentDict = useDBForPitchDict
? YomichanPitchAccentDBManager.GetRecordsFromDB(pitchDict!.Name, dictResult.Key)
? YomichanPitchAccentDBManager.GetRecordsFromDB(pitchDict!.Name, kanji)
: null;

List<IList<IDictRecord>> iResult = dictResult.Value.Results;
KanjidicRecord kanjiRecord = (KanjidicRecord)iResult[0][0];
KanjidicRecord kanjiRecord = (KanjidicRecord)intermediaryResult.Results[0][0];

string[]? allReadings = Utils.ConcatNullableArrays(kanjiRecord.OnReadings, kanjiRecord.KunReadings, kanjiRecord.NanoriReadings);

IntermediaryResult intermediaryResult = kanjiResults.First().Value;

_ = DictUtils.KanjiCompositionDict.TryGetValue(dictResult.Key, out string? kanjiComposition);
_ = DictUtils.KanjiCompositionDict.TryGetValue(kanji, out string? kanjiComposition);

LookupResult result = new
(
primarySpelling: dictResult.Key,
primarySpelling: kanji,
readings: allReadings,
onReadings: kanjiRecord.OnReadings,
kunReadings: kanjiRecord.KunReadings,
Expand All @@ -1184,7 +1181,7 @@ private static List<LookupResult> BuildKanjidicResult(IDictionary<string, Interm
strokeCount: kanjiRecord.StrokeCount,
kanjiGrade: kanjiRecord.Grade,
kanjiComposition: kanjiComposition,
frequencies: GetKanjidicFrequencies(dictResult.Key, kanjiRecord.Frequency, kanjiFreqs),
frequencies: GetKanjidicFrequencies(kanji, kanjiRecord.Frequency, kanjiFreqs),
matchedText: intermediaryResult.MatchedText,
deconjugatedMatchedText: intermediaryResult.DeconjugatedMatchedText,
dict: intermediaryResult.Dict,
Expand Down
40 changes: 20 additions & 20 deletions JL.Core/Mining/MiningUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public static class MiningUtils
int pitchAccentCount = pitchAccents.Count;
for (int i = 0; i < pitchAccentCount; i++)
{
KeyValuePair<string, byte> pitchAccent = pitchAccents[i];
_ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(pitchAccent.Key, pitchAccent.Value));
(string expression, byte position) = pitchAccents[i];
_ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(expression, position));

if (i + 1 != pitchAccentCount)
{
Expand All @@ -305,8 +305,8 @@ public static class MiningUtils
int pitchAccentCount = pitchAccents.Count;
for (int i = 0; i < pitchAccentCount; i++)
{
KeyValuePair<string, byte> pitchAccent = pitchAccents[i];
_ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{pitchAccent.Key}: {pitchAccent.Value}");
(string expression, byte position) = pitchAccents[i];
_ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{expression}: {position}");

if (i + 1 != pitchAccentCount)
{
Expand All @@ -327,11 +327,11 @@ public static class MiningUtils
List<KeyValuePair<string, byte>>? pitchAccents = GetPitchAccents(lookupResult.PitchAccentDict ?? pitchDict.Contents, lookupResult);
if (pitchAccents is not null)
{
KeyValuePair<string, byte> firstPitchAccentKeyValuePair = pitchAccents[0];
if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0])
|| (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling))
(string expression, byte position) = pitchAccents[0];
if ((lookupResult.Readings is not null && expression == lookupResult.Readings[0])
|| (lookupResult.Readings is null && expression == lookupResult.PrimarySpelling))
{
return string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstPitchAccentKeyValuePair.Key, firstPitchAccentKeyValuePair.Value)}");
return string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(expression, position)}");
}
}
}
Expand All @@ -345,11 +345,11 @@ public static class MiningUtils
List<KeyValuePair<string, byte>>? pitchAccents = GetPitchAccents(lookupResult.PitchAccentDict ?? pitchDict.Contents, lookupResult);
if (pitchAccents is not null)
{
KeyValuePair<string, byte> firstPitchAccentKeyValuePair = pitchAccents[0];
if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0])
|| (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling))
(string expression, byte position) = pitchAccents[0];
if ((lookupResult.Readings is not null && expression == lookupResult.Readings[0])
|| (lookupResult.Readings is null && expression == lookupResult.PrimarySpelling))
{
return string.Create(CultureInfo.InvariantCulture, $"{firstPitchAccentKeyValuePair.Key}: {firstPitchAccentKeyValuePair.Value}");
return string.Create(CultureInfo.InvariantCulture, $"{expression}: {position}");
}
}
}
Expand Down Expand Up @@ -539,9 +539,9 @@ private static Dictionary<JLField, string> GetMiningParameters(LookupResult look
int pitchAccentCount = pitchAccents.Count;
for (int i = 0; i < pitchAccentCount; i++)
{
KeyValuePair<string, byte> pitchAccent = pitchAccents[i];
_ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{pitchAccent.Key}: {pitchAccent.Value}");
_ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(pitchAccent.Key, pitchAccent.Value));
(string expression, byte position) = pitchAccents[i];
_ = numericPitchAccentBuilder.Append(CultureInfo.InvariantCulture, $"{expression}: {position}");
_ = expressionsWithPitchAccentBuilder.Append(GetExpressionWithPitchAccent(expression, position));

if (i + 1 != pitchAccentCount)
{
Expand All @@ -553,12 +553,12 @@ private static Dictionary<JLField, string> GetMiningParameters(LookupResult look
miningParams[JLField.NumericPitchAccents] = numericPitchAccentBuilder.ToString();
miningParams[JLField.PitchAccents] = expressionsWithPitchAccentBuilder.ToString();

KeyValuePair<string, byte> firstPitchAccentKeyValuePair = pitchAccents[0];
if ((lookupResult.Readings is not null && firstPitchAccentKeyValuePair.Key == lookupResult.Readings[0])
|| (lookupResult.Readings is null && firstPitchAccentKeyValuePair.Key == lookupResult.PrimarySpelling))
(string firstExpression, byte firstPosition) = pitchAccents[0];
if ((lookupResult.Readings is not null && firstExpression == lookupResult.Readings[0])
|| (lookupResult.Readings is null && firstExpression == lookupResult.PrimarySpelling))
{
miningParams[JLField.PitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstPitchAccentKeyValuePair.Key, firstPitchAccentKeyValuePair.Value)}");
miningParams[JLField.NumericPitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{firstPitchAccentKeyValuePair.Key}: {firstPitchAccentKeyValuePair.Value}");
miningParams[JLField.PitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{PitchAccentStyle}\n\n{GetExpressionWithPitchAccent(firstExpression, firstPosition)}");
miningParams[JLField.NumericPitchAccentForFirstReading] = string.Create(CultureInfo.InvariantCulture, $"{firstExpression}: {firstPosition}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/ManageDictionariesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ private static string EntityDictToString(Dictionary<string, string> entityDict)

StringBuilder sb = new();
IOrderedEnumerable<KeyValuePair<string, string>> sortedJmdictEntities = entityDict.OrderBy(static e => e.Key, StringComparer.InvariantCulture);
foreach (KeyValuePair<string, string> entity in sortedJmdictEntities)
foreach ((string name, string description) in sortedJmdictEntities)
{
_ = sb.Append(CultureInfo.InvariantCulture, $"{entity.Key}: {entity.Value}\n");
_ = sb.Append(CultureInfo.InvariantCulture, $"{name}: {description}\n");
}

return sb.ToString(0, sb.Length - 1);
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ public static void AddHotKeyToGlobalKeyGestureDict(string hotkeyName, KeyGesture

public static void RegisterAllGlobalHotKeys(nint windowHandle)
{
foreach (KeyValuePair<int, KeyGesture> keyValuePair in KeyGestureUtils.GlobalKeyGestureDict)
foreach ((int id, KeyGesture keyGesture) in KeyGestureUtils.GlobalKeyGestureDict)
{
_ = RegisterHotKey(windowHandle, keyValuePair.Key, (uint)keyValuePair.Value.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyValuePair.Value.Key));
_ = RegisterHotKey(windowHandle, id, (uint)keyGesture.Modifiers | MOD_NOREPEAT, (uint)KeyInterop.VirtualKeyFromKey(keyGesture.Key));
}
}

Expand Down

0 comments on commit 322259e

Please sign in to comment.