Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.98 KB | None | 0 0
  1. //=============================DATA TYPE LOGIC================================
  2. // schema logic
  3.  
  4. //-- generate events in a format of a schema but also data so it can be used as both
  5. //-- we assume we have a starting point of some "vertex" schema definition
  6.  
  7. {
  8. "LH": {
  9. "key": "nonNegativeInteger",
  10. "runtime": {
  11. "ref": "xxx",
  12. "params": {}
  13. }
  14. }},
  15.  
  16. {
  17. "$schema": "http://json-schema.org/draft-04/schema#",
  18. "definitions": {},
  19. "id": "http://example.com/example.json",
  20. "properties": {
  21. "LH": {
  22. "id": "/properties/LH",
  23. "properties": {
  24. "key": {
  25. "id": "/properties/LH/properties/key",
  26. "type": "string"
  27. },
  28. "runtime": {
  29. "id": "/properties/LH/properties/runtime",
  30. "properties": {
  31. "params": {
  32. "id": "/properties/LH/properties/runtime/properties/params",
  33. "properties": {},
  34. "type": "object"
  35. },
  36. "ref": {
  37. "id": "/properties/LH/properties/runtime/properties/ref",
  38. "type": "string"
  39. }
  40. },
  41. "type": "object"
  42. }
  43. },
  44. "type": "object"
  45. }
  46. },
  47. "type": "object"
  48. }
  49.  
  50. {
  51. "type": "object",
  52. "children": [
  53. {
  54. "type": "property",
  55. "key": {
  56. "type": "identifier",
  57. "value": "LH"
  58. },
  59. "value": {
  60. "type": "object",
  61. "children": [
  62. {
  63. "type": "property",
  64. "key": {
  65. "type": "identifier",
  66. "value": "key"
  67. },
  68. "value": {
  69. "type": "literal",
  70. "value": "nonNegativeInteger",
  71. "rawValue": "\"nonNegativeInteger\""
  72. }
  73. },
  74. {
  75. "type": "property",
  76. "key": {
  77. "type": "identifier",
  78. "value": "runtime"
  79. },
  80. "value": {
  81. "type": "object",
  82. "children": [
  83. {
  84. "type": "property",
  85. "key": {
  86. "type": "identifier",
  87. "value": "ref"
  88. },
  89. "value": {
  90. "type": "literal",
  91. "value": "xxx",
  92. "rawValue": "\"xxx\""
  93. }
  94. },
  95. {
  96. "type": "property",
  97. "key": {
  98. "type": "identifier",
  99. "value": "params"
  100. },
  101. "value": {
  102. "type": "object",
  103. "children": []
  104. }
  105. }
  106. ]
  107. }
  108. }
  109. ]
  110. }
  111. }
  112. ]
  113. }
  114.  
  115. JSON Origina
  116.  
  117. // generate schema for our JSON
  118. var schemagraph = [[1, 'ref', 'literal'], [2, 'key', 'literal'], [3, 'LH', 'object']]
  119.  
  120. subject, predicate, object
  121.  
  122. assignId to initial stream: [[1,1,1, dateTime],[],[]] -- > each new schema item will increment the concept
  123.  
  124. Concept Logical Levels: (as we move the subject/predicate/object - we just shift the numbers)
  125. -- no assert -- [[0,1,1, dateTime],[],[], TwitterLikeInt]
  126. -- concept 1 -- [[1,1,1, dateTime],[],[], TwitterLikeInt]
  127. -- concept 2 -- [[2,1,1, dateTime],[],[], TwitterLikeInt]... [[4,1,1, dateTime],[],[], TwitterLikeInt] ... [[1,1,1, dateTime],[],[], TwitterLikeInt]
  128. -- concept 3 -- [[3,1,1, dateTime],[],[], TwitterLikeInt]
  129. -- concept 4 -- [[4,1,1, dateTime],[],[], TwitterLikeInt]
  130.  
  131. -- concept 2.0 -- [[2,1,1],[[2,1,1, dateTime],[],[], TwitterLikeInt]]
  132. -- concept 2.1 -- [[1,2,1],[[2,1,1, dateTime],[],[], TwitterLikeInt]]
  133.  
  134. Context Traversal:
  135. -- concept 2.1 -- [[[1,2,1],[1,2,1]],[[2,1,1, dateTime],[],[], TwitterLikeInt]]
  136.  
  137.  
  138. -- Declare an item
  139. -- Assert an item
  140.  
  141.  
  142.  
  143.  
  144. [axiom, [class]]
  145.  
  146. axiom - 2,1,1 -- itemId, subclass level, ontologyId -- interpretation
  147. base class - 2,1,1 -- individual cardinality, concept, ontologyId -- here is where the individual is grounded
  148.  
  149. Individuals - before assertion:
  150. -- level 0 -- [[0,1,1],[[0,1,1, dateTime],[],[], TwitterLikeInt]]
  151. -- level 1 -- [[0,1,1],[[0,1,1, dateTime],[],[], TwitterLikeInt]]
  152. -- level 2 -- [[0,1,1],[[0,1,1, dateTime],[],[], TwitterLikeInt]]
  153. -- level 3 -- [[0,1,1],[[0,1,1, dateTime],[],[], TwitterLikeInt]]
  154.  
  155.  
  156. Individuals - after assertion (to the same stream): (we need to assert as a base class, subclasses get a new item created)
  157. -- level 0 -- [[1,1,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]] [ predicate section ] [ object section ]
  158. -- level 1 -- [[1,1,1],[[2,1,1, dateTime],[],[], TwitterLikeInt]]
  159. -- level 2 -- [[1,2,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]]
  160. -- level 3 -- [[1,3,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]]
  161.  
  162. Individuals - subclass assertion:
  163. -- level 0 -- [[1,1,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]] [ predicate section ] [ object section ]
  164. -- level 1 -- [[1,1,1],[[1,2,1, dateTime],[],[], TwitterLikeInt]]
  165. -- level 2 -- [[1,2,1],[[1,3,1, dateTime],[],[], TwitterLikeInt]]
  166. -- level 3 -- [[1,3,1],[[1,4,1, dateTime],[],[], TwitterLikeInt]]
  167.  
  168. Individuals - after assertion - DIFFERENT stream:
  169. -- level 0 -- [[1,1,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]] [ predicate section ] [ object section ]
  170. -- level 1 -- [[1,1,1],[[2,1,1, dateTime],[],[], TwitterLikeInt]]
  171. -- level 2 -- [[1,2,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]]
  172. -- level 3 -- [[1,3,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]]
  173.  
  174. schema subject shift UP logical hierarchy: [1,5,3] [5,3,9] [3,9,16] ++ NewPredicate ++ old object (inferencing new level) (+ add edge SameAs)
  175. schema subject shift DOWN logical hierarchy: [1,5,3] [10,1,5] [2,10,1]
  176.  
  177. schema predicate shift DOWN logical hierarchy: [1,5,3] [1,5,2] [1,5,1] ++ NewPredicate ++ new objectId (inferencing new connection) (+ add edge SameAs)
  178. -- in some cases when under conditions we may need to not add SameAs or add "not the same as"
  179.  
  180. - how do we draw subclass - we can safely say that every stream has its own schema
  181. - for other types of
  182. --
  183.  
  184. [[1,3,1],[[1,1,1, dateTime],[],[], TwitterLikeInt]] and __ [1,3,1]__[1,5,2]__[8,3,4] ____ and [[8,3,4],[[1,1,1, dateTime],[],[], TwitterLikeInt]]
  185.  
  186. schema:
  187. subject: objectFullPath
  188. predicate: 'has' (type: property)
  189. object: propertyFullPath (value.type:'literal )
  190.  
  191.  
  192. // Add ast parsing - so we can easily parse JSON
  193. // === This still executes as Realine non-core code - so we can prep the data for actual upload
  194. // initialize parent object stream
  195. // declare objects/properties/functions/schema
  196. // assert objects/properties/functions/schema
  197. function JsonObjectDeclaration(parent, element) ( if element.type = "object" then .. run('DeclareState', element.key), ) //these we put in the top object stream
  198. function JsonObjectAssertion(parent, element) ('here we push individual to specific stream or leave asserted in the parent stream')
  199. function JsonObjectSchemaAssertion(element) ( 'need to finalize the format')
  200.  
  201. // Here we start declaration and assertion process in Realine
  202. // -- initilize a specific stream (we dump data there in a proper format, but not asserted yet)
  203. // -- separately upload schema into a different stream
  204. // -- compose schema and attach mappings to Realine existing schemas - if such exist (on low level, we should have variable type etc, if not, we just create it)
  205. // -- push the schema to be Realine Ontology schema (as classes, object properties, data properties + mappings to runtime workers etc.)
  206. // -- here we need to capture relationship such as subclass vs object property etc. (we should be able to see the resulting schema on UI)
  207. // -- for the above point, we should probably create a JSON decomposition grammar - so we do not have to do the mappings every time
  208. // -- run assertion process on the properties - we push the value through the pipeline in an iterative cycle (basically - like a business rule - equivalent class)
  209. // -- asserted classes, data props, etc. are pushed to respective streams (copied multiple times if necessary) - for every Class we create a stream
  210. // -- we have a UI worker that gets the messages and shows them on a UI Json tree (now we have 3 tree on the page - original, ontology schema, assertion results)
  211. // -- we can compare the original vs. result and if we have any ambiguities regarding type (multiple assertions etc - we need to mark what is same/different individual, add disjoints etc. )
  212. // -- we rerun the assertion as many times as needed
  213. // -- now we should be able to start querying the object, add more individuals to it or expand schema
  214. // -- we can also take 2-3 more jsons and merge them and return a specific axiom that will create a new stream
  215.  
  216.  
  217. var RealineSchemaState = [[1, 'ref', 'literal'], [2, 'key', 'literal'], [3, 'LH', 'object']]
  218.  
  219. function JsonPropertyAssertion(parent, child)
  220.  
  221.  
  222. function PropertyDeclaration(value) { var prop = [1, dateTime.Now(), ] return message }
  223.  
  224. function PropertyAssertion(propertyDeclaration) { var message = [] return message}
  225.  
  226. Property('dog') = value
  227.  
  228. function stream(functionDeclaration, params[]) { var instance = [] return instance }
  229.  
  230. arguments = [Property("ref", ...), ]
  231. var state = stream('objectAssert', arguments)
  232.  
  233. function DeclareState() { return []}
  234.  
  235. function router(element) { run('runJsonObjectSchemaAssertion', element) }
  236.  
  237.  
  238.  
  239. // Json processing
  240. // 0. Parse to AST
  241. // 1. Generate schema
  242. // 2. Upload data
  243.  
  244. // runtime schema
  245. -- argument
  246. -- parameter
  247. -- function
  248. -- function.name
  249. -- value
  250. -- functionDefinition // this is what is described in the code -- intersect, declare
  251.  
  252.  
  253. // function definition
  254. function abc(params) { run(....) return value}
  255. abc(argument) = value
  256. //
  257.  
  258. // schema[] schema.push(functionDefinition) ==> value = run(function.name, argument) // our worker
  259. // data = data.push(value)
  260.  
  261. // abstraction level --> schemaGraph
  262. // grammar item for the schema graph --> nodeType == property
  263. // and then we add a specific item
  264.  
  265. schema: [s(id)(SchemaItem, type=property), p-(has), o-(Params: type:literal), v=key.value ("ref" as name)] // (schemaitem, schemaConcept, schmagrpah)
  266.  
  267. // when we create individuals - we do not create an explicit edge - instead we use our 3 digit ID
  268.  
  269. data: [s(id, schemaItemId, schemaId), p(has??literal), o(id, value--xxx) ] // here we also need to use ontology logic on high level (data property)
  270. state: [subject +++ data ] // individuals
  271. ------------------ ^^^^^ graph logic
  272.  
  273. ------------------ ontology logic
  274. stream: [subject +++ schema] --> filter by schemaid, schemaItemId --> push to state // schema --> filter/assertion --
  275.  
  276. --- [s[2,2,2],098980980, [params] [props], pred(params, props), object[state-msg1, state-msg-2,..]]
  277. --- [s, p, o[state]] == graph == object
  278. --- schema --> linked to stream subject conceptId/schemaId == ontology class
  279. --- query --> linked to stream predicate conceptId/schemaId == object property (in schema we have detailed mapping to methdos - we need to account for get and put)
  280. --- object --> message array --> we can use it reconstruct the "data tree"
  281. --- stream = vertex, state = props
  282. --- stream predicate link = function -- params, props==arguments (definition link), (input) object (output - (*-generated when processed), 2, 2 ) [props] [params: value="xxx"]
  283. --- function[predicate] abc(object) { [params] return subject}
  284.  
  285. // when we move data from stream to stream --> means we do "assertion"
  286. // when we add to a specific stream --> we do assertion
  287.  
  288. =================================
  289. -- messages -- props, params [subject, predcate, object] --> state -- vertex+props/params // graph
  290. state -- [id, [props], [params], label?]
  291. property --- [subjId, predicate(has), objectId [params], [props=value] ]
  292.  
  293. -- streams -- classes[class/object property/data property] --> stream -- object(props/params), objectProperty(props/params), dataProperty(props, params)// ontology
  294.  
  295. -- how do we create the schema for graph and ontology
  296. -- how do we store the data for graph and ontology
  297.  
  298. ------------------
  299. -- what elements do we have in schema
  300. -- what is the order
  301. -- what are the params
  302. -- need to reduce it to non-repeating values
  303. -- need to be able to take our schema and take apart the data to messages later
  304. ------------------
  305. -- take apart data based on the schema
  306. ------------------
  307.  
  308. // schema generation
  309. [subject (schema), predicate(has), object(node-LH -- key, runtime)]
  310.  
  311. // data
  312.  
  313.  
  314. const SchemaItemId = 2; // each will have their schema when it is created - we need to create schema first
  315. let sequenceId = 1;
  316. let value = ['abc', 'hdhd'];
  317.  
  318. const property = [[ sequenceId++, SchemaItemId, Date.now()], value];
  319. let parameter = [[sequenceId++, SchemaItemId, Date.now()], []];
  320. let object = [[sequenceId++, SchemaItemId, Date.now()], [property, property], []];
  321.  
  322. let functionDefinition = [object, [[sequenceId++, SchemaItemId, Date.now()], [], [parameter, parameter]]]; // edge in schema == function
  323. const message = [object, [[sequenceId++, SchemaItemId, Date.now()], [], [parameter, parameter]], object]; // edge in data
  324.  
  325.  
  326. const input = [[sequenceId++, SchemaItemId, Date.now()], [vertexProperty, vertexProperty], []];
  327. let output = message;
  328.  
  329. const functionBody = '';// workflow = array of schema items
  330. parameter = [[[sequenceId++, SchemaItemId, Date.now()], []], [[sequenceId++, SchemaItemId, Date.now()], []]]; /// edge params style
  331. const functionName = 'text' // from schema;
  332. functionDefinition = [functionName, functionBody, parameter];
  333.  
  334. const argument = [vertex]; // [[sequenceId++, SchemaItemId, Date.now()], [vertexProperty, vertexProperty], []];
  335. //output = run(functionDefinition, argument, input); // == [[sequenceId++, SchemaItemId, Date.now()], [vertexProperty, vertexProperty], []];
  336.  
  337. //==================== GRPAH LOGIC ============================
  338.  
  339.  
  340. const vertexProperty = property;
  341. const edgeParameter = parameter
  342. const vertex = object;
  343. const edgeSchema = functionDefinition;
  344.  
  345. const edgeData = message
  346.  
  347. const graph = [[vertex, message] , [vertex, message] , [vertex, message] ]
  348.  
  349.  
  350. //================= STATE LOGIC =================================
  351.  
  352. const subject = vertex;
  353. const predicate = []; // function name linking to functionDefinition???
  354. object = vertex;
  355.  
  356. const state = [graph, graph];
  357. const schema = [];
  358. const stream = [state, schema]; // stream is a just a function schema-graph, state-graph ---->>>> state2-graph
  359.  
  360.  
  361. //================= ONTOLOGY LOGIC =================================
  362. const ontology = [stream, stream]; // schema of streams --- all logic pretty much the same as above - stream of functions
  363. const classIndividuals = [state, state] // schema of states -- stream of states
  364.  
  365.  
  366.  
  367. //const agent = [[ontology,classIndividuals ], [ontology,classIndividuals ]]
  368.  
  369. //========================== FUNCTIONAL LOGIC ======================
  370.  
  371. // runtime schema
  372. -- argument
  373. -- parameter
  374. -- function
  375. -- function.name
  376. -- value
  377.  
  378. // event logic
  379. -- delegate (run, delegate, onAction)
  380. -- workerUnit (webworkerUnit, runtimeUnit) (class) -- these go per workspace
  381. -- worker (intersect, sum, save )
  382. -- supervisor (onWorker???) (this will be a callback)
  383. -- router (onEvent - contextRouter)
  384.  
  385. -- message
  386. -- event
  387. -- action
  388.  
  389. // state logic
  390. -- delegateState (persistent)
  391. -- workerUnit (...)
  392.  
  393. --> push first event based on JSON
  394. --> generate event on UI
  395.  
  396. -- Event -> "run" --> delegate --> workerUnit(command) --> worker (declares) --> |result| --> supervisor(asserts) >> ? write to stream : discard >> callsLOnEvent(result) --> Event to Subscribers==delegate
  397. // command logic
  398. -- action --> "do" --> onStream(delegate) --> workerUnit(?)....
  399. ===================================================================================
  400. // assertEvent --> 'call action'
  401. // it is subscribed to specific states to get events
  402.  
  403. function perceptor(message) { // on event
  404. // on event external
  405. // message -- save it or proces otherwise -- save plans we sent so we can confirm completion
  406. var actions = getPlans(message); // actions: [[workername, params]]
  407. delegate(actions); // 'intersect', 'array1, array2'
  408. }
  409.  
  410. const conditionsState = [] // beliefs
  411. const delegateState = [];
  412.  
  413. // business logic condition check to decide when to execute action (eg - it may wait for validation completed)
  414. // brokers out the action to a specific worker
  415.  
  416. function delegate(action) {
  417. // get plan or hold the action
  418. // save actions to delegateState
  419. // check pre-conditions to fire actions --- intersect with some other state
  420.  
  421. var currentActions = delegateState.intersect(conditionsState);
  422.  
  423. foreach(currentActions) {}
  424. // here w will be calling worker units, but without millions of callbacks and need to manage with state
  425.  
  426. run('functionaName', 'params', supervisor) // internal event
  427. }
  428. }
  429.  
  430. const supervisorState = [];
  431. // check worker results and 'declares' that an event has happened
  432. function supervisor(result) { // it checks if the worker results are satisfactory // intrnal actions
  433. // if true, save to all states and push a list to to router (on event) as an array
  434. if result good then
  435. workspace(result); // maybe call it in a loop?
  436. else
  437. delegate(...)
  438. end
  439. }
  440.  
  441. const workspaceState = []
  442. // manages all states, streams and agents
  443. function workspace(message) { // it keeps events and manages subscriptions == router
  444. // we need to get a list of subscribers
  445. foreach....(perceptor(message)) // external event
  446. }
  447.  
  448.  
  449. =================== worker functions =========== // intersect, sum, callApi, render .....
  450.  
  451. function worker(state) { /// this works in webworker/serviceworker/serverside
  452. const state = [];
  453. // it can call other functions from code
  454. // worker is written in code as our helper function
  455. }
  456.  
  457. function getPlan()
  458.  
  459. function generatePlan()
  460.  
  461. function run() { return }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement