Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Aug 19, 2024
1 parent 1c2f260 commit 9a20ff7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace JL.Core.Dicts.EPWING.Nazeka;

internal static class EpwingNazekaDBManager
{
public const int Version = 2;
public const int Version = 3;

private const string SingleTermQuery =
"""
Expand Down
9 changes: 5 additions & 4 deletions JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static async Task Load(Dict dict)

IDictionary<string, IList<IDictRecord>> nazekaEpwingDict = dict.Contents;

bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiNazeka;
bool nonNameDict = dict.Type is not DictType.NonspecificNameNazeka;

foreach (JsonElement jsonObj in jsonObjects!.Skip(1))
{
string reading = jsonObj.GetProperty("r").GetString()!.GetPooledString();
Expand Down Expand Up @@ -72,15 +75,13 @@ public static async Task Load(Dict dict)
continue;
}

bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiNazeka;

string primarySpellingInHiragana = nonKanjiDict
? JapaneseUtils.KatakanaToHiragana(primarySpelling).GetPooledString()
: primarySpelling.GetPooledString();

EpwingNazekaRecord record = new(primarySpelling, reading, spellingList.RemoveAtToArray(0), definitions);
AddRecordToDictionary(primarySpellingInHiragana, record, nazekaEpwingDict);
if (nonKanjiDict && dict.Type is not DictType.NonspecificNameNazeka)
if (nonKanjiDict && nonNameDict)
{
string readingInHiragana = JapaneseUtils.KatakanaToHiragana(reading).GetPooledString();
if (primarySpellingInHiragana != readingInHiragana)
Expand Down Expand Up @@ -117,7 +118,7 @@ public static async Task Load(Dict dict)
}

EpwingNazekaRecord record = new(reading, null, null, definitions);
AddRecordToDictionary(JapaneseUtils.KatakanaToHiragana(reading).GetPooledString(), record, nazekaEpwingDict);
AddRecordToDictionary(nonKanjiDict ? JapaneseUtils.KatakanaToHiragana(reading).GetPooledString() : reading, record, nazekaEpwingDict);
}
}

Expand Down
10 changes: 6 additions & 4 deletions JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static async Task Load(Dict dict)
IEnumerable<string> jsonFiles = Directory.EnumerateFiles(fullPath, "*_bank_*.json", SearchOption.TopDirectoryOnly)
.Where(static s => s.Contains("term", StringComparison.Ordinal) || s.Contains("kanji", StringComparison.Ordinal));

bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiWithWordSchemaYomichan;
bool nonNameDict = dict.Type is not DictType.NonspecificNameYomichan;

foreach (string jsonFile in jsonFiles)
{
List<List<JsonElement>>? jsonElementLists;
Expand All @@ -39,7 +42,7 @@ public static async Task Load(Dict dict)
EpwingYomichanRecord? record = GetEpwingYomichanRecord(jsonElements, dict);
if (record is not null)
{
AddToDictionary(record, dict);
AddToDictionary(record, dict, nonKanjiDict, nonNameDict);
}
}
}
Expand Down Expand Up @@ -101,9 +104,8 @@ public static async Task Load(Dict dict)
return new EpwingYomichanRecord(primarySpelling, reading, definitions, wordClasses, definitionTags);
}

private static void AddToDictionary(EpwingYomichanRecord yomichanRecord, Dict dict)
private static void AddToDictionary(EpwingYomichanRecord yomichanRecord, Dict dict, bool nonKanjiDict, bool nonNameDict)
{
bool nonKanjiDict = dict.Type is not DictType.NonspecificKanjiWithWordSchemaYomichan;
string primarySpellingInHiragana = nonKanjiDict
? JapaneseUtils.KatakanaToHiragana(yomichanRecord.PrimarySpelling).GetPooledString()
: yomichanRecord.PrimarySpelling.GetPooledString();
Expand All @@ -117,7 +119,7 @@ private static void AddToDictionary(EpwingYomichanRecord yomichanRecord, Dict di
dict.Contents[primarySpellingInHiragana] = [yomichanRecord];
}

if (nonKanjiDict && dict.Type is not DictType.NonspecificNameYomichan && !string.IsNullOrEmpty(yomichanRecord.Reading))
if (nonKanjiDict && nonNameDict && yomichanRecord.Reading is not null)
{
string readingInHiragana = JapaneseUtils.KatakanaToHiragana(yomichanRecord.Reading).GetPooledString();
if (primarySpellingInHiragana != readingInHiragana)
Expand Down
12 changes: 6 additions & 6 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private bool CopyText(string text)
return false;
}

text = TextUtils.SanitizeText(text);
if (text.Length is 0)
string sanitizedText = TextUtils.SanitizeText(text);
if (sanitizedText.Length is 0)
{
return false;
}
Expand All @@ -175,13 +175,13 @@ private bool CopyText(string text)

mergeTexts = (ConfigManager.MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds is 0
|| (preciseTimeNow - s_lastTextCopyTime).TotalMilliseconds < ConfigManager.MaxDelayBetweenCopiesForMergingMatchingSequentialTextsInMilliseconds)
&& text.StartsWith(MainTextBox.Text, StringComparison.Ordinal);
&& sanitizedText.StartsWith(MainTextBox.Text, StringComparison.Ordinal);

s_lastTextCopyTime = preciseTimeNow;

if (mergeTexts)
{
subsequentText = text[MainTextBox.Text.Length..];
subsequentText = sanitizedText[MainTextBox.Text.Length..];
}
}

Expand All @@ -193,7 +193,7 @@ private bool CopyText(string text)
}
else
{
MainTextBox.Text = text;
MainTextBox.Text = sanitizedText;
}

MainTextBox.Foreground = ConfigManager.MainWindowTextColor;
Expand All @@ -215,7 +215,7 @@ private bool CopyText(string text)
BringToFront();
}, DispatcherPriority.Send);

HandlePostCopy(text, subsequentText);
HandlePostCopy(sanitizedText, subsequentText);

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions JL.Windows/GUI/PreferencesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@
</DockPanel>

<DockPanel>
<TextBlock HorizontalAlignment="Left" Text="Merge sequential texts when they match"
<TextBlock HorizontalAlignment="Left" Text="Mergse sequential texts when they match"
Style="{StaticResource TextBlockDefault}"
TextWrapping="Wrap" VerticalAlignment="Center"
Cursor="Help"
ToolTip="If the new text found in Clipboard/WebSocket starts with the current text
&#10;then simply append the subsequent text to the current text, instead of copying it as a new text.
&#10;then the subsequent text is simply appended to the current text, instead of being copied as a new text.
&#10;For example, if the current text is 我が and 我が妹よ is the next text found in Clipboard/WebSocket, 妹よ is appended to 我が.
&#10;This is useful when you feed JL with real-time generated text as it is being generated.
&#10;This is mainly useful when you feed JL with real-time generated text as it is being generated.
&#10;It keeps the statistics accurate and prevents unwanted scroll up." />
<CheckBox x:Name="MergeSequentialTextsWhenTheyMatchCheckBox" HorizontalAlignment="Right" />
</DockPanel>
Expand Down

0 comments on commit 9a20ff7

Please sign in to comment.