@@ -83,17 +83,17 @@ protected WordConverter ConvertTags()
8383 return this ;
8484 }
8585
86- protected WordConverter ConvertWording ( )
86+ protected WordConverter ConvertContent ( string title )
8787 {
88- var wording = new Content { Title = "語法" , Text = string . Empty } ;
88+ var content = new Content { Title = title , Text = string . Empty } ;
8989 var delete = new List < int > ( ) ;
9090 var flag = false ;
9191 foreach ( var ( line , index ) in DicWord . Trans . Split ( '\n ' ) . Select ( ( line , index ) => ( line , index ) ) )
9292 {
93- if ( line == "[語法 ]")
93+ if ( line == $ "[ { title } ]")
9494 flag = true ;
9595 else if ( flag )
96- wording . Text = ( wording . Text + "\n " + line ) . Trim ( ) ;
96+ content . Text = ( content . Text + "\n " + line ) . Trim ( ) ;
9797 else if ( string . IsNullOrEmpty ( line ) )
9898 flag = false ;
9999 if ( flag )
@@ -107,16 +107,16 @@ protected WordConverter ConvertWording()
107107 . TakeWhile ( ( line , index ) => ! delete . Contains ( index ) )
108108 . Select ( taple => taple . line )
109109 . Aggregate ( ( now , next ) => now + "\n " + next ) ;
110- Word . Contents . Add ( wording ) ;
111- wording = new Content { Title = "語法" , Text = string . Empty } ;
110+ Word . Contents . Add ( content ) ;
111+ content = new Content { Title = title , Text = string . Empty } ;
112112 delete . Clear ( ) ;
113113 flag = false ;
114114 foreach ( var ( line , index ) in DicWord . Exp . Split ( '\n ' ) . Select ( ( line , index ) => ( line , index ) ) )
115115 {
116- if ( line == "[語法 ]")
116+ if ( line == $ "[ { title } ]")
117117 flag = true ;
118118 else if ( flag )
119- wording . Text = ( wording . Text + "\n " + line ) . Trim ( ) ;
119+ content . Text = ( content . Text + "\n " + line ) . Trim ( ) ;
120120 else if ( string . IsNullOrEmpty ( line ) )
121121 flag = false ;
122122 if ( flag )
@@ -130,58 +130,7 @@ protected WordConverter ConvertWording()
130130 . TakeWhile ( ( line , index ) => ! delete . Contains ( index ) )
131131 . Select ( taple => taple . line )
132132 . Aggregate ( ( now , next ) => now + "\n " + next ) ;
133- Word . Contents . Add ( wording ) ;
134- return this ;
135- }
136-
137- protected WordConverter ConvertCulture ( )
138- {
139- var culture = new Content { Title = "文化" , Text = string . Empty } ;
140- var delete = new List < int > ( ) ;
141- var flag = false ;
142- foreach ( var ( line , index ) in DicWord . Trans . Split ( '\n ' ) . Select ( ( line , index ) => ( line , index ) ) )
143- {
144- if ( line == "[文化]" )
145- flag = true ;
146- else if ( flag )
147- culture . Text = ( culture . Text + "\n " + line ) . Trim ( ) ;
148- else if ( string . IsNullOrEmpty ( line ) )
149- flag = false ;
150- if ( flag )
151- delete . Add ( index ) ;
152- }
153- DicWord . Trans =
154- ( DicWord . Trans . Split ( '\n ' ) . Length == delete . Count ) ?
155- string . Empty :
156- DicWord . Trans . Split ( '\n ' )
157- . Select ( ( line , index ) => ( line , index ) )
158- . TakeWhile ( ( line , index ) => ! delete . Contains ( index ) )
159- . Select ( taple => taple . line )
160- . Aggregate ( ( now , next ) => now + "\n " + next ) ;
161- Word . Contents . Add ( culture ) ;
162- culture = new Content { Title = "文化" , Text = string . Empty } ;
163- delete . Clear ( ) ;
164- flag = false ;
165- foreach ( var ( line , index ) in DicWord . Exp . Split ( '\n ' ) . Select ( ( line , index ) => ( line , index ) ) )
166- {
167- if ( line == "[文化]" )
168- flag = true ;
169- else if ( flag )
170- culture . Text = ( culture . Text + "\n " + line ) . Trim ( ) ;
171- else if ( string . IsNullOrEmpty ( line ) )
172- flag = false ;
173- if ( flag )
174- delete . Add ( index ) ;
175- }
176- DicWord . Exp =
177- ( DicWord . Exp . Split ( '\n ' ) . Length == delete . Count ) ?
178- string . Empty :
179- DicWord . Exp . Split ( '\n ' )
180- . Select ( ( line , index ) => ( line , index ) )
181- . TakeWhile ( ( line , index ) => ! delete . Contains ( index ) )
182- . Select ( taple => taple . line )
183- . Aggregate ( ( now , next ) => now + "\n " + next ) ;
184- Word . Contents . Add ( culture ) ;
133+ Word . Contents . Add ( content ) ;
185134 return this ;
186135 }
187136
@@ -272,8 +221,8 @@ public WordConverter ConvertRelations()
272221
273222 public WordConverter Initialization ( )
274223 {
275- DicWord . Trans = DicWord . Trans . Replace ( "\r \n " , "\n " ) ;
276- DicWord . Exp = DicWord . Exp . Replace ( "\r \n " , "\n " ) ;
224+ DicWord . Trans = DicWord . Trans . Replace ( " " , " " ) . Replace ( " \r \n ", "\n " ) ;
225+ DicWord . Exp = DicWord . Exp . Replace ( " " , " " ) . Replace ( " \r \n ", "\n " ) ;
277226 return this ;
278227 }
279228
@@ -300,8 +249,9 @@ public Word Convert()
300249 . ConvertEntry ( )
301250 . ConvertTranslations ( )
302251 . ConvertTags ( )
303- . ConvertWording ( )
304- . ConvertCulture ( )
252+ . ConvertContent ( "語法" )
253+ . ConvertContent ( "文化" )
254+ . ConvertContent ( "文法" )
305255 . ConvertRemarks ( )
306256 . ConvertRelations ( )
307257 . FinalAdjustment ( )
@@ -313,60 +263,57 @@ public List<Word> AddSubheading(OneToManyJson dictionary)
313263 var list = new List < Word > ( ) ;
314264 foreach ( var content in Word . Contents )
315265 {
316- foreach ( var ( line , index ) in content . Text . Split ( '\n ' ) . Select ( ( line , index ) => ( line , index ) ) )
266+ var r = new Regex ( @"【(.*)】\s?([a-zA-Z\.\'\-\s]+)\s(.*)($|\n)" ) ;
267+ MatchCollection mc = r . Matches ( content . Text ) ;
268+ if ( mc . Count == 0 )
317269 {
318- var r = new Regex ( @"【(.*)】\s?([a-zA-Z\.\'\-\s]+)\s(.*)($|\n)" ) ;
319- MatchCollection mc = r . Matches ( line ) ;
320- if ( mc . Count == 0 )
321- {
322- break ;
323- }
324- else
270+ break ;
271+ }
272+ else
273+ {
274+ foreach ( Match m in mc )
325275 {
326- foreach ( Match m in mc )
276+ var subheadingWord = m . Groups [ 2 ] . Value . Trim ( ) ;
277+ if ( subheadingWord == Word . Entry . Form )
327278 {
328- var subheadingWord = m . Groups [ 2 ] . Value . Trim ( ) ;
329- if ( subheadingWord == Word . Entry . Form )
279+ Word . Translations . Add ( new Translation
330280 {
331- Word . Translations . Add ( new Translation
281+ Title = m . Groups [ 1 ] . Value . Replace ( "】【" , "・" ) ,
282+ Forms = Regex . Split ( m . Groups [ 3 ] . Value , @"、|\s" ) . ToList ( ) ,
283+ } ) ;
284+ }
285+ else
286+ {
287+ var subheading = dictionary . Words . FirstOrDefault ( word => word . Entry . Form == subheadingWord ) ??
288+ new Word
332289 {
333- Title = m . Groups [ 1 ] . Value . Replace ( "】【" , "・" ) ,
334- Forms = Regex . Split ( m . Groups [ 3 ] . Value , @"、|\s" ) . ToList ( ) ,
335- } ) ;
336- }
337- else
338- {
339- var subheading = dictionary . Words . FirstOrDefault ( word => word . Entry . Form == subheadingWord ) ??
340- new Word
290+ Entry = new Entry
291+ {
292+ Form = subheadingWord ,
293+ } ,
294+ Translations = new List < Translation > ( ) ,
295+ Tags = new List < string >
341296 {
342- Entry = new Entry
343- {
344- Form = subheadingWord ,
345- } ,
346- Translations = new List < Translation > ( ) ,
347- Tags = new List < string >
348- {
349297 "小見出し" ,
350- } ,
351- Relations = new List < Relation > ( ) ,
352- } ;
353- subheading . Translations . Add ( new Translation
354- {
355- Title = m . Groups [ 1 ] . Value . Replace ( "】【" , "・" ) ,
356- Forms = Regex . Split ( m . Groups [ 3 ] . Value , @"、|\s" ) . ToList ( ) ,
357- } ) ;
358- subheading . Relations . Add ( new Relation
359- {
360- Title = "見出し語" ,
361- Entry = Word . Entry ,
362- } ) ;
363- Word . Relations . Add ( new Relation
364- {
365- Title = "小見出し" ,
366- Entry = subheading . Entry ,
367- } ) ;
368- list . Add ( subheading ) ;
369- }
298+ } ,
299+ Relations = new List < Relation > ( ) ,
300+ } ;
301+ subheading . Translations . Add ( new Translation
302+ {
303+ Title = m . Groups [ 1 ] . Value . Replace ( "】【" , "・" ) ,
304+ Forms = Regex . Split ( m . Groups [ 3 ] . Value , @"、|\s" ) . ToList ( ) ,
305+ } ) ;
306+ subheading . Relations . Add ( new Relation
307+ {
308+ Title = "見出し語" ,
309+ Entry = Word . Entry ,
310+ } ) ;
311+ Word . Relations . Add ( new Relation
312+ {
313+ Title = "小見出し" ,
314+ Entry = subheading . Entry ,
315+ } ) ;
316+ list . Add ( subheading ) ;
370317 }
371318 }
372319 }
0 commit comments