jmdict-streaming-parser
Version:
Streaming parser for JMdict and related files.
36 lines (35 loc) • 1.13 kB
JavaScript
var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {get: all[name], enumerable: true});
};
__markAsModule(exports);
__export(exports, {
parseGroupedEntities: () => parseGroupedEntities
});
function parseGroupedEntities(initialChunk) {
const lines = initialChunk.split("\n");
let groupKey = "";
const groupedEntities = new Map();
for (const line of lines) {
if (line === "<JMdict>") {
break;
}
const groupHeaderMatch = /^<!--\s*?<(.*)>.*?entities\s*?-->$/.exec(line);
if (groupHeaderMatch != null) {
;
[, groupKey] = groupHeaderMatch;
groupedEntities.set(groupKey, []);
continue;
}
const entityDefinitionMatch = /^