Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active September 29, 2019 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/543881b09311d98127e99f117339e025 to your computer and use it in GitHub Desktop.
Save matthewstokeley/543881b09311d98127e99f117339e025 to your computer and use it in GitHub Desktop.
a very quick sketch of a spark-inspired transformation layer that sites on top of a mongo-esque nlp api - meant to listen to node streams
/*---------------------------------
*
* Real-time data analysis library
*
*/
// transformation layer for node streams
// - listen to node stream
// - create a transformation object on event listener
// - emit event
type TransformationObject {
count: Number
}
type MatchEvent {
key: String,
name: String,
fn: Function,
writeable: Boolean,
enumerable: Boolean
}
type StreamEvent {
}
// like a happening
type FluxishEvent {
}
// flux / reduc state-based event model
const EVENTS = {
'EVENT_NAME': ''
}
const eventsApi = function() {}
const STATE_API = {
'STATE_KEY': {
"OBJ": "CURRENT_STATE"
}
}
// @todo
function retrieveMatchEvent() {
let cache = new WeakMap();
const keyResolver = ( function( key ) {
return function( salt ) {
cache.get( key )
}
} ) ( )
}
const objWriter = function( obj ) {
return Object.defineProperty( obj, {
name,
key,
writeable,
enumerable
} )
}
// analysis methods
const mle = ( function( ) {
} ) ( )
const wc = ( function( ) {
} ) ( )
const match = ( function( obj: TransformationObject ): Object {
let analysis = {}
const mle = function() {}
return {
}
} ) ( );
const transformationObjFactory = function() {
return {
}
}
// proof of concept
const eventPayloadPartitioner = function() {
const qs = function() {
}
const partition = function( high, low ) {
}
}
const eventService = ( function(): Object {
const events = []
const add = ( function(): Function {
return function( name, fn ) {
events.push( {
name,
fn
} )
}
} )()
const emit = ( function( name ): Function {
let emittable
for ( let i = 0; i < events.length; i++ ) {
if ( events[ i ].name === name )
emittable = events[ i ]
}
return function() {
return emittable.fn.call( this, ...args )
}
} )()
return {
add,
emit
}
} )()
// run events as child processes
const eventsSpawningWrapper = ( function() {
return eventService
} )()
const corpusServiceFactory = ( function( ) {
const definition = ( fn ) => {
// decorator fn
return fn
}
const generateBson = ( fn ) => {
}
return ( function() {
const corpus
const build = function( string, delim = '<p>' ) {
corpus = string.split( delim )
}
const buildTable = function() {
let table = {}
let bson - generateBson( i )
for ( let i = 0; i < corpus[ i ]; i++ ) {
table[ bson ] = {
'_id': bson,
'value': corpus[ i ],
'index': i
}
}
return table
}
const get = function() {
return corpus
}
const getByCount = function() {}
const findByIndex = function( index ) {
return corpus[ index ]
}
const findByString = function( string ) {
for ( let i = 0; i < corpus.length; i++ ) {
if ( corpus[ i ] === string )
return {
value: corpus[ i ],
index: i,
array: corpus
}
}
}
const findByBson = function( _id ) {
return table[ _id ]
}
const buildParagraphMetadata = function() {}
const save = function() {}
return {
build,
get,
getCoumt,
findByIndex,
findByString
}
} )( )
} )( )
const corpusService = corpusServiceFactory()
// logic
corpusService = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment