Index: graphspell-js/dawg.js ================================================================== --- graphspell-js/dawg.js +++ graphspell-js/dawg.js @@ -293,10 +293,42 @@ for (let s of this.lArcVal) { console.log(i + ": " + s); i++; } } + + * select (sPattern="") { + // generator: returns all entries which morphology fits + let zPattern = null; + if (sPattern !== "") { + try { + zPattern = new RegExp(sPattern); + } + catch (e) { + console.log("Error in regex pattern"); + console.log(e.message); + } + } + yield* this._select1(zPattern, this.oRoot, ""); + } + + * _select1 (zPattern, oNode, sWord) { + // recursive generator + for (let [nVal, oNextNode] of oNode.arcs.entries()) { + if (nVal < this.nChar) { + // simple character + yield* this._select1(zPattern, oNextNode, sWord + this.lArcVal[nVal]); + } else { + let sEntry = sWord + "\t" + this.funcStemming(sWord, this.lArcVal[nVal]); + for (let [nMorphVal, _] of oNextNode.arcs.entries()) { + if (!zPattern || zPattern.test(this.lArcVal[nMorphVal])) { + yield sEntry + "\t" + this.lArcVal[nMorphVal]; + } + } + } + } + } // BINARY CONVERSION createBinary (nMethod) { console.log("Write DAWG as an indexable binary dictionary [method: "+nMethod+"]"); if (nMethod == 1) {