Skip to content

Commit

Permalink
Add "Leading Source Text Part" and "Trailing Sentence Text Part" fiel…
Browse files Browse the repository at this point in the history
…ds for mining
  • Loading branch information
rampaa committed Nov 2, 2024
1 parent 0db48a0 commit 9607936
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion JL.Core/Mining/JLField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public enum JLField
[Description("Dictionary Name")] DictionaryName,
Audio,
Image,
[Description("Source Text")] SourceText,
[Description("Leading Source Text Part")] LeadingSourceTextPart,
[Description("Trailing Source Text Part")] TrailingSourceTextPart,
Sentence,
[Description("Leading Sentence Part")] LeadingSentencePart,
[Description("Trailing Sentence Part")] TrailingSentencePart,
[Description("Source Text")] SourceText,
[Description("Matched Text")] MatchedText,
[Description("Local Time")] LocalTime,
Frequencies,
Expand Down
6 changes: 6 additions & 0 deletions JL.Core/Mining/JLFieldUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public static class JLFieldUtils
JLField.Audio,
JLField.Image,
JLField.SourceText,
JLField.LeadingSourceTextPart,
JLField.TrailingSourceTextPart,
JLField.Sentence,
JLField.LeadingSentencePart,
JLField.TrailingSentencePart,
Expand Down Expand Up @@ -54,6 +56,8 @@ public static class JLFieldUtils
JLField.Audio,
JLField.Image,
JLField.SourceText,
JLField.LeadingSourceTextPart,
JLField.TrailingSourceTextPart,
JLField.Sentence,
JLField.LeadingSentencePart,
JLField.TrailingSentencePart,
Expand Down Expand Up @@ -81,6 +85,8 @@ public static class JLFieldUtils
JLField.Audio,
JLField.Image,
JLField.SourceText,
JLField.LeadingSourceTextPart,
JLField.TrailingSourceTextPart,
JLField.Sentence,
JLField.LeadingSentencePart,
JLField.TrailingSentencePart,
Expand Down
18 changes: 15 additions & 3 deletions JL.Core/Mining/MiningUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ private static Dictionary<JLField, string> GetMiningParameters(LookupResult look
Dictionary<JLField, string> miningParams = new()
{
[JLField.LocalTime] = DateTime.Now.ToString("s", CultureInfo.InvariantCulture),
[JLField.SourceText] = useHtmlTags
? string.Create(CultureInfo.InvariantCulture, $"{currentText[..currentCharPosition]}<b>{lookupResult.MatchedText}</b>{currentText[(currentCharPosition + lookupResult.MatchedText.Length)..]}").ReplaceLineEndings("<br/>")
: currentText,
[JLField.DictionaryName] = lookupResult.Dict.Name,
[JLField.MatchedText] = lookupResult.MatchedText,
[JLField.DeconjugatedMatchedText] = lookupResult.DeconjugatedMatchedText,
Expand All @@ -91,6 +88,21 @@ private static Dictionary<JLField, string> GetMiningParameters(LookupResult look
: lookupResult.PrimarySpelling
};

string leadingSourcePart = currentText[..currentCharPosition];
string trailingSourcePart = currentText[(currentCharPosition + lookupResult.MatchedText.Length)..];
if (useHtmlTags)
{
leadingSourcePart = leadingSourcePart.ReplaceLineEndings("<br/>");
trailingSourcePart = trailingSourcePart.ReplaceLineEndings("<br/>");
}

miningParams[JLField.LeadingSourceTextPart] = leadingSourcePart;
miningParams[JLField.TrailingSourceTextPart] = trailingSourcePart;

miningParams[JLField.SourceText] = useHtmlTags
? string.Create(CultureInfo.InvariantCulture, $"{leadingSourcePart}<b>{lookupResult.MatchedText}</b>{trailingSourcePart}").ReplaceLineEndings("<br/>")
: currentText;

string sentence = JapaneseUtils.FindSentence(currentText, currentCharPosition);
int searchStartIndex = currentCharPosition + lookupResult.MatchedText.Length - sentence.Length;
if (searchStartIndex < 0 || searchStartIndex >= currentText.Length)
Expand Down
6 changes: 6 additions & 0 deletions JL.Windows/GUI/PreferencesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static bool IsItVisible()
• Audio: Audio for the first reading of the mined word.
• Image: Image found in clipboard at the time of mining.
• Source Text: Whole text in which the mined word appears in.
• Leading Source Text Part: Part of the source text that appears before the matched text.
• Trailing Sentence Text Part: Part of the source that appears after the matched text.
• Sentence: Sentence in which the mined word appears in.
• Leading Sentence Part: Part of the sentence that appears before the matched text. e.g., if the mined word is "大好き" while the sentence is "妹が大好きです", "Leading Sentence Part" will be "妹が".
• Trailing Sentence Part: Part of the sentence that appears after the matched text. e.g., if the mined word is "大好き" while the sentence is "妹が大好きです", "Trailing Sentence Part" will be "です".
Expand Down Expand Up @@ -93,6 +95,8 @@ public static bool IsItVisible()
• Audio: Audio for the first reading of the mined word.
• Image: Image found in clipboard at the time of mining.
• Source Text: Whole text in which the mined kanji appears in.
• Leading Source Text Part: Part of the source text that appears before the mined kanji.
• Trailing Sentence Text Part: Part of the source that appears after the mined kanji.
• Sentence: Sentence in which the mined kanji appears in.
• Leading Sentence Part: Part of the sentence that appears before the mined kanji. e.g., if the mined kanji is "大" while the sentence is "妹が大好きです", "Leading Sentence Part" will be "妹が".
• Trailing Sentence Part: Part of the sentence that appears after the mined kanji. e.g., if the mined kanji is "大" while the sentence is "妹が大好きです", "Trailing Sentence Part" will be "好きです".
Expand All @@ -117,6 +121,8 @@ public static bool IsItVisible()
• Audio: Audio for the first reading of the mined word.
• Image: Image found in clipboard at the time of mining.
• Source Text: Whole text in which the mined name appears in.
• Leading Source Text Part: Part of the source text that appears before the mined name.
• Trailing Sentence Text Part: Part of the source that appears after the mined name.
• Sentence: Sentence in which the mined name appears in.
• Leading Sentence Part: Part of the sentence that appears before the mined name. e.g., if the mined name is "エスト" while the sentence is "俺はエストのことが大好き", "Leading Sentence Part" will be "俺は".
• Trailing Sentence Part: Part of the sentence that appears after the mined name. e.g., if the mined name is "エスト" while the sentence is "俺はエストのことが大好き", "Trailing Sentence Part" will be "のことが大好き".
Expand Down

0 comments on commit 9607936

Please sign in to comment.