(def simple-grammar
{:hub [:node-unique-accept :node-unique-check :node-unique-persist]
:node-unique-accept [:ParseUrl :ParseParams :AcceptBool]
:node-unique-check [:FormatRead :FormatCheckBool]
:node-unique-persist [:SaveOrUpdate :PersistBool]
:ParseUrl #{"http, www, mattcutts.com, /blog/seo-glossary-url-definitions/" "http, jbowles, github.com/" "http, www, cs.dartmouth.edu, /~mckeeman/cs48/mxcom/doc, FiniteAutomata.pdf" "https, www, ruby-toolbox.com, categories/state_machines.html"}
:ParseParams #{"program address city state zip" "fname lname school program address city state zip" "fname lname school state zip" "fname lname city state zip"}
:AcceptBool #{"0" "1"} ;;[] (one-of [0 1])
:FormatRead #{"UTF8" "other stuff"}
//package state_gacket // soft 'g', like state_dʒacket | |
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
/* | |
type Metadata struct { | |
EntryLength int |
/*jslint node:true*/ | |
"use strict"; | |
function normal_random(mean, variance) { | |
if (mean === undefined) { | |
mean = 0.0; | |
} | |
if (variance === undefined) { | |
variance = 1.0; | |
} |
/*jshint node:true*/ | |
"use strict"; | |
// SEND REQUEST TO CLASSIFY TEXT | |
var http = require('http'), | |
fs = require('fs'), | |
natural = require('natural'), | |
classifier = new natural.BayesClassifier(); | |
// flatten an array |
require 'treat' | |
include Treat::Core::DSL | |
doc1 = document('http://en.wikipedia.org/wiki/List_of_best-selling_fiction_authors') | |
doc2 = document('http://en.wikipedia.org/wiki/List_of_best-selling_books') | |
[d1,d2].apply(:chunk, :segment, :tokenize) | |
#Check it! | |
doc1.sentences | |
doc1.sentences.count |
The :hub
is the transaction and/or application (more on this later). Each :node
is wrapper around a Hero Formula
responsible for passing the non-boolean values to the :hub
, but it also returns a boolean. Each camel-cased line inside the :node
parentheses is a Hero :formula
and the values in quotes are the return values of a Formula's :step
. Formula.step
is the only thing responsible for changing state.
The following is in Clojure but it should be interpretable from a Ruby perspective; it's the relations that matter here not the syntax.
[:hub ;; begin transaction
( ;; begin set of Nodes
:node-unique-accept
```clojure | |
;; Clojure Step | |
(declare step check-valid base-complete check-user) | |
(defn one-of [coll] | |
(if (seq coll) | |
[(rand-nth coll)])) | |
(defn step[] (concat (check-valid) (base-complete) (check-user))) | |
(defn check-valid[] (one-of [0 1])) |
Transactional system that defines a set of primitive and composable concepts. It is inspired by Finite State Grammars.
Finite State Transactional Grammar. I don't know if I made up this term, so I won't claim to have invented this, but I'm running with it. What is sketched here is a transactional system inspired by finite state machines, finite state grammars, rule engines, map-reduce algorithms, functional programming (namely Clojure and LISP), business intelligence, and the rubygem Hero.
require File.join(File.dirname(__FILE__), 'lib','new_class.rb') | |
has_many :hadoop_logs | |
def self.twitter_creds | |
tconfig_file = Rails.root.join 'config', 'twitter_oauth.yml' | |
NimbleTwitter.twitter_config(NimbleTwitter.dev_twitter("#{tconfig_file}")) | |
end | |
def self.json_encoder | |
Yajl::Encoder.new |
class NewClass | |
def self.tell_me_something | |
"whatup!" | |
end | |
def self.randomize_select | |
list = [ | |
"one", | |
"two", | |
"three" | |
] |