occam-verify-cli 1.0.387 → 1.0.396
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/lib/action/verify.js +3 -3
- package/lib/context/file.js +8 -7
- package/lib/context/local.js +23 -57
- package/lib/context/temporary.js +705 -0
- package/lib/mixins/statement/verify.js +38 -16
- package/lib/mixins/step/unify.js +3 -3
- package/lib/node/substitution/frame.js +23 -1
- package/lib/node/substitution/term.js +23 -1
- package/lib/ontology/assertion/contained.js +77 -35
- package/lib/ontology/assertion/defined.js +76 -34
- package/lib/ontology/assertion/property.js +71 -29
- package/lib/ontology/assertion/satisfies.js +70 -22
- package/lib/ontology/assertion/subproof.js +95 -41
- package/lib/ontology/assertion/type.js +74 -18
- package/lib/ontology/assertion.js +66 -0
- package/lib/ontology/axiom.js +8 -11
- package/lib/ontology/combinator/bracketed.js +17 -3
- package/lib/ontology/combinator.js +17 -3
- package/lib/ontology/conclusion.js +38 -9
- package/lib/ontology/constructor/bracketed.js +17 -3
- package/lib/ontology/constructor.js +17 -3
- package/lib/ontology/declaration.js +27 -2
- package/lib/ontology/deduction.js +38 -9
- package/lib/ontology/frame.js +50 -13
- package/lib/ontology/hypothesis.js +11 -11
- package/lib/ontology/judgement.js +1 -1
- package/lib/ontology/label.js +5 -6
- package/lib/ontology/metavariable.js +11 -12
- package/lib/ontology/premise.js +47 -17
- package/lib/ontology/procedureCall.js +15 -15
- package/lib/ontology/procedureReference.js +1 -1
- package/lib/ontology/proof.js +2 -2
- package/lib/ontology/reference.js +4 -5
- package/lib/ontology/rule.js +68 -69
- package/lib/ontology/section.js +2 -2
- package/lib/ontology/signature.js +2 -2
- package/lib/ontology/statement.js +9 -1
- package/lib/ontology/step.js +37 -24
- package/lib/ontology/subproof.js +11 -11
- package/lib/ontology/substitution/frame.js +69 -21
- package/lib/ontology/substitution/reference.js +24 -9
- package/lib/ontology/substitution/statement.js +99 -79
- package/lib/ontology/substitution/term.js +89 -29
- package/lib/ontology/substitution.js +37 -30
- package/lib/ontology/supposition.js +56 -25
- package/lib/ontology/term.js +4 -3
- package/lib/ontology/topLevelAssertion.js +15 -15
- package/lib/ontology/topLevelMetaAssertion.js +2 -2
- package/lib/ontology/variable.js +42 -14
- package/lib/substitutions.js +25 -25
- package/lib/unifier/intrinsicLevel.js +14 -7
- package/lib/unifier/metaLevel.js +25 -17
- package/lib/utilities/brackets.js +4 -21
- package/lib/utilities/context.js +6 -6
- package/lib/utilities/json.js +24 -1
- package/lib/utilities/metavariable.js +18 -0
- package/lib/utilities/substitutions.js +3 -3
- package/lib/utilities/unification.js +10 -16
- package/lib/utilities/variable.js +30 -0
- package/package.json +2 -2
- package/src/action/verify.js +2 -2
- package/src/context/file.js +8 -7
- package/src/context/local.js +13 -61
- package/src/context/temporary.js +394 -0
- package/src/mixins/statement/verify.js +60 -23
- package/src/mixins/step/unify.js +2 -2
- package/src/node/substitution/frame.js +26 -0
- package/src/node/substitution/term.js +26 -0
- package/src/ontology/assertion/contained.js +12 -23
- package/src/ontology/assertion/defined.js +12 -23
- package/src/ontology/assertion/property.js +7 -20
- package/src/ontology/assertion/satisfies.js +7 -16
- package/src/ontology/assertion/subproof.js +36 -42
- package/src/ontology/assertion/type.js +10 -11
- package/src/ontology/assertion.js +23 -0
- package/src/ontology/axiom.js +7 -16
- package/src/ontology/combinator/bracketed.js +2 -0
- package/src/ontology/combinator.js +2 -0
- package/src/ontology/conclusion.js +51 -10
- package/src/ontology/constructor/bracketed.js +2 -0
- package/src/ontology/constructor.js +2 -0
- package/src/ontology/declaration.js +34 -1
- package/src/ontology/deduction.js +51 -10
- package/src/ontology/frame.js +58 -21
- package/src/ontology/hypothesis.js +8 -8
- package/src/ontology/judgement.js +1 -1
- package/src/ontology/label.js +2 -7
- package/src/ontology/metavariable.js +12 -15
- package/src/ontology/premise.js +64 -21
- package/src/ontology/procedureCall.js +14 -14
- package/src/ontology/procedureReference.js +2 -2
- package/src/ontology/proof.js +1 -1
- package/src/ontology/reference.js +1 -6
- package/src/ontology/rule.js +76 -80
- package/src/ontology/section.js +1 -1
- package/src/ontology/signature.js +1 -1
- package/src/ontology/statement.js +6 -0
- package/src/ontology/step.js +43 -26
- package/src/ontology/subproof.js +8 -8
- package/src/ontology/substitution/frame.js +72 -26
- package/src/ontology/substitution/reference.js +8 -6
- package/src/ontology/substitution/statement.js +93 -77
- package/src/ontology/substitution/term.js +108 -42
- package/src/ontology/substitution.js +27 -22
- package/src/ontology/supposition.js +70 -24
- package/src/ontology/term.js +5 -5
- package/src/ontology/topLevelAssertion.js +14 -16
- package/src/ontology/topLevelMetaAssertion.js +1 -1
- package/src/ontology/variable.js +64 -17
- package/src/substitutions.js +25 -25
- package/src/unifier/intrinsicLevel.js +18 -8
- package/src/unifier/metaLevel.js +35 -21
- package/src/utilities/brackets.js +3 -29
- package/src/utilities/context.js +5 -5
- package/src/utilities/json.js +28 -0
- package/src/utilities/metavariable.js +13 -0
- package/src/utilities/substitutions.js +2 -4
- package/src/utilities/unification.js +8 -24
- package/src/utilities/variable.js +22 -0
package/src/ontology/variable.js
CHANGED
|
@@ -127,13 +127,12 @@ export default define(class Variable {
|
|
|
127
127
|
|
|
128
128
|
variable = this; ///
|
|
129
129
|
|
|
130
|
-
const
|
|
130
|
+
const substitution = substitutions.findSubstitutionByVariable(variable);
|
|
131
131
|
|
|
132
|
-
if (
|
|
132
|
+
if (substitution !== null) {
|
|
133
133
|
context = specificContext; ///
|
|
134
134
|
|
|
135
|
-
const
|
|
136
|
-
substitutionTermEqualToTerm = substitution.isTermEqualTo(term, context);
|
|
135
|
+
const substitutionTermEqualToTerm = substitution.isTermEqualToTerm(term, context);
|
|
137
136
|
|
|
138
137
|
if (substitutionTermEqualToTerm) {
|
|
139
138
|
termUnifies = true;
|
|
@@ -147,26 +146,20 @@ export default define(class Variable {
|
|
|
147
146
|
|
|
148
147
|
context = specificContext; ///
|
|
149
148
|
|
|
150
|
-
const
|
|
151
|
-
let verifiesAhead = false;
|
|
149
|
+
const termNode = term.getNode();
|
|
152
150
|
|
|
153
|
-
|
|
154
|
-
variableType = variable.getType(),
|
|
155
|
-
termTypeEqualToOrSubTypeOfVariableType = termType.isEqualToOrSubTypeOf(variableType);
|
|
151
|
+
term = context.findTermByTermNode(termNode);
|
|
156
152
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
153
|
+
const termType = term.getType(),
|
|
154
|
+
variableType = variable.getType(),
|
|
155
|
+
termTypeEqualToOrSubTypeOfVariableType = termType.isEqualToOrSubTypeOf(variableType);
|
|
160
156
|
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
if (termVerifies) {
|
|
157
|
+
if (termTypeEqualToOrSubTypeOfVariableType) {
|
|
165
158
|
const { TermSubstitution } = ontology,
|
|
166
159
|
termSubstitution = TermSubstitution.fromTernAndVariable(term, variable, context),
|
|
167
160
|
substitution = termSubstitution; ///
|
|
168
161
|
|
|
169
|
-
substitutions.addSubstitution(substitution,
|
|
162
|
+
substitutions.addSubstitution(substitution, context);
|
|
170
163
|
|
|
171
164
|
termUnifies = true;
|
|
172
165
|
}
|
|
@@ -179,6 +172,60 @@ export default define(class Variable {
|
|
|
179
172
|
return termUnifies;
|
|
180
173
|
}
|
|
181
174
|
|
|
175
|
+
unifyTermVariable(termVariable, substitutions, generalContext, specificContext) {
|
|
176
|
+
let termVariableUnifies = false;
|
|
177
|
+
|
|
178
|
+
const variableString = this.string, ///
|
|
179
|
+
termVariableString = termVariable.getString();
|
|
180
|
+
|
|
181
|
+
specificContext.trace(`Unifying the '${termVariableString}' term variable with the '${variableString}' variable...`);
|
|
182
|
+
|
|
183
|
+
let context,
|
|
184
|
+
variable;
|
|
185
|
+
|
|
186
|
+
variable = this; ///
|
|
187
|
+
|
|
188
|
+
const substitution = substitutions.findSubstitutionByVariable(variable);
|
|
189
|
+
|
|
190
|
+
if (substitution !== null) {
|
|
191
|
+
context = specificContext; ///
|
|
192
|
+
|
|
193
|
+
const substitutionTermVariableEqualToTerm = substitution.isTermVariableEqualToTerm(termVariable, context);
|
|
194
|
+
|
|
195
|
+
if (substitutionTermVariableEqualToTerm) {
|
|
196
|
+
termVariableUnifies = true;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
context = generalContext; ///
|
|
200
|
+
|
|
201
|
+
const variableIdentifier = variable.getIdentifier();
|
|
202
|
+
|
|
203
|
+
variable = context.findVariableByVariableIdentifier(variableIdentifier);
|
|
204
|
+
|
|
205
|
+
context = specificContext; ///
|
|
206
|
+
|
|
207
|
+
const variableType = variable.getType(),
|
|
208
|
+
termVariableType = termVariable.getType(),
|
|
209
|
+
termVariableTypeEqualToOrSubTypeOfVariableType = termVariableType.isEqualToOrSubTypeOf(variableType);
|
|
210
|
+
|
|
211
|
+
if (termVariableTypeEqualToOrSubTypeOfVariableType) {
|
|
212
|
+
const { TermSubstitution } = ontology,
|
|
213
|
+
termSubstitution = TermSubstitution.fromTernVariableAndVariable(termVariable, variable, context),
|
|
214
|
+
substitution = termSubstitution; ///
|
|
215
|
+
|
|
216
|
+
substitutions.addSubstitution(substitution, context);
|
|
217
|
+
|
|
218
|
+
termVariableUnifies = true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (termVariableUnifies) {
|
|
223
|
+
specificContext.debug(`...unified the '${termVariableString}' term variable with the '${variableString}' variable.`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return termVariableUnifies;
|
|
227
|
+
}
|
|
228
|
+
|
|
182
229
|
toJSON() {
|
|
183
230
|
const typeJSON = typeToTypeJSON(this.type),
|
|
184
231
|
string = this.string, ///
|
package/src/substitutions.js
CHANGED
|
@@ -22,18 +22,6 @@ export default class Substitutions {
|
|
|
22
22
|
|
|
23
23
|
getLength() { return this.array.length; }
|
|
24
24
|
|
|
25
|
-
getFirstSubstitution() {
|
|
26
|
-
let firstSubstitution = null;
|
|
27
|
-
|
|
28
|
-
const length = this.getLength();
|
|
29
|
-
|
|
30
|
-
if (length > 0) {
|
|
31
|
-
firstSubstitution = first(this.array);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return firstSubstitution;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
25
|
getMetavariables() {
|
|
38
26
|
const metavariables = [];
|
|
39
27
|
|
|
@@ -70,6 +58,18 @@ export default class Substitutions {
|
|
|
70
58
|
return nonTrivialLength;
|
|
71
59
|
}
|
|
72
60
|
|
|
61
|
+
getFirstSubstitution() {
|
|
62
|
+
let firstSubstitution = null;
|
|
63
|
+
|
|
64
|
+
const length = this.getLength();
|
|
65
|
+
|
|
66
|
+
if (length > 0) {
|
|
67
|
+
firstSubstitution = first(this.array);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return firstSubstitution;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
73
|
mapSubstitution(callback) { return this.array.map(callback); }
|
|
74
74
|
|
|
75
75
|
findSubstitution(callback) { return this.array.find(callback) || null; } ///
|
|
@@ -107,7 +107,7 @@ export default class Substitutions {
|
|
|
107
107
|
|
|
108
108
|
findSubstitutionsByMetavariable(metavariable) {
|
|
109
109
|
const substitutions = this.findSubstitutions((substitution) => {
|
|
110
|
-
const substitutionMetavariableEqualToMetavariable = substitution.
|
|
110
|
+
const substitutionMetavariableEqualToMetavariable = substitution.isMetavariableEqualToMetavariable(metavariable);
|
|
111
111
|
|
|
112
112
|
if (substitutionMetavariableEqualToMetavariable) {
|
|
113
113
|
return true;
|
|
@@ -123,7 +123,7 @@ export default class Substitutions {
|
|
|
123
123
|
|
|
124
124
|
if (substitutionSimple) {
|
|
125
125
|
const simpleSubstitution = substitution, ///
|
|
126
|
-
simpleSubstitutionMetavariableEqualToMetavariable = simpleSubstitution.
|
|
126
|
+
simpleSubstitutionMetavariableEqualToMetavariable = simpleSubstitution.isMetavariableEqualToMetavariable(metavariable);
|
|
127
127
|
|
|
128
128
|
if (simpleSubstitutionMetavariableEqualToMetavariable) {
|
|
129
129
|
return true;
|
|
@@ -140,7 +140,7 @@ export default class Substitutions {
|
|
|
140
140
|
|
|
141
141
|
if (substitutionComplex) {
|
|
142
142
|
const complexSubstitution = substitution, ///
|
|
143
|
-
complexSubstitutionMetavariableEqualToMetavariable = complexSubstitution.
|
|
143
|
+
complexSubstitutionMetavariableEqualToMetavariable = complexSubstitution.isMetavariableEqualToMetavariable(metavariable);
|
|
144
144
|
|
|
145
145
|
if (complexSubstitutionMetavariableEqualToMetavariable) {
|
|
146
146
|
return true;
|
|
@@ -155,11 +155,11 @@ export default class Substitutions {
|
|
|
155
155
|
const substitutionA = substitution; ///
|
|
156
156
|
|
|
157
157
|
substitution = this.findSubstitution((substitution) => { ///
|
|
158
|
-
const substitutionMetavariableEqualToMetavariable = substitution.
|
|
158
|
+
const substitutionMetavariableEqualToMetavariable = substitution.isMetavariableEqualToMetavariable(metavariable);
|
|
159
159
|
|
|
160
160
|
if (substitutionMetavariableEqualToMetavariable) {
|
|
161
161
|
const substitutionB = substitution, ///
|
|
162
|
-
substitutionBSubstitutionEqualToSubstitutionA = substitutionB.
|
|
162
|
+
substitutionBSubstitutionEqualToSubstitutionA = substitutionB.isSubstitutionEqualToSubstitution(substitutionA);
|
|
163
163
|
|
|
164
164
|
if (substitutionBSubstitutionEqualToSubstitutionA) {
|
|
165
165
|
return true;
|
|
@@ -192,15 +192,15 @@ export default class Substitutions {
|
|
|
192
192
|
return substitutionPresent;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
addSubstitution(substitution,
|
|
195
|
+
addSubstitution(substitution, context) {
|
|
196
196
|
this.array.push(substitution);
|
|
197
197
|
|
|
198
198
|
const substitutionString = substitution.getString();
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
context.trace(`Added the ${substitutionString} substitution.`);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
removeSubstitution(substitution,
|
|
203
|
+
removeSubstitution(substitution, context) {
|
|
204
204
|
const substitutionA = substitution; ///
|
|
205
205
|
|
|
206
206
|
prune(this.array, (substitution) => {
|
|
@@ -213,7 +213,7 @@ export default class Substitutions {
|
|
|
213
213
|
|
|
214
214
|
const substitutionString = substitution.getString();
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
context.trace(`Removed the ${substitutionString} substitution.`);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
correlateSubstitutions(substitutions) {
|
|
@@ -247,7 +247,7 @@ export default class Substitutions {
|
|
|
247
247
|
this.savedArray = null;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
resolve(
|
|
250
|
+
resolve(context) {
|
|
251
251
|
const metavariables = this.getMetavariables();
|
|
252
252
|
|
|
253
253
|
metavariables.forEach((metavariable) => {
|
|
@@ -261,7 +261,7 @@ export default class Substitutions {
|
|
|
261
261
|
resolved = substitution.isResolved();
|
|
262
262
|
|
|
263
263
|
if (!resolved) {
|
|
264
|
-
substitution.resolve(substitutions,
|
|
264
|
+
substitution.resolve(substitutions, context);
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
267
|
|
|
@@ -297,7 +297,7 @@ export default class Substitutions {
|
|
|
297
297
|
];
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
rollback(
|
|
300
|
+
rollback(context) {
|
|
301
301
|
const array = [
|
|
302
302
|
...this.array
|
|
303
303
|
];
|
|
@@ -305,7 +305,7 @@ export default class Substitutions {
|
|
|
305
305
|
leftDifference(array, this.savedArray);
|
|
306
306
|
|
|
307
307
|
array.forEach((substitution) => {
|
|
308
|
-
this.removeSubstitution(substitution,
|
|
308
|
+
this.removeSubstitution(substitution, context);
|
|
309
309
|
});
|
|
310
310
|
|
|
311
311
|
this.array = [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import ontology from "../ontology";
|
|
4
3
|
import Unifier from "../unifier";
|
|
5
4
|
|
|
6
5
|
import { nodeQuery } from "../utilities/query";
|
|
6
|
+
import { variableIdentifierFromVariableNode, termVariableIdentifierFromTermNode } from "../utilities/variable";
|
|
7
7
|
|
|
8
8
|
const termNodeQuery = nodeQuery("/term"),
|
|
9
9
|
termVariableNodeQuery = nodeQuery("/term/variable!");
|
|
@@ -24,23 +24,33 @@ class IntrinsicLevelUnifier extends Unifier {
|
|
|
24
24
|
generalNodeQuery: termVariableNodeQuery,
|
|
25
25
|
specificNodeQuery: termNodeQuery,
|
|
26
26
|
unify: (generalTermVariableNode, specificTermNode, substitutions, generalContext, specificContext) => {
|
|
27
|
-
let termUnifies;
|
|
27
|
+
let termUnifies = false;
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const termNode = specificTermNode, ///
|
|
30
|
+
variableNode = generalTermVariableNode, ///
|
|
31
|
+
variableIdentifier = variableIdentifierFromVariableNode(variableNode);
|
|
32
32
|
|
|
33
33
|
let context;
|
|
34
34
|
|
|
35
35
|
context = generalContext; ///
|
|
36
36
|
|
|
37
|
-
const variable =
|
|
37
|
+
const variable = context.findVariableByVariableIdentifier(variableIdentifier);
|
|
38
38
|
|
|
39
39
|
context = specificContext; ///
|
|
40
40
|
|
|
41
|
-
const term =
|
|
41
|
+
const term = context.findTermByTermNode(termNode);
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
if (term !== null) {
|
|
44
|
+
termUnifies = variable.unifyTerm(term, substitutions, generalContext, specificContext);
|
|
45
|
+
} else {
|
|
46
|
+
const termVariaibleIdentifer = termVariableIdentifierFromTermNode(termNode),
|
|
47
|
+
termVariable = context.findVariableByVariableIdentifier(termVariaibleIdentifer),
|
|
48
|
+
termVariableUnifies = variable.unifyTermVariable(termVariable, substitutions, generalContext, specificContext);
|
|
49
|
+
|
|
50
|
+
if (termVariableUnifies) {
|
|
51
|
+
termUnifies = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
|
|
45
55
|
return termUnifies;
|
|
46
56
|
}
|
package/src/unifier/metaLevel.js
CHANGED
|
@@ -4,7 +4,8 @@ import ontology from "../ontology";
|
|
|
4
4
|
import Unifier from "../unifier";
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
|
-
import
|
|
7
|
+
import { metavariableNameFromMetavariableNode } from "../utilities/metavariable";
|
|
8
|
+
import { variableIdentifierFromVariableNode, termVariableIdentifierFromTermNode } from "../utilities/variable";
|
|
8
9
|
|
|
9
10
|
const termNodeQuery = nodeQuery("/term"),
|
|
10
11
|
frameNodeQuery = nodeQuery("/frame"),
|
|
@@ -32,30 +33,32 @@ class MetaLevelUnifier extends Unifier {
|
|
|
32
33
|
unify: (generalStatementMetavariableNode, specificStatementNode, substitutions, generalContext, specificContext) => {
|
|
33
34
|
let statementUnifies;
|
|
34
35
|
|
|
35
|
-
const { Metavariable, Statement } = ontology; ///
|
|
36
|
-
|
|
37
36
|
let context,
|
|
37
|
+
statement,
|
|
38
38
|
statementNode;
|
|
39
39
|
|
|
40
40
|
context = generalContext; ///
|
|
41
41
|
|
|
42
42
|
const metavariableNode = generalStatementMetavariableNode, ///
|
|
43
|
-
|
|
43
|
+
metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
|
|
44
|
+
metavariable = context.findMetavariableByMetavariableName(metavariableName);
|
|
44
45
|
|
|
45
46
|
const metavariableNodeParentNode = metavariableNode.getParentNode();
|
|
46
47
|
|
|
47
48
|
statementNode = metavariableNodeParentNode; ///
|
|
48
49
|
|
|
50
|
+
statement = context.findStatementByStatementNode(statementNode);
|
|
51
|
+
|
|
49
52
|
const { TermSubstitution, FrameSubstitution } = ontology,
|
|
50
|
-
frameSubstitution = FrameSubstitution.
|
|
51
|
-
termSubstitution = TermSubstitution.
|
|
53
|
+
frameSubstitution = FrameSubstitution.fromStatement(statement, context),
|
|
54
|
+
termSubstitution = TermSubstitution.fromStatement(statement, context),
|
|
52
55
|
substitution = (frameSubstitution || termSubstitution);
|
|
53
56
|
|
|
54
57
|
context = specificContext; ///
|
|
55
58
|
|
|
56
59
|
statementNode = specificStatementNode; ///
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
statement = context.findStatementByStatementNode(statementNode);
|
|
59
62
|
|
|
60
63
|
statementUnifies = metavariable.unifyStatement(statement, substitution, substitutions, generalContext, specificContext);
|
|
61
64
|
|
|
@@ -68,19 +71,19 @@ class MetaLevelUnifier extends Unifier {
|
|
|
68
71
|
unify: (generalFrameDeclarationMetavariableNode, specificFrameNode, substitutions, generalContext, specificContext) => {
|
|
69
72
|
let frameUnifies;
|
|
70
73
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
const frameNode = specificFrameNode, ///
|
|
75
|
+
metavariableNode = generalFrameDeclarationMetavariableNode, ///
|
|
76
|
+
metavariableName = metavariableNameFromMetavariableNode(metavariableNode);
|
|
74
77
|
|
|
75
78
|
let context;
|
|
76
79
|
|
|
77
80
|
context = generalContext; ///
|
|
78
81
|
|
|
79
|
-
const metavariable =
|
|
82
|
+
const metavariable = context.findMetavariableByMetavariableName(metavariableName);
|
|
80
83
|
|
|
81
84
|
context = specificContext; ///
|
|
82
85
|
|
|
83
|
-
const frame =
|
|
86
|
+
const frame = context.findFrameByFrameNode(frameNode);
|
|
84
87
|
|
|
85
88
|
frameUnifies = metavariable.unifyFrame(frame, substitutions, generalContext, specificContext);
|
|
86
89
|
|
|
@@ -91,23 +94,33 @@ class MetaLevelUnifier extends Unifier {
|
|
|
91
94
|
generalNodeQuery: termVariableNodeQuery,
|
|
92
95
|
specificNodeQuery: termNodeQuery,
|
|
93
96
|
unify: (generalTermVariableNode, specificTermNode, substitutions, generalContext, specificContext) => {
|
|
94
|
-
let termUnifies;
|
|
97
|
+
let termUnifies = false;
|
|
95
98
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
const termNode = specificTermNode, ///
|
|
100
|
+
variableNode = generalTermVariableNode, ///
|
|
101
|
+
variableIdentifier = variableIdentifierFromVariableNode(variableNode);
|
|
99
102
|
|
|
100
103
|
let context;
|
|
101
104
|
|
|
102
105
|
context = generalContext; ///
|
|
103
106
|
|
|
104
|
-
const variable =
|
|
107
|
+
const variable = context.findVariableByVariableIdentifier(variableIdentifier);
|
|
105
108
|
|
|
106
109
|
context = specificContext; ///
|
|
107
110
|
|
|
108
|
-
const term =
|
|
111
|
+
const term = context.findTermByTermNode(termNode);
|
|
112
|
+
|
|
113
|
+
if (term !== null) {
|
|
114
|
+
termUnifies = variable.unifyTerm(term, substitutions, generalContext, specificContext);
|
|
115
|
+
} else {
|
|
116
|
+
const termVariaibleIdentifer = termVariableIdentifierFromTermNode(termNode),
|
|
117
|
+
termVariable = context.findVariableByVariableIdentifier(termVariaibleIdentifer),
|
|
118
|
+
termVariableUnifies = variable.unifyTermVariable(termVariable, substitutions, generalContext, specificContext);
|
|
109
119
|
|
|
110
|
-
|
|
120
|
+
if (termVariableUnifies) {
|
|
121
|
+
termUnifies = true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
111
124
|
|
|
112
125
|
return termUnifies;
|
|
113
126
|
}
|
|
@@ -118,7 +131,7 @@ class MetaLevelUnifier extends Unifier {
|
|
|
118
131
|
unify: (generalDeclarationMetavariableNode, specificDeclarationMetavariableNode, substitutions, generalContext, specificContext) => {
|
|
119
132
|
let referenceUnifies;
|
|
120
133
|
|
|
121
|
-
const {
|
|
134
|
+
const { Reference } = ontology;
|
|
122
135
|
|
|
123
136
|
let context,
|
|
124
137
|
metavariableNode;
|
|
@@ -127,7 +140,8 @@ class MetaLevelUnifier extends Unifier {
|
|
|
127
140
|
|
|
128
141
|
metavariableNode = generalDeclarationMetavariableNode; ///
|
|
129
142
|
|
|
130
|
-
const
|
|
143
|
+
const metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
|
|
144
|
+
metavariable = context.findMetavariableByMetavariableName(metavariableName);
|
|
131
145
|
|
|
132
146
|
context = specificContext; ///
|
|
133
147
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ontology from "../ontology";
|
|
4
|
-
import
|
|
4
|
+
import TemporaryContext from "../context/temporary";
|
|
5
5
|
import combinatorBracketedContext from "../context/bracketed/combinator";
|
|
6
6
|
import constructorBracketedContext from "../context/bracketed/constructor";
|
|
7
7
|
|
|
@@ -21,22 +21,6 @@ export function stripBracketsFromTerm(term, context) {
|
|
|
21
21
|
return term;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function stripBracketsFromReference(reference, context) {
|
|
25
|
-
const referenceNode = reference.getNode(),
|
|
26
|
-
bracketedReferenceChildNode = bracketedReferenceChildNodeFromReferenceNode(referenceNode);
|
|
27
|
-
|
|
28
|
-
if (bracketedReferenceChildNode !== null) {
|
|
29
|
-
context = contextFromReference(reference, context); ///
|
|
30
|
-
|
|
31
|
-
const { Reference } = ontology,
|
|
32
|
-
referenceNode = bracketedReferenceChildNode; ///
|
|
33
|
-
|
|
34
|
-
reference = Reference.fromReferenceNode(referenceNode, context);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return reference;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
24
|
export function stripBracketsFromStatement(statement, context) {
|
|
41
25
|
const statementNode = statement.getNode(),
|
|
42
26
|
bracketedStatementChildNode = bracketedStatementChildNodeFromStatementNode(statementNode);
|
|
@@ -105,22 +89,12 @@ export function bracketedStatementChildNodeFromStatementNode(statementNode) {
|
|
|
105
89
|
return bracketedStatementChildNode;
|
|
106
90
|
}
|
|
107
91
|
|
|
108
|
-
function contextFromReference(reference, context) {
|
|
109
|
-
const referenceTokens = reference.getTokens(),
|
|
110
|
-
tokens = referenceTokens, ///
|
|
111
|
-
localContext = LocalContext.fromContextAndTokens(context, tokens);
|
|
112
|
-
|
|
113
|
-
context = localContext; ///
|
|
114
|
-
|
|
115
|
-
return context;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
92
|
function contextFromStatement(statement, context) {
|
|
119
93
|
const statementTokens = statement.getTokens(),
|
|
120
94
|
tokens = statementTokens, ///
|
|
121
|
-
|
|
95
|
+
temporaryContext = TemporaryContext.fromContextAndTokens(context, tokens);
|
|
122
96
|
|
|
123
|
-
context =
|
|
97
|
+
context = temporaryContext; ///
|
|
124
98
|
|
|
125
99
|
return context;
|
|
126
100
|
}
|
package/src/utilities/context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ontology from "../ontology";
|
|
4
|
-
import
|
|
4
|
+
import TemporaryContext from "../context/temporary";
|
|
5
5
|
|
|
6
6
|
export function metavariableFromFrame(frame, context) {
|
|
7
7
|
context = contextFromFrame(frame, context); ///
|
|
@@ -106,9 +106,9 @@ export function satisfiesAssertionFromStatement(statement, context) {
|
|
|
106
106
|
function contextFromFrame(frame, context) {
|
|
107
107
|
const frameTokens = frame.getTokens(),
|
|
108
108
|
tokens = frameTokens, ///
|
|
109
|
-
|
|
109
|
+
temporaryContext = TemporaryContext.fromContextAndTokens(context, tokens);
|
|
110
110
|
|
|
111
|
-
context =
|
|
111
|
+
context = temporaryContext; ///
|
|
112
112
|
|
|
113
113
|
return context;
|
|
114
114
|
}
|
|
@@ -116,9 +116,9 @@ function contextFromFrame(frame, context) {
|
|
|
116
116
|
function contextFromStatement(statement, context) {
|
|
117
117
|
const statementTokens = statement.getTokens(),
|
|
118
118
|
tokens = statementTokens, ///
|
|
119
|
-
|
|
119
|
+
temporaryContext = TemporaryContext.fromContextAndTokens(context, tokens);
|
|
120
120
|
|
|
121
|
-
context =
|
|
121
|
+
context = temporaryContext; ///
|
|
122
122
|
|
|
123
123
|
return context;
|
|
124
124
|
}
|
package/src/utilities/json.js
CHANGED
|
@@ -203,6 +203,22 @@ export function labelFromJSON(json, context) {
|
|
|
203
203
|
return label;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
export function framesFromJSON(json, context) {
|
|
207
|
+
let { frames } = json;
|
|
208
|
+
|
|
209
|
+
const { Frame } = ontology,
|
|
210
|
+
framesJSON = frames; ///
|
|
211
|
+
|
|
212
|
+
frames = framesJSON.map((frameJSON) => {
|
|
213
|
+
const json = frameJSON, ///
|
|
214
|
+
frame = Frame.fromJSON(json, context);
|
|
215
|
+
|
|
216
|
+
return frame;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return frames;
|
|
220
|
+
}
|
|
221
|
+
|
|
206
222
|
export function labelsFromJSON(json, context) {
|
|
207
223
|
let { labels } = json;
|
|
208
224
|
|
|
@@ -600,6 +616,18 @@ export function rulesToRulesJSON(rules) {
|
|
|
600
616
|
return rulesJSON;
|
|
601
617
|
}
|
|
602
618
|
|
|
619
|
+
export function framesToFramesJSON(frames) {
|
|
620
|
+
const framesJSON = frames.map((frame) => {
|
|
621
|
+
const frameJSON = frame.toJSON();
|
|
622
|
+
|
|
623
|
+
frame = frameJSON; ///
|
|
624
|
+
|
|
625
|
+
return frame;
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
return framesJSON;
|
|
629
|
+
}
|
|
630
|
+
|
|
603
631
|
export function labelsToLabelsJSON(labels) {
|
|
604
632
|
const labelsJSON = labels.map((label) => {
|
|
605
633
|
const labelJSON = label.toJSON();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { nodeQuery } from "../utilities/query";
|
|
4
|
+
|
|
5
|
+
const metavariableNameNodeQuery = nodeQuery("/metavariable/@name!");
|
|
6
|
+
|
|
7
|
+
export function metavariableNameFromMetavariableNode(metavariableNode) {
|
|
8
|
+
const metavariableNameTerminalNode = metavariableNameNodeQuery(metavariableNode),
|
|
9
|
+
metavariableNameTerminalNodeContent = metavariableNameTerminalNode.getContent(),
|
|
10
|
+
metavariableName = metavariableNameTerminalNodeContent; ///
|
|
11
|
+
|
|
12
|
+
return metavariableName;
|
|
13
|
+
}
|
|
@@ -55,11 +55,9 @@ export function statementFromStatementAndSubstitutions(statement, substitutions,
|
|
|
55
55
|
if (metavariable !== null) {
|
|
56
56
|
let substitution;
|
|
57
57
|
|
|
58
|
-
const { TermSubstitution, FrameSubstitution } = ontology
|
|
59
|
-
termSubstitution = TermSubstitution.fromStatementNode(statementNode, context),
|
|
60
|
-
frameSubstitution = FrameSubstitution.fromStatementNode(statementNode, context);
|
|
58
|
+
const { TermSubstitution, FrameSubstitution } = ontology;
|
|
61
59
|
|
|
62
|
-
substitution = (
|
|
60
|
+
substitution = TermSubstitution.fromStatement(statement, context) || FrameSubstitution.fromStatement(statement, context);
|
|
63
61
|
|
|
64
62
|
substitution = substitutions.findSubstitutionByMetavariableAndSubstitution(metavariable, substitution); ///
|
|
65
63
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use string";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import TemporaryContext from "../context/temporary";
|
|
4
4
|
import metaLevelUnifier from "../unifier/metaLevel";
|
|
5
5
|
import metavariableUnifier from "../unifier/metavariable";
|
|
6
6
|
import intrinsicLevelUnifier from "../unifier/intrinsicLevel";
|
|
@@ -12,14 +12,7 @@ export function unifyStatement(generalStatement, specificStatement, substitution
|
|
|
12
12
|
|
|
13
13
|
const generalStatementNode = generalStatement.getNode(),
|
|
14
14
|
specificStatementNode = specificStatement.getNode(),
|
|
15
|
-
|
|
16
|
-
specificStatementTokens = specificStatement.getTokens();
|
|
17
|
-
|
|
18
|
-
generalContext = contextFromTokens(generalStatementTokens, generalContext); ///
|
|
19
|
-
|
|
20
|
-
specificContext = contextFromTokens(specificStatementTokens, specificContext); ///
|
|
21
|
-
|
|
22
|
-
const generalNonTerminalNode = generalStatementNode, ///
|
|
15
|
+
generalNonTerminalNode = generalStatementNode, ///
|
|
23
16
|
specificNonTerminalNode = specificStatementNode, ///
|
|
24
17
|
unifiesAtMetaLevel = metaLevelUnifier.unify(generalNonTerminalNode, specificNonTerminalNode, substitutions, generalContext, specificContext);
|
|
25
18
|
|
|
@@ -35,14 +28,7 @@ export function unifySubstitution(generalSubstitution, specificSubstitution, sub
|
|
|
35
28
|
|
|
36
29
|
const generalSubstitutionNode = generalSubstitution.getNode(),
|
|
37
30
|
specificSubstitutionNode = specificSubstitution.getNode(),
|
|
38
|
-
|
|
39
|
-
specificSubstitutionTokens = specificSubstitution.getTokens();
|
|
40
|
-
|
|
41
|
-
generalContext = contextFromTokens(generalSubstitutionTokens, generalContext); ///
|
|
42
|
-
|
|
43
|
-
specificContext = contextFromTokens(specificSubstitutionTokens, specificContext); ///
|
|
44
|
-
|
|
45
|
-
const generalNonTerminalNode = generalSubstitutionNode, ///
|
|
31
|
+
generalNonTerminalNode = generalSubstitutionNode, ///
|
|
46
32
|
specificNonTerminalNode = specificSubstitutionNode,
|
|
47
33
|
unifiesAtMetaLevel = metaLevelUnifier.unify(generalNonTerminalNode, specificNonTerminalNode, substitutions, generalContext, specificContext);
|
|
48
34
|
|
|
@@ -106,17 +92,15 @@ export function unifyStatementWithCombinator(statement, combinator, assignments,
|
|
|
106
92
|
let statementUnifiesWithCombinator;
|
|
107
93
|
|
|
108
94
|
const statementNode = statement.getNode(),
|
|
109
|
-
statementTokens = statement.getTokens(),
|
|
110
95
|
combinatorStatement = combinator.getStatement(),
|
|
111
96
|
combinatorStatementNode = combinatorStatement.getNode(),
|
|
112
97
|
combinatorStatementTokens = combinatorStatement.getTokens();
|
|
113
98
|
|
|
114
|
-
|
|
115
|
-
specificContext = context; ///
|
|
99
|
+
const specificContext = context; ///
|
|
116
100
|
|
|
117
|
-
|
|
101
|
+
context = contextFromTokens(combinatorStatementTokens, context); ///
|
|
118
102
|
|
|
119
|
-
|
|
103
|
+
const generalContext = context; ///
|
|
120
104
|
|
|
121
105
|
statementUnifiesWithCombinator = statementWithCombinatorUnifier.unify(combinatorStatementNode, statementNode, assignments, stated, generalContext, specificContext);
|
|
122
106
|
|
|
@@ -144,9 +128,9 @@ export function unifyMetavariableIntrinsically(generalMetavariable, specificMeta
|
|
|
144
128
|
}
|
|
145
129
|
|
|
146
130
|
function contextFromTokens(tokens, context) {
|
|
147
|
-
const
|
|
131
|
+
const temporaryContext = TemporaryContext.fromContextAndTokens(context, tokens);
|
|
148
132
|
|
|
149
|
-
context =
|
|
133
|
+
context = temporaryContext; ///
|
|
150
134
|
|
|
151
135
|
return context;
|
|
152
136
|
}
|