theprogrammablemind 7.1.4-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ const { Semantics, Semantic } = require('./src/semantics')
2
+ const { Generators, Generator } = require('./src/generators')
3
+ const { Config } = require('./src/config')
4
+ const Digraph = require('./src/digraph')
5
+ const client = require('./client')
6
+ const flattens = require('./src/flatten')
7
+ const unflatten = require('./src/unflatten')
8
+
9
+ module.exports = {
10
+ process: client.process,
11
+ submitBug: client.submitBug,
12
+ processContext: client.processContext,
13
+ processContexts: client.processContexts,
14
+ runTests: client.runTests,
15
+ knowledgeModule: client.knowledgeModule,
16
+ ensureTestFile: client.ensureTestFile,
17
+ where: client.where,
18
+ w: client.w,
19
+ Config,
20
+ Semantics,
21
+ Semantic,
22
+ Generators,
23
+ Generator,
24
+ Digraph,
25
+ flattens: flattens.flattens,
26
+ unflatten: unflatten.unflatten
27
+ }
package/lines.js ADDED
@@ -0,0 +1,61 @@
1
+ class Lines {
2
+ constructor (widths) {
3
+ this.widths = widths
4
+ this.lines = []
5
+ this.rows = []
6
+ }
7
+
8
+ addLine () {
9
+ this.lines.push(this.widths.map((width) => ''.padEnd(width)))
10
+ }
11
+
12
+ // will wrap to next line within the column
13
+ setElement (row, column, value) {
14
+ const values = value.toString().split('\n')
15
+ const width = this.widths[column]
16
+ let index = 0
17
+ for (value of values) {
18
+ while (value.length > 0) {
19
+ const lineValue = value.substring(0, width).padEnd(width)
20
+ const remaining = value.substring(width)
21
+ const line = this.getLine(row + index)
22
+ line[column] = lineValue
23
+ value = remaining
24
+ ++index
25
+ }
26
+ }
27
+ }
28
+
29
+ toString () {
30
+ this.newRow()
31
+ let result = ''
32
+ for (const row of this.rows) {
33
+ result += row
34
+ result += '\n'
35
+ }
36
+ return result
37
+ }
38
+
39
+ newRow () {
40
+ for (const line of this.lines) {
41
+ this.rows.push(line.join(''))
42
+ }
43
+ this.lines = []
44
+ }
45
+
46
+ log () {
47
+ for (const line of this.lines) {
48
+ console.log(line.join(''))
49
+ }
50
+ this.lines = []
51
+ }
52
+
53
+ getLine (indexFromZero) {
54
+ while (this.lines.length < indexFromZero + 1) {
55
+ this.addLine()
56
+ }
57
+ return this.lines[indexFromZero]
58
+ }
59
+ }
60
+
61
+ module.exports = Lines
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "keywords": [
3
+ "NLP",
4
+ "NLU",
5
+ "NLC",
6
+ "natural language processing",
7
+ "natural language generation",
8
+ "natural language understanding",
9
+ "chatbot"
10
+ ],
11
+ "dependencies": {
12
+ "uuid": "^8.3.2",
13
+ "sort-json": "^2.0.0",
14
+ "lodash": "^4.17.20",
15
+ "readline": "^1.3.0",
16
+ "base-64": "^1.0.0",
17
+ "deep-equal": "^2.0.4",
18
+ "scriptjs": "^2.5.9",
19
+ "underscore": "^1.13.1",
20
+ "json-stable-stringify": "^1.0.1",
21
+ "json-diff": "^1.0.3",
22
+ "fs": "0.0.1-security",
23
+ "node-fetch": "^2.6.1"
24
+ },
25
+ "main": "index.js",
26
+ "files": [
27
+ "client.js",
28
+ "index.js",
29
+ "lines.js",
30
+ "src/helpers.js",
31
+ "src/flatten.js",
32
+ "src/unflatten.js",
33
+ "src/config.js",
34
+ "src/copy.js",
35
+ "src/digraph.js",
36
+ "src/generators.js",
37
+ "src/semantics.js"
38
+ ],
39
+ "name": "theprogrammablemind",
40
+ "scripts": {
41
+ "lint": "eslint \"**/*.js\"",
42
+ "to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO",
43
+ "lint:fix": "eslint \"**/*.js\" --fix",
44
+ "test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
45
+ "test": "jest --config ./jest.config.json",
46
+ "test:watch": "npm run test -- --watch",
47
+ "to": "node node_modules/.bin/jest --runInBand -t NEO",
48
+ "tod": "node inspect node_modules/.bin/jest --runInBand -t NEO"
49
+ },
50
+ "license": "ISC",
51
+ "devDependencies": {
52
+ "eslint-plugin-import": "^2.23.4",
53
+ "jest": "^26.6.3",
54
+ "eslint-plugin-node": "^11.1.0",
55
+ "eslint": "^7.31.0",
56
+ "@typescript-eslint/eslint-plugin": "^4.28.4",
57
+ "eslint-plugin-promise": "^5.1.0",
58
+ "@typescript-eslint/parser": "^4.28.4",
59
+ "eslint-config-standard": "^16.0.3"
60
+ },
61
+ "version": "7.1.4-beta.3",
62
+ "author": "dev@thinktelligence.com"
63
+ }
package/readme ADDED
@@ -0,0 +1,132 @@
1
+ # The Programmable Mind (aka Entodicton)
2
+
3
+ This is the client for a server that processes natural language statements
4
+ into JSON. Instead of using grammar based parser, the server uses a
5
+ generalized operator precedence parser and neural nets.
6
+
7
+ ## Demo Walkthough
8
+
9
+ If you run node_modules/entodiction/test.js that will run a sample
10
+ program against the API.
11
+
12
+ This is the input
13
+
14
+ ```
15
+ operators = ['(i [([went] ([to] (<the> store)))])']
16
+
17
+ bridges = [
18
+ { "id": "the", "level": 0, "bridge": "{ ...after, determiner: 'the' }" },
19
+ { "id": "to", "level": 0, "bridge": "{ ...next(operator), after: after[0] }" },
20
+ { "id": "went", "level": 0, "bridge": "{ ...squish(after[0]), ...next(operator) }" },
21
+ { "id": "went", "level": 1, "bridge": "{ ...next(operator), who: before[0] }" },
22
+ { "id": "went", "level": 2, "bridge": "{ action: 'go', marker: 'go', actor: operator.who, place: operator.to }" },
23
+ ]
24
+
25
+ utterances = ["joe went to the store"]
26
+ ```
27
+
28
+ ## Operators
29
+
30
+ Operators is used to do two things: specify the priority of operators and the argument structure. The priority
31
+ is used to train a neural net. The idea here is to give sample sentences that are marked up so a graph
32
+ of priorities can be made and fed to a neural net. The '[]' or '<>' is used to mark operators. In a generalized
33
+ operator precedence parser, the result of a apply an operator can be another operator. The '[]' means
34
+ there is a next operator the '<>' means there is not. The operators that this example defines are
35
+
36
+ ```
37
+ Operator/Level Arity
38
+ the/0 prefix operator
39
+ to/0 prefix operator
40
+ went/0 prefix operator
41
+ went/1 postfix operator
42
+ ```
43
+
44
+ The priorities defined in order of application are
45
+
46
+ ```
47
+ the/1 > to/1 > went/1 > went/2
48
+ ```
49
+
50
+
51
+ 'Went' could be defined as infix but in the future once I implement conjunction this definition will allow
52
+ sentences such as "I went to the store bought a coffee and chips and jumped on the bus and I got there".
53
+
54
+ ## Bridges
55
+
56
+ This works by combining contexts. Each context has a marker which indicates that is the operator. The
57
+ bridge langauge is used to specify how to combine contexts to get the next context. This abstraction
58
+ support multiple languages mapping ultimately to the same JSON. Its a generaliztion of what I did
59
+ before in the v4 design seen in the youtube video. The syntax is
60
+
61
+ ```
62
+ {
63
+ "id": <id of the operator>,
64
+ "level": <level of the operator>,
65
+ "bridge": <how to calculate new context>
66
+ }
67
+ ```
68
+
69
+ 'after' is the arguments after the operator. 'before' is the argument before the operator. 'operator' is the
70
+ operator. They are all contexts. The '...' operator works like the spread operator in JS. 'next(operator)'
71
+ will take increment the level for the operator. 'squish(<context>)' will take the marker of the context and
72
+ use that as a property name for the contexts. Here is an example. For this bridge
73
+
74
+ ```
75
+ {
76
+ "id": "went",
77
+ "level": 0,
78
+ "bridge": "{ ...squish(after[0]), ...next(operator) }"
79
+ }
80
+ ```
81
+
82
+ and initial state
83
+
84
+ ```
85
+ operator = { 'marker': went/0 }
86
+ after = [{
87
+ 'marker': to/0,
88
+ 'after': { 'marker': 'store', 'determiner': 'the' }
89
+ }]
90
+ ```
91
+
92
+ the result is
93
+
94
+ ```
95
+ {
96
+ 'marker': went/0,
97
+ 'to': {
98
+ 'marker': 'store',
99
+ 'determiner': 'the'
100
+ }
101
+ }
102
+ ```
103
+
104
+ ## Utterances
105
+
106
+ This is a list of statement that will be processed using the given definitions
107
+
108
+ ## Priorities
109
+
110
+ If request fail to process correctly one of the main causes is operator ordering. The 'operators' definition is used to generate training data for the ordering neural net. Sometimes that is not enough. There is a 'priorities' property that can be used to supply additional training data. Priorties is a list of operators. The last operator it the preferred one. The logs show the order that operators were run in. If it wrong look for another message like
111
+
112
+ ```
113
+ Context for choosing the operator ('wantMcDonalds', 0) was [('i', 0), ('wantMcDonalds', 0), ('aEnglish', 0), ('fromM', 0)]
114
+ ```
115
+
116
+ In this case I wanted 'fromM' to apply before 'wantMcDonalds'. So I add this to the priorities array
117
+
118
+ ```
119
+ [['i', 0], ['wantMcDonalds', 0], ['aEnglish', 0], ['fromM', 0]]
120
+ ```
121
+
122
+ ## Generators
123
+
124
+ A generator is used to describe how to map json back to strings. This is an example
125
+
126
+ ```
127
+ ({ 'marker': 'tankConcept', 'number': { '>': 0 } }, '${number} ${word}')
128
+ ```
129
+
130
+ The first part is a condition that is used to select the context. This example would match a context where the value 'marker' equals 'tankConcept' and the property 'number' is an number greater than zero. The second part can access properties in the context and generate a string. The access the properties 'number' and 'word' to generate a string.
131
+
132
+ List the default generators first. For example if you want English to be the default list the generator for English for and for other language with a language selector later.