jadb/bin/radkfile/parser.dart

33 lines
786 B
Dart

import 'dart:io';
import 'package:sqflite_common/sqlite_api.dart';
Future<void> addDataFromRADKFILE(Database db) async {
final String content = File('data/radkfile_utf8').readAsStringSync();
final Iterable<String> blocks =
content.replaceAll(RegExp(r'^#.*$'), '').split(r'$').skip(2);
print('[RADKFILE] Writing to database...');
final b = db.batch();
for (final block in blocks) {
final String radical = block[1];
final List<String> kanjiList = block
.replaceFirst(RegExp(r'.*\n'), '')
.split('')
..removeWhere((e) => e == '' || e == '\n');
for (final kanji in kanjiList.toSet()) {
b.insert(
'RADKFILE',
{
'radical': radical,
'kanji': kanji,
},
);
}
}
b.commit();
}