Grammalecte  Check-in [fe54076259]

Overview
Comment:[graphspell][js] ibdawg: add select() function
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | graphspell
Files: files | file ages | folders
SHA3-256: fe540762594466d7b774dfea60e41b4a90cc2f05b4d644e50bd702f1beaa5553
User & Date: olr on 2018-02-07 15:19:52
Other Links: manifest | tags
Context
2018-02-07
16:14
[graphspell][js] dawg: fix bugs in select() check-in: a227ad5a87 user: olr tags: graphspell, trunk
15:19
[graphspell][js] ibdawg: add select() function check-in: fe54076259 user: olr tags: graphspell, trunk
15:19
[graphspell][py] ibdawg: select(), don’t compile pattern if empty check-in: 418b212030 user: olr tags: graphspell, trunk
Changes

Modified graphspell-js/ibdawg.js from [46212759e7] to [6074b8efa8].

   379    379           return aTails;
   380    380       }
   381    381   
   382    382       // morph (sWord) {
   383    383       //     is defined in constructor
   384    384       // }
   385    385       
          386  +    * select (sPattern="") {
          387  +        // generator: returns all entries which morphology fits <sPattern>
          388  +        let zPattern = null;
          389  +        if (sPattern !== "") {
          390  +            try {
          391  +                zPattern = new RegExp(sPattern);
          392  +            }
          393  +            catch (e) {
          394  +                console.log("Error in regex pattern");
          395  +                console.log(e.message);
          396  +            }
          397  +        }
          398  +        yield* this._select1(zPattern, 0, "");
          399  +    }
          400  +
   386    401       // VERSION 1
          402  +
          403  +    _select1 (zPattern, iAddr, sWord) {
          404  +        // recursive generator
          405  +        for (let [nVal, jAddr] of self._getArcs1(iAddr)) {
          406  +            if (nVal < this.nChar) {
          407  +                // simple character
          408  +                yield* self._select1(zPattern, jAddr, sWord + self.lArcVal[nVal])
          409  +            } else {
          410  +                let sEntry = sWord + "\t" + this.funcStemming(sWord, this.lArcVal[nVal]);
          411  +                for (let [nMorphVal, _] of this._getArcs1(jAddr)) {
          412  +                    if (!zPattern || zPattern.search(this.lArcVal[nMorphVal])) {
          413  +                        yield sEntry + "\t" + this.lArcVal[nMorphVal];
          414  +                    }
          415  +                }
          416  +            }
          417  +        }
          418  +    }            
          419  +
   387    420       _morph1 (sWord) {
   388    421           // returns morphologies of sWord
   389    422           let iAddr = 0;
   390    423           for (let c of sWord) {
   391    424               if (!this.dChar.has(c)) {
   392    425                   return [];
   393    426               }