ekms 8.0.0-beta.40 → 8.0.0-beta.42
Sign up to get free protection for your applications and to get access to all the features.
- package/common/listener.js +54 -0
- package/common/listener.test.json +104 -0
- package/common/nameable.js +6 -0
- package/common/stm.js +31 -5
- package/main.js +2 -0
- package/package.json +5 -2
@@ -0,0 +1,54 @@
|
|
1
|
+
const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
|
2
|
+
const { defaultContextCheck } = require('./helpers')
|
3
|
+
const helpers = require('./helpers')
|
4
|
+
const gdefaults = require('./gdefaults')
|
5
|
+
const listener_tests = require('./listener.test.json')
|
6
|
+
|
7
|
+
const configStruct = {
|
8
|
+
name: 'listener',
|
9
|
+
operators: [
|
10
|
+
{ pattern: "([call])", development: true },
|
11
|
+
],
|
12
|
+
bridges: [
|
13
|
+
{
|
14
|
+
id: 'call',
|
15
|
+
semantic: ({context}) => {
|
16
|
+
context.wasCalled = true
|
17
|
+
},
|
18
|
+
},
|
19
|
+
],
|
20
|
+
semantics: [
|
21
|
+
{
|
22
|
+
match: ({context}) => context.marker == 'call',
|
23
|
+
apply: ({context, defer}) => {
|
24
|
+
defer(({context}) => {
|
25
|
+
if (context.wasCalled) {
|
26
|
+
context.sawWasCalled = true
|
27
|
+
}
|
28
|
+
})
|
29
|
+
},
|
30
|
+
},
|
31
|
+
],
|
32
|
+
}
|
33
|
+
|
34
|
+
let createConfig = async () => {
|
35
|
+
const config = new Config(configStruct, module)
|
36
|
+
config.stop_auto_rebuild()
|
37
|
+
await config.add(gdefaults)
|
38
|
+
await config.restart_auto_rebuild()
|
39
|
+
return config
|
40
|
+
}
|
41
|
+
|
42
|
+
knowledgeModule( {
|
43
|
+
module,
|
44
|
+
description: 'test of listeners',
|
45
|
+
createConfig,
|
46
|
+
test: {
|
47
|
+
name: './listener.test.json',
|
48
|
+
contents: listener_tests,
|
49
|
+
checks: {
|
50
|
+
context: defaultContextCheck,
|
51
|
+
objects: ['mentioned', { km: 'gdefaults' }],
|
52
|
+
},
|
53
|
+
},
|
54
|
+
})
|
@@ -0,0 +1,104 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"associations": [
|
4
|
+
],
|
5
|
+
"config": {
|
6
|
+
},
|
7
|
+
"contexts": [
|
8
|
+
{
|
9
|
+
"dead": true,
|
10
|
+
"default": true,
|
11
|
+
"level": 1,
|
12
|
+
"marker": "call",
|
13
|
+
"range": {
|
14
|
+
"end": 3,
|
15
|
+
"start": 0
|
16
|
+
},
|
17
|
+
"sawWasCalled": true,
|
18
|
+
"text": "call",
|
19
|
+
"topLevel": true,
|
20
|
+
"touchedBy": [
|
21
|
+
"listener#call2"
|
22
|
+
],
|
23
|
+
"value": "call",
|
24
|
+
"wasCalled": true,
|
25
|
+
"word": "call"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"developerTest": false,
|
29
|
+
"generatedParenthesized": [
|
30
|
+
""
|
31
|
+
],
|
32
|
+
"metadata": {
|
33
|
+
"opChoices": [
|
34
|
+
{
|
35
|
+
"counter": 1,
|
36
|
+
"op": [
|
37
|
+
"call",
|
38
|
+
0
|
39
|
+
],
|
40
|
+
"ops": [
|
41
|
+
[
|
42
|
+
"call",
|
43
|
+
0
|
44
|
+
]
|
45
|
+
]
|
46
|
+
}
|
47
|
+
]
|
48
|
+
},
|
49
|
+
"objects": {
|
50
|
+
"nameToUUID": {
|
51
|
+
"gdefaults": "gdefaults2",
|
52
|
+
"listener": "listener1",
|
53
|
+
"tokenize": "tokenize2"
|
54
|
+
},
|
55
|
+
"namespaced": {
|
56
|
+
"gdefaults2": {
|
57
|
+
},
|
58
|
+
"listener1": {
|
59
|
+
},
|
60
|
+
"tokenize2": {
|
61
|
+
}
|
62
|
+
},
|
63
|
+
"processed": [
|
64
|
+
{
|
65
|
+
"context": {
|
66
|
+
"dead": true,
|
67
|
+
"default": true,
|
68
|
+
"level": 1,
|
69
|
+
"marker": "call",
|
70
|
+
"range": {
|
71
|
+
"end": 3,
|
72
|
+
"start": 0
|
73
|
+
},
|
74
|
+
"sawWasCalled": true,
|
75
|
+
"text": "call",
|
76
|
+
"topLevel": true,
|
77
|
+
"touchedBy": [
|
78
|
+
"listener#call2"
|
79
|
+
],
|
80
|
+
"value": "call",
|
81
|
+
"wasCalled": true,
|
82
|
+
"word": "call"
|
83
|
+
},
|
84
|
+
"generatedParenthesized": "",
|
85
|
+
"paraphrases": "call",
|
86
|
+
"paraphrasesParenthesized": "(call)",
|
87
|
+
"responses": [
|
88
|
+
""
|
89
|
+
]
|
90
|
+
}
|
91
|
+
]
|
92
|
+
},
|
93
|
+
"paraphrases": [
|
94
|
+
"call"
|
95
|
+
],
|
96
|
+
"paraphrasesParenthesized": [
|
97
|
+
"(call)"
|
98
|
+
],
|
99
|
+
"query": "call",
|
100
|
+
"responses": [
|
101
|
+
""
|
102
|
+
]
|
103
|
+
}
|
104
|
+
]
|
package/common/nameable.js
CHANGED
@@ -45,6 +45,11 @@ class API {
|
|
45
45
|
return [...names]
|
46
46
|
}
|
47
47
|
|
48
|
+
getNames(nameable) {
|
49
|
+
return (nameable.stm && nameable.stm.names) || []
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
48
53
|
getNames() {
|
49
54
|
const current = this.current()
|
50
55
|
console.log('getReportNames current', JSON.stringify(current, null, 2))
|
@@ -53,6 +58,7 @@ class API {
|
|
53
58
|
return { name, selected, id: name }
|
54
59
|
})
|
55
60
|
}
|
61
|
+
*/
|
56
62
|
|
57
63
|
setCurrent(name) {
|
58
64
|
const context = this.objects.named[name]
|
package/common/stm.js
CHANGED
@@ -65,8 +65,14 @@ class API {
|
|
65
65
|
this._objects.mentioned.unshift(concept)
|
66
66
|
}
|
67
67
|
|
68
|
-
mentions({ context, useHierarchy=true, condition = (() => true) } = {}) {
|
68
|
+
mentions({ context, useHierarchy=true, all, condition = (() => true) } = {}) {
|
69
69
|
const findPrevious = !!context.stm_previous
|
70
|
+
const forAll = []
|
71
|
+
const addForAll = (context) => {
|
72
|
+
if (!forAll.find( (c) => c.stm.id == context.stm.id)) {
|
73
|
+
forAll.push(context)
|
74
|
+
}
|
75
|
+
}
|
70
76
|
|
71
77
|
// care about value first
|
72
78
|
let findCounter = 0
|
@@ -77,7 +83,11 @@ class API {
|
|
77
83
|
continue
|
78
84
|
}
|
79
85
|
if (condition()) {
|
80
|
-
|
86
|
+
if (all) {
|
87
|
+
allForAll(m)
|
88
|
+
} else {
|
89
|
+
return m
|
90
|
+
}
|
81
91
|
}
|
82
92
|
}
|
83
93
|
}
|
@@ -95,7 +105,11 @@ class API {
|
|
95
105
|
continue
|
96
106
|
}
|
97
107
|
if (condition(m)) {
|
98
|
-
|
108
|
+
if (all) {
|
109
|
+
addForAll(m)
|
110
|
+
} else {
|
111
|
+
return m
|
112
|
+
}
|
99
113
|
}
|
100
114
|
}
|
101
115
|
// if (context.types && context.types.includes(m.marker)) {
|
@@ -107,7 +121,11 @@ class API {
|
|
107
121
|
continue
|
108
122
|
}
|
109
123
|
if (condition(m)) {
|
110
|
-
|
124
|
+
if (all) {
|
125
|
+
addForAll(m)
|
126
|
+
} else {
|
127
|
+
return m
|
128
|
+
}
|
111
129
|
}
|
112
130
|
}
|
113
131
|
}
|
@@ -123,11 +141,19 @@ class API {
|
|
123
141
|
continue
|
124
142
|
}
|
125
143
|
if (condition(m)) {
|
126
|
-
|
144
|
+
if (all) {
|
145
|
+
addForAll(m)
|
146
|
+
} else {
|
147
|
+
return m
|
148
|
+
}
|
127
149
|
}
|
128
150
|
}
|
129
151
|
}
|
130
152
|
}
|
153
|
+
|
154
|
+
if (all) {
|
155
|
+
return forAll
|
156
|
+
}
|
131
157
|
}
|
132
158
|
|
133
159
|
getVariable(name) {
|
package/main.js
CHANGED
@@ -19,6 +19,7 @@ const hierarchy = require('./common/hierarchy')
|
|
19
19
|
const ordering = require('./common/ordering')
|
20
20
|
const properties = require('./common/properties')
|
21
21
|
const sizeable = require('./common/sizeable')
|
22
|
+
const listener = require('./common/listener')
|
22
23
|
const tokenize = require('./common/tokenize')
|
23
24
|
const articles = require('./common/articles')
|
24
25
|
const nameable = require('./common/nameable')
|
@@ -73,6 +74,7 @@ module.exports = {
|
|
73
74
|
ordering,
|
74
75
|
properties,
|
75
76
|
sizeable,
|
77
|
+
listener,
|
76
78
|
tokenize,
|
77
79
|
articles,
|
78
80
|
nameable,
|
package/package.json
CHANGED
@@ -46,6 +46,7 @@
|
|
46
46
|
"name": "Hidden",
|
47
47
|
"description": "Don't show in the UI",
|
48
48
|
"includes": [
|
49
|
+
"listener",
|
49
50
|
"tokenize"
|
50
51
|
]
|
51
52
|
},
|
@@ -198,6 +199,8 @@
|
|
198
199
|
"common/length.instance.json",
|
199
200
|
"common/length.js",
|
200
201
|
"common/length.test.json",
|
202
|
+
"common/listener.js",
|
203
|
+
"common/listener.test.json",
|
201
204
|
"common/math.instance.json",
|
202
205
|
"common/math.js",
|
203
206
|
"common/math.test.json",
|
@@ -291,8 +294,8 @@
|
|
291
294
|
"table": "^6.7.1",
|
292
295
|
"base-64": "^1.0.0",
|
293
296
|
"argparse": "^2.0.1",
|
294
|
-
"theprogrammablemind": "8.0.0-beta.
|
297
|
+
"theprogrammablemind": "8.0.0-beta.42"
|
295
298
|
},
|
296
|
-
"version": "8.0.0-beta.
|
299
|
+
"version": "8.0.0-beta.42",
|
297
300
|
"license": "UNLICENSED"
|
298
301
|
}
|