Code Monkey home page Code Monkey logo

djinn's Introduction

Djinn: Finite State Automata in Javascript

Build Status

Inspirations:

Notes from various emails:

FSMs are effectively directed graphs (with a global source), so I extracted everything possible into a directed graph class.

https://github.com/automatthew/djinn/blob/master/src/digraph.coffee

The FSA class extends Digraph. It has accept, match, and matches methods for testing input strings or arrays. It's still suffering from cruft, feature creep, and indecision. The test script shows you pretty much all the primitives it offers.

https://github.com/automatthew/djinn/blob/master/src/fsa.coffee https://github.com/automatthew/djinn/blob/master/test/fsaTest.js


I had graphs on the brain this weekend, so I refurbished Djinn.

There's now a base Digraph class that requires you to implement your own Vertex and Arc (a.k.a. node and edge) classes. So far I supply a NaiveDigraph subclass that's based on mindless OO patterns and a SequenceAcceptor (currently using NaiveDigraph, but could use any other Digraph class). The SequenceAcceptor is a limited FSM for matching strings or arrays.

Aside from refurbishings, the really cool thing that happened was the implementation of digraph-intersection. In other words, Djinn can now take two FSMs and generate an intersection of the grammars they express. String matching is a special case of FSA intersection where the string is assumed to be a trivial FSA with each state having one and only one transition to the next state.

Near Future Coolness: the intersection algorithm for finite state acceptors is apparently a special case of the composition algorithm for finite state transducers. That is, where an Acceptor can only return matches from inputs, a Transducer can return transformations. FSTransducer composition is exactly analogous to function or set composition.

Limitations: I stepped waaaay back from my idea of allowing each FSA transition to do arbitrary matching. Doing anything other than exact matching drops you straight into Cartesian Product territory. That territory may well be worth exploring for situations with known bounds on the number of arcs per vertex (aka transitions leaving each state), but I'm not assuming that constraint for now. It should be near-trivial to add later, by augmenting the way the Arc classes test equivalence.

Interoperability: AT&T's fsm and OpenFST emit and consume simple text formats. Djinn easily could be modified to emit/consume these formats. This means that a production environment could take FSMs created in the browser by Djinn and perform complex, CPU intensive operations with a highly-optimized OpenFST application. Or a browser could use Djinn to perform less intensive operations on an FSM constructed and maintained by OpenFST.

TODOS:

  • subclass of Digraph that uses an adjacency list for vertex/arc operations
  • dump/load functions for OpenFST text format
  • transducer subclass (both input and output values for each arc)
  • regex compiler (mostly for demo)
  • subclass that maintains a codebook of arc values, using integer labels for the actual arc storage.

djinn's People

Contributors

automatthew avatar

Stargazers

steve wei avatar  avatar Dan Minshew avatar west avatar  avatar

Watchers

 avatar James Cloos avatar

djinn's Issues

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.