@@ -74,16 +74,10 @@ public static class MiningUtils
74
74
</style>
75
75
""" ;
76
76
77
- private static string ? GetMiningParameter ( JLField field , LookupResult lookupResult , string currentText , string ? formattedDefinitions , string ? selectedDefinitions , int currentCharPosition )
77
+ private static string ? GetMiningParameter ( JLField field , LookupResult lookupResult , string currentText , int currentCharPosition )
78
78
{
79
79
switch ( field )
80
80
{
81
- case JLField . Nothing :
82
- case JLField . Audio :
83
- case JLField . Image :
84
- case JLField . LocalTime :
85
- default :
86
- return null ;
87
81
case JLField . LeadingSentencePart :
88
82
{
89
83
string sentence = JapaneseUtils . FindSentence ( currentText , currentCharPosition ) ;
@@ -96,6 +90,7 @@ public static class MiningUtils
96
90
int sentenceStartIndex = currentText . IndexOf ( sentence , searchStartIndex , StringComparison . Ordinal ) ;
97
91
return currentText [ sentenceStartIndex ..currentCharPosition ] ;
98
92
}
93
+
99
94
case JLField . TrailingSentencePart :
100
95
{
101
96
string sentence = JapaneseUtils . FindSentence ( currentText , currentCharPosition ) ;
@@ -108,6 +103,7 @@ public static class MiningUtils
108
103
int sentenceStartIndex = currentText . IndexOf ( sentence , searchStartIndex , StringComparison . Ordinal ) ;
109
104
return currentText [ ( lookupResult . MatchedText . Length + currentCharPosition ) ..( sentenceStartIndex + sentence . Length ) ] ;
110
105
}
106
+
111
107
case JLField . Sentence :
112
108
{
113
109
string sentence = JapaneseUtils . FindSentence ( currentText , currentCharPosition ) ;
@@ -122,93 +118,135 @@ public static class MiningUtils
122
118
string trailingSentencePart = currentText [ ( lookupResult . MatchedText . Length + currentCharPosition ) ..( sentenceStartIndex + sentence . Length ) ] ;
123
119
return $ "{ leadingSentencePart } <b>{ lookupResult . MatchedText } </b>{ trailingSentencePart } ";
124
120
}
121
+
125
122
case JLField . SourceText :
126
123
{
127
124
string leadingSourcePart = currentText [ ..currentCharPosition ] . ReplaceLineEndings ( "<br/>" ) ;
128
125
string trailingSourcePart = currentText [ ( currentCharPosition + lookupResult . MatchedText . Length ) ..] . ReplaceLineEndings ( "<br/>" ) ;
129
126
return $ "{ leadingSourcePart } <b>{ lookupResult . MatchedText } </b>{ trailingSourcePart } ". ReplaceLineEndings ( "<br/>" ) ;
130
127
}
128
+
131
129
case JLField . Readings :
132
- return lookupResult . Readings is not null ? string . Join ( '、' , lookupResult . Readings ) : null ;
130
+ return lookupResult . Readings is not null
131
+ ? string . Join ( '、' , lookupResult . Readings )
132
+ : null ;
133
+
133
134
case JLField . ReadingsWithOrthographyInfo :
134
135
return lookupResult . ReadingsOrthographyInfoList is not null && lookupResult . Readings is not null
135
- ? LookupResultUtils . ElementWithOrthographyInfoToText ( lookupResult . Readings , lookupResult . ReadingsOrthographyInfoList )
136
- : lookupResult . Readings is not null ? string . Join ( '、' , lookupResult . Readings ) : null ;
136
+ ? LookupResultUtils . ElementWithOrthographyInfoToText ( lookupResult . Readings , lookupResult . ReadingsOrthographyInfoList )
137
+ : lookupResult . Readings is not null
138
+ ? string . Join ( '、' , lookupResult . Readings )
139
+ : null ;
140
+
137
141
case JLField . FirstReading :
138
142
return lookupResult . Readings ? [ 0 ] ;
143
+
139
144
case JLField . PrimarySpellingAndReadings :
140
- return lookupResult . Readings is not null ? $ "{ lookupResult . PrimarySpelling } [{ string . Join ( '、' , lookupResult . Readings ) } ]" : null ;
145
+ return lookupResult . Readings is not null
146
+ ? $ "{ lookupResult . PrimarySpelling } [{ string . Join ( '、' , lookupResult . Readings ) } ]"
147
+ : null ;
148
+
141
149
case JLField . PrimarySpellingAndFirstReading :
142
150
return lookupResult . Readings is not null
143
151
? $ "{ lookupResult . PrimarySpelling } [{ lookupResult . Readings [ 0 ] } ]"
144
152
: null ;
153
+
145
154
case JLField . PrimarySpellingWithOrthographyInfo :
146
155
return lookupResult . PrimarySpellingOrthographyInfoList is not null
147
- ? $ "{ lookupResult . PrimarySpelling } ({ string . Join ( ", " , lookupResult . PrimarySpellingOrthographyInfoList ) } )"
148
- : lookupResult . PrimarySpelling ;
156
+ ? $ "{ lookupResult . PrimarySpelling } ({ string . Join ( ", " , lookupResult . PrimarySpellingOrthographyInfoList ) } )"
157
+ : lookupResult . PrimarySpelling ;
158
+
149
159
case JLField . AlternativeSpellings :
150
- return lookupResult . AlternativeSpellings is not null ? string . Join ( '、' , lookupResult . AlternativeSpellings ) : null ;
160
+ return lookupResult . AlternativeSpellings is not null
161
+ ? string . Join ( '、' , lookupResult . AlternativeSpellings )
162
+ : null ;
163
+
151
164
case JLField . AlternativeSpellingsWithOrthographyInfo :
152
- return lookupResult . AlternativeSpellings is not null ? lookupResult . AlternativeSpellingsOrthographyInfoList is not null
165
+ return lookupResult . AlternativeSpellings is not null
166
+ ? lookupResult . AlternativeSpellingsOrthographyInfoList is not null
153
167
? LookupResultUtils . ElementWithOrthographyInfoToText ( lookupResult . AlternativeSpellings , lookupResult . AlternativeSpellingsOrthographyInfoList )
154
- : string . Join ( '、' , lookupResult . AlternativeSpellings ) : null ;
168
+ : string . Join ( '、' , lookupResult . AlternativeSpellings )
169
+ : null ;
170
+
155
171
case JLField . MatchedText :
156
172
return lookupResult . MatchedText ;
173
+
157
174
case JLField . PrimarySpelling :
158
175
return lookupResult . PrimarySpelling ;
176
+
159
177
case JLField . DeconjugatedMatchedText :
160
178
return lookupResult . DeconjugatedMatchedText ;
179
+
161
180
case JLField . KanjiStats :
162
181
return lookupResult . KanjiStats ;
182
+
163
183
case JLField . OnReadings :
164
- return lookupResult . OnReadings is not null ? string . Join ( '、' , lookupResult . OnReadings ) : null ;
184
+ return lookupResult . OnReadings is not null
185
+ ? string . Join ( '、' , lookupResult . OnReadings )
186
+ : null ;
187
+
165
188
case JLField . KunReadings :
166
- return lookupResult . KunReadings is not null ? string . Join ( '、' , lookupResult . KunReadings ) : null ;
189
+ return lookupResult . KunReadings is not null
190
+ ? string . Join ( '、' , lookupResult . KunReadings )
191
+ : null ;
192
+
167
193
case JLField . NanoriReadings :
168
- return lookupResult . NanoriReadings is not null ? string . Join ( '、' , lookupResult . NanoriReadings ) : null ;
194
+ return lookupResult . NanoriReadings is not null
195
+ ? string . Join ( '、' , lookupResult . NanoriReadings )
196
+ : null ;
197
+
169
198
case JLField . EdictId :
170
199
return lookupResult . EdictId > 0
171
200
? lookupResult . EdictId . ToString ( CultureInfo . InvariantCulture )
172
201
: null ;
173
202
174
203
case JLField . DeconjugationProcess :
175
204
return lookupResult . DeconjugationProcess ;
205
+
176
206
case JLField . KanjiComposition :
177
207
return lookupResult . KanjiComposition ;
208
+
178
209
case JLField . StrokeCount :
179
210
return lookupResult . StrokeCount > 0
180
211
? lookupResult . StrokeCount . ToString ( CultureInfo . InvariantCulture )
181
212
: null ;
213
+
182
214
case JLField . KanjiGrade :
183
215
return lookupResult . KanjiGrade != byte . MaxValue
184
216
? lookupResult . KanjiGrade . ToString ( CultureInfo . InvariantCulture )
185
217
: null ;
218
+
186
219
case JLField . RadicalNames :
187
220
return lookupResult . RadicalNames is not null
188
221
? string . Join ( '、' , lookupResult . RadicalNames )
189
222
: null ;
190
- case JLField . Definitions :
191
- return formattedDefinitions ? . ReplaceLineEndings ( "<br/>" ) ;
223
+
192
224
case JLField . SelectedDefinitions :
193
- return selectedDefinitions is not null ? selectedDefinitions . ReplaceLineEndings ( "<br/>" ) : formattedDefinitions ? . ReplaceLineEndings ( "<br/>" ) ;
225
+ case JLField . Definitions :
226
+ return lookupResult . FormattedDefinitions ? . ReplaceLineEndings ( "<br/>" ) ;
227
+
194
228
case JLField . LeadingSourceTextPart :
195
229
return currentText [ ..currentCharPosition ] . ReplaceLineEndings ( "<br/>" ) ;
230
+
196
231
case JLField . TrailingSourceTextPart :
197
232
return currentText [ ( currentCharPosition + lookupResult . MatchedText . Length ) ..] . ReplaceLineEndings ( "<br/>" ) ;
233
+
198
234
case JLField . DictionaryName :
199
235
return lookupResult . Dict . Name ;
236
+
200
237
case JLField . Frequencies :
201
238
return lookupResult . Frequencies is not null
202
239
? LookupResultUtils . FrequenciesToText ( lookupResult . Frequencies , true , lookupResult . Frequencies . Count is 1 )
203
240
: null ;
241
+
204
242
case JLField . RawFrequencies :
205
243
if ( lookupResult . Frequencies is not null )
206
244
{
207
- List < LookupFrequencyResult > validFrequencies = lookupResult . Frequencies
208
- . Where ( static f => f . Freq is > 0 and < int . MaxValue ) . ToList ( ) ;
245
+ List < LookupFrequencyResult > validFrequencies = lookupResult . Frequencies . Where ( static f => f . Freq is > 0 and < int . MaxValue ) . ToList ( ) ;
209
246
return string . Join ( ", " , validFrequencies . Select ( static f => f . Freq ) . ToList ( ) ) ;
210
247
}
211
248
return null ;
249
+
212
250
case JLField . PreferredFrequency :
213
251
if ( lookupResult . Frequencies is not null )
214
252
{
@@ -219,14 +257,15 @@ public static class MiningUtils
219
257
}
220
258
}
221
259
return null ;
260
+
222
261
case JLField . FrequencyHarmonicMean :
223
262
if ( lookupResult . Frequencies is not null )
224
263
{
225
- List < LookupFrequencyResult > validFrequencies = lookupResult . Frequencies
226
- . Where ( static f => f . Freq is > 0 and < int . MaxValue ) . ToList ( ) ;
264
+ List < LookupFrequencyResult > validFrequencies = lookupResult . Frequencies . Where ( static f => f . Freq is > 0 and < int . MaxValue ) . ToList ( ) ;
227
265
return CalculateHarmonicMean ( validFrequencies ) . ToString ( CultureInfo . InvariantCulture ) ;
228
266
}
229
267
return null ;
268
+
230
269
case JLField . PitchAccents :
231
270
{
232
271
if ( DictUtils . SingleDictTypeDicts . TryGetValue ( DictType . PitchAccentYomichan , out Dict ? pitchDict ) && pitchDict . Active )
@@ -254,6 +293,7 @@ public static class MiningUtils
254
293
}
255
294
return null ;
256
295
}
296
+
257
297
case JLField . NumericPitchAccents :
258
298
{
259
299
if ( DictUtils . SingleDictTypeDicts . TryGetValue ( DictType . PitchAccentYomichan , out Dict ? pitchDict ) && pitchDict . Active )
@@ -279,6 +319,7 @@ public static class MiningUtils
279
319
}
280
320
return null ;
281
321
}
322
+
282
323
case JLField . PitchAccentForFirstReading :
283
324
{
284
325
if ( DictUtils . SingleDictTypeDicts . TryGetValue ( DictType . PitchAccentYomichan , out Dict ? pitchDict ) && pitchDict . Active )
@@ -296,6 +337,7 @@ public static class MiningUtils
296
337
}
297
338
return null ;
298
339
}
340
+
299
341
case JLField . NumericPitchAccentForFirstReading :
300
342
{
301
343
if ( DictUtils . SingleDictTypeDicts . TryGetValue ( DictType . PitchAccentYomichan , out Dict ? pitchDict ) && pitchDict . Active )
@@ -313,6 +355,13 @@ public static class MiningUtils
313
355
}
314
356
return null ;
315
357
}
358
+
359
+ case JLField . Nothing :
360
+ case JLField . Audio :
361
+ case JLField . Image :
362
+ case JLField . LocalTime :
363
+ default :
364
+ return null ;
316
365
}
317
366
}
318
367
@@ -687,7 +736,6 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex
687
736
688
737
public static async ValueTask < bool [ ] ? > CheckDuplicates ( LookupResult [ ] lookupResults , string currentText , int currentCharPosition )
689
738
{
690
-
691
739
Dictionary < MineType , AnkiConfig > ? ankiConfigDict = await AnkiConfig . ReadAnkiConfig ( ) . ConfigureAwait ( false ) ;
692
740
if ( ankiConfigDict is null )
693
741
{
@@ -727,11 +775,12 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex
727
775
728
776
Dictionary < string , JLField > userFields = ankiConfig . Fields ;
729
777
( string firstFieldName , JLField firstField ) = userFields . First ( ) ;
730
- string ? firstFieldValue = GetMiningParameter ( firstField , lookupResult , currentText , null , null , currentCharPosition ) ;
778
+ string ? firstFieldValue = GetMiningParameter ( firstField , lookupResult , currentText , currentCharPosition ) ;
731
779
if ( string . IsNullOrEmpty ( firstFieldValue ) )
732
780
{
733
781
continue ;
734
782
}
783
+
735
784
Dictionary < string , string > fields = new ( 1 , StringComparer . Ordinal )
736
785
{
737
786
{ firstFieldName , firstFieldValue }
0 commit comments