Code Monkey home page Code Monkey logo

lookups's Introduction

This repository is DEPRECATED

This library has been ported to TypeScript here:

https://github.com/mckoss/dawg

The new library can also be installed via:

npm install dawg-lookup

All future Issues and development should be directed there.

Exploration of different dictionary lookup techniques for client-side JavaScript.

Inspired by several blog posts by John Resig:

You can try out hosted version of this software at:

#Packed Trie Encoding Format

A Packed Trie is an encoding a textual Trie using 7-bit ascii. None of the character need be quoted themselves when placed inside a JavaScript string, so dictionaries can be easily including in JavaScript source files or read via ajax.

Example

Suppose our dictionary contains the words:

cat cats dog dogs bat bats rat rats

The corresponding Packed Trie string is:

b0c0dog1r0
at0
!s

';' characters have been replaced with newlines for clarity.

This Trie (actually, a DAWG) has 3 nodes. If we follow the path of "cats" through the Trie we get the squence:

node 0. match 'c': continue at node + 1
node 1. match 'at': continue at node + 1
node 2. match s: Found!

Or 'dog':

node 0. match 'dog': continue at node + 2
node 2. nothing left to match - '!' indicates Found!

Nodes

A file consists of a sequence of nodes, which are nodes in a Trie representing a dictionary. Nodes are separated by ';' characters (you can split(';') to get an array of node strings).

A node string contains an optional '!' first character, which indicates that this node is a terminal (matching) node in the Trie if there are zero characters left in the pattern.

The rest of the node is a sequence of character strings. Each string is either associated with a node reference, or is a terminal string completing a match. Node references are base 36.1 encoded relative node numbers ('0' == +1, '1' == +2, ...). A comma follows each terminal string to separate it from the next string in the sequence.

A Node reference can also be a symbol - an absolute node reference, instead of a relative one.

Symbols

Large dictionaries can be further compressed by recognizing that node references to some common suffixes can be quite large (i.e., spanning 1,000's of nodes). While encoded as only 3 or 4 characters, we can reduce the file size by replacing selected row references with symbolic references.

To do so, we prepend the file with a collection of symbol definitions:

0:B9M
1:B9O
2:B6R
3:B6B
...
aA5Kb971c82Ud7FFe6Y5f6E5g5Y7h5IDi58Tj53Xk4XOl4J0m3WMn3N0o38Sp2E3q2BZr1QIs0JFtXHuLPvE2w4Kx41y24zS

When used in a Node, a symbol reference indicates the absolute row number as defined in it's symbol definition line (above).

For each symbol we define (up to 36), we shift the meaning of all relative references down by 1. E.g.,if we define 1 symbol ('0'), then the node reference 1 now means "+1 row", whereas it normally means "+2 rows".

Base 36.1 numbers

Unlike base 36 numbers (digits 0-9, A-Z), base "36.1" distinguished between leading zeros. The counting numbers are hence:

0, 1, 2, 3, ..., 9, A, B, C, ..., Y, Z, 00, 01, 02, ... AA, ...

so we eke out a bit more space by not ignoring leading zeros.

lookups'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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lookups's Issues

One minimal usage example

This library appears to be exactly what I need, but I'm having trouble figuring out how to use it and which are the minimal dependancies required to build a trie and then run lookups on it. When I try to load /scripts/ptrie-complete.js I get:

ReferenceError: namespace is not defined
    at Object.<anonymous> (/Users/ESL/Desktop/hola/trie-test.js:1:442)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

Weirdly, I get this same error even if I include /scripts/namespace.js before it. It's not obvious to me what namespace.js is...

I would love just a couple lines of code demonstrating how these fils are intended to be used. The index.html file is almost this, but it's currently broken at the moment because it tries to load resources that do not exist anymore.

split repexp to strict and console.log

Hi,
This is a really cool library.

But the split regexp in trie.js

words = words.split(/[^a-zA-Z]+/);

IMO is a little bit to strict for eg: german language, where we have öäü ..
It would be nice to have the possibility to overwrite your defaults with a config object, that contains a regexp eg: /[^a-zA-ZöäüÖÄÜ]+/

And there is a console.log which you forgot to comment.

kind regards

packing missing a node

hi mike, thanks for making this. I've found a tough bug. that can be reproduced in the online tool:

brian bruce bryan bryant bryce bryon buddy dejan burton byron caleb calvin carlo carlton carroll cedric cesar cha charle charli chester chri christian christopher chuck clarence clark claude clay clayton damian damien damon daniel danny darin dariu darwin dav davi david dean delbert deni demetriu denni derek derrick desmond deven devin dewayne dewey dexter

then lookup dejan, which should be there.

i tried really hard to debug this. the regular trie finds dejan, but this node gets lost in the pack() method.
cheers

No Liscence

I'd love to use this library in a project, but there is no license, so I am unsure about what is permissive and what is not.

Can you please update this repo to have a license?

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.