Git Product home page Git Product logo

dawg's People

Contributors

mckoss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dawg's Issues

Words with underscores are not found

Words with underscores are reported as not present in a word collection with isWord

const trie = new Trie(['yes', 'yes_no']);
trie.isWord('yes'); // => true (which is correct)
trie.isWord('no'); // => false (which is correct)
trie.isWord('yes_no'); // => false (which is incorrect)

I guess this is because Node has special properties like _c that use _ and hence any prop starting with _ is excluded in node.props() https://github.com/mckoss/dawg/blob/master/src/node.ts#L88.

I guess a safer option would be to store props in their own dictionary like node.props. Otherwise the only option I can think of is to replace _ prior to creating the Trie and before isWord but that seems less ideal.

PTrie constructed from packed string does not yield same isWord result as original Trie

I constructed a Trie from a Scrabble dictionary which is then packed and used to construct a PTrie.
The PTrie itself appears to be populated, though methods such as isWord and completions are not returning expected results.

Example:

import { createReadStream, createWriteStream } from 'fs';
import { resolve } from 'path';
import { createInterface, Interface } from 'readline';

var Trie = require('dawg-lookup').Trie;
var PTrie = require('dawg-lookup/lib/ptrie').PTrie;

var trie = new Trie();
var scrabbleDictionary = createInterface({
   input: createReadStream(resolve(__dirname, '../lib', 'Collins Scrabble Words (2019).txt'), 'utf8')
});
var output = createWriteStream(resolve(__dirname, '../lib', 'dictionary.txt'));

scrabbleDictionary.on('line', (line: string) => {
        trie.insert(line);
    }).on('close', () => {
        console.log(trie.isWord('FUN'));

        let packed = trie.pack();
        let ptrie = new PTrie(packed);

        console.log(ptrie.isWord('FUN'));
        console.log(ptrie.completions('F'));

        output.write(packed);
        output.close();
    });

Result:

> true
> false
> []

Any ideas why this is occurring?

Node string fragment conflicts with internal fields

The way Node stores string fragments alongside internal fields is problematic:

new Trie(['child']).optimize()
Uncaught TypeError: this.child is not a function
    at Node.isTerminalString (node.js:51)
    at Node.isTerminal (node.js:56)
    at Trie.collapseChains (trie.js:207)
    at Trie.optimize (trie.js:126)
    at <anonymous>:1:26

"child" is a property holding a Node reference, not the child method from the prototype.

This could possibly be worked around by usage of Symbols to insure internal fields/method never conflict with string fragment properties.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.