UNPKG

@freeword/meta

Version:

Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.

59 lines 2.09 kB
import _ /**/ from 'lodash'; import * as UF from "../lib/UF.js"; import { starlines } from "../lib/Filer.js"; export class LemmaDef { get words() { return _.map(this.wordforms, 'word'); } get stemcores() { return _.map(this.wordforms, 'stemcore'); } get suffixes() { return _.map(this.wordforms, 'suffix'); } get poses() { return _.map(this.wordforms, 'pos'); } get stemkinds() { return _.map(this.wordforms, 'stemkind'); } get stemsplits() { return _.map(this.wordforms, 'stemsplit'); } static make(rawline) { return new this(rawline); } parseRawLine() { return this; } prettyA({ indent = '' } = {}) { return indent + _.map(this.wordforms, 'pretty').join(',\n' + indent) + ','; } get pretty() { return this.prettyA({ indent: ' ' }); } static async *parseDictStar(rawlines) { let oopsieCount = 0; const oopsies = []; for await (const rawline of rawlines) { const def = this.make(rawline); def.parseRawLine(); if (def.ok) { yield def; } else { oopsies.push(def); oopsieCount++; } if (oopsieCount >= 30) { console.error('halting at 30 oopsies: things like', _.first(oopsies)); break; } } return { oopsies, oopsieCount }; } static async slurpLexicon(filename) { const { vals: defs, ret } = await UF.slurpWithResult(this.parseDictStar(starlines(filename))); return { ...ret, defs }; } static parseDict(rawlines) { let oopsieCount = 0; const oopsies = []; const defs = []; for (const rawline of rawlines) { const def = this.make(rawline); def.parseRawLine(); if (def.ok) { defs.push(def); } else { oopsies.push(def); oopsieCount++; } } return { oopsies, defs, oopsieCount }; } } //# sourceMappingURL=LemmaDef.js.map