(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"}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// PART FOUR: in which we get the min value for delete, insert, substitute and set value in Vector, return significant Vector value. | |
func MinInt(a ...int) int { | |
min := int(^uint(0) >> 1) | |
for _, i := range a { | |
if i < min { | |
min = i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// PART THREE: if characters are not the same, we step through a comparison against each character to | |
//// determine DELETION, INSERTION, SUBSTITUTION and get the minimum of the three values. | |
func MinInt(a ...int) int { | |
min := int(^uint(0) >> 1) | |
for _, i := range a { | |
if i < min { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// PART TWO: step through each string character and vector/cell of dynamic programming table to determine difference. | |
//// This handles the case where both characters are an exact match, and only the "no-change" condition is used. | |
func LevenshteinTwo(s1, s2 string) { | |
m := len(s1) | |
n := len(s2) | |
width := n - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// http://en.wikipedia.org/wiki/Levenshtein_distance | |
// FIRST PART: define vector/cell for the dynamic programming table based on string lengths | |
func PartOneLevenshtein(s1, s2 string) { | |
m := len(s1) | |
n := len(s2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package state_gacket // soft 'g', like state_dʒacket | |
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
/* | |
type Metadata struct { | |
EntryLength int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint node:true*/ | |
"use strict"; | |
function normal_random(mean, variance) { | |
if (mean === undefined) { | |
mean = 0.0; | |
} | |
if (variance === undefined) { | |
variance = 1.0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```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])) |