occam-verify-cli 1.0.388 → 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
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ontology from "../../ontology";
|
|
4
|
+
import Assertion from "../assertion";
|
|
4
5
|
import VariableAssignment from "../../assignment/variable";
|
|
5
6
|
|
|
6
7
|
import { define } from "../../ontology";
|
|
7
8
|
|
|
8
|
-
export default define(class TypeAssertion {
|
|
9
|
-
constructor(string, term, type) {
|
|
10
|
-
|
|
9
|
+
export default define(class TypeAssertion extends Assertion {
|
|
10
|
+
constructor(string, node, tokens, term, type) {
|
|
11
|
+
super(string, node, tokens);
|
|
12
|
+
|
|
11
13
|
this.term = term;
|
|
12
14
|
this.type = type;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
getString() {
|
|
16
|
-
return this.string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
17
|
getTerm() {
|
|
20
18
|
return this.term;
|
|
21
19
|
}
|
|
@@ -27,7 +25,7 @@ export default define(class TypeAssertion {
|
|
|
27
25
|
verify(assignments, stated, context) {
|
|
28
26
|
let verifies = false;
|
|
29
27
|
|
|
30
|
-
let typeAssertionString = this.
|
|
28
|
+
let typeAssertionString = this.getString(); ///
|
|
31
29
|
|
|
32
30
|
context.trace(`Verifying the '${typeAssertionString}' type assertion...`);
|
|
33
31
|
|
|
@@ -89,7 +87,7 @@ export default define(class TypeAssertion {
|
|
|
89
87
|
verifyWhenStated(assignments, context) {
|
|
90
88
|
let verifiesWhenStated = false;
|
|
91
89
|
|
|
92
|
-
const typeAssertionString = this.
|
|
90
|
+
const typeAssertionString = this.getString(); ///
|
|
93
91
|
|
|
94
92
|
context.trace(`Verifying the '${typeAssertionString}' stated type assertion...`);
|
|
95
93
|
|
|
@@ -120,7 +118,7 @@ export default define(class TypeAssertion {
|
|
|
120
118
|
verifyWhenDerived(context) {
|
|
121
119
|
let verifiesWhenDerived;
|
|
122
120
|
|
|
123
|
-
const typeAssertionString = this.
|
|
121
|
+
const typeAssertionString = this.getString(); ///
|
|
124
122
|
|
|
125
123
|
context.trace(`Verifying the '${typeAssertionString}' derived type assertion...`);
|
|
126
124
|
|
|
@@ -191,11 +189,12 @@ export default define(class TypeAssertion {
|
|
|
191
189
|
if (typeAssertionNode !== null) {
|
|
192
190
|
const { Term, Type } = ontology,
|
|
193
191
|
node = typeAssertionNode, ///
|
|
192
|
+
tokens = null,
|
|
194
193
|
string = context.nodeAsString(node),
|
|
195
194
|
term = Term.fromTypeAssertionNode(typeAssertionNode, context),
|
|
196
195
|
type = Type.fromTypeAssertionNode(typeAssertionNode, context);
|
|
197
196
|
|
|
198
|
-
typeAssertion = new TypeAssertion(string, term, type);
|
|
197
|
+
typeAssertion = new TypeAssertion(string, node, tokens, term, type);
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
return typeAssertion;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export default class Assertion {
|
|
4
|
+
constructor(string, node, tokens) {
|
|
5
|
+
this.string = string;
|
|
6
|
+
this.node = node;
|
|
7
|
+
this.tokens = tokens;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getString() {
|
|
11
|
+
return this.string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getNode() {
|
|
15
|
+
return this.node;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getTokens() {
|
|
19
|
+
return this.tokens;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
matchAssertionNode(assertionNode) { return this.node.match(assertionNode); }
|
|
23
|
+
}
|
package/src/ontology/axiom.js
CHANGED
|
@@ -82,6 +82,8 @@ export default define(class Axiom extends TopLevelAssertion {
|
|
|
82
82
|
unifyStep(step, substitutions, context) {
|
|
83
83
|
let stepUnifies = false;
|
|
84
84
|
|
|
85
|
+
context = step.getContext();
|
|
86
|
+
|
|
85
87
|
const node = this.getNode(),
|
|
86
88
|
stepString = step.getString(),
|
|
87
89
|
axiomString = this.getString();
|
|
@@ -94,12 +96,7 @@ export default define(class Axiom extends TopLevelAssertion {
|
|
|
94
96
|
context.trace(`Cannot unify the '${stepString}' step with the '${axiomString}' axiom because the axiom is not unconditional.`, node);
|
|
95
97
|
} else {
|
|
96
98
|
const statement = step.getStatement(),
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
context = this.getContext();
|
|
100
|
-
|
|
101
|
-
const generalContext = context, ///
|
|
102
|
-
statementUnifiesWithDeduction = this.unifyStatementWithDeduction(statement, substitutions, generalContext, specificContext);
|
|
99
|
+
statementUnifiesWithDeduction = this.unifyStatementWithDeduction(statement, substitutions, context);
|
|
103
100
|
|
|
104
101
|
if (statementUnifiesWithDeduction) {
|
|
105
102
|
stepUnifies = true;
|
|
@@ -113,18 +110,17 @@ export default define(class Axiom extends TopLevelAssertion {
|
|
|
113
110
|
return stepUnifies;
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
unifyLastStep(lastStep, substitutions,
|
|
113
|
+
unifyLastStep(lastStep, substitutions, context) {
|
|
117
114
|
let lastStepUnifies = false;
|
|
118
115
|
|
|
119
116
|
const node = this.getNode(),
|
|
120
|
-
context = specificContext, ///
|
|
121
117
|
axiomString = this.getString(),
|
|
122
118
|
lastStepString = lastStep.getString();
|
|
123
119
|
|
|
124
120
|
context.trace(`Unifying the '${lastStepString}' last step with the '${axiomString}' axiom...`, node)
|
|
125
121
|
|
|
126
122
|
const statement = lastStep.getStatement(),
|
|
127
|
-
statementUnifiesWithDeduction = this.unifyStatementWithDeduction(statement, substitutions,
|
|
123
|
+
statementUnifiesWithDeduction = this.unifyStatementWithDeduction(statement, substitutions, context);
|
|
128
124
|
|
|
129
125
|
if (statementUnifiesWithDeduction) {
|
|
130
126
|
lastStepUnifies = true;
|
|
@@ -152,16 +148,11 @@ export default define(class Axiom extends TopLevelAssertion {
|
|
|
152
148
|
context.trace(`Cannot unify the '${subproofString}' subproof with the '${axiomString}' axiom because the axiom is unconditional.`, node);
|
|
153
149
|
} else {
|
|
154
150
|
const lastStep = subproof.getLastStep(),
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
context = this.getContext();
|
|
158
|
-
|
|
159
|
-
const generalContext = context, ///
|
|
160
|
-
lastStepUnifies = this.unifyLastStep(lastStep, substitutions, generalContext, specificContext);
|
|
151
|
+
lastStepUnifies = this.unifyLastStep(lastStep, substitutions, context);
|
|
161
152
|
|
|
162
153
|
if (lastStepUnifies) {
|
|
163
154
|
const suppositions = subproof.getSuppositions(),
|
|
164
|
-
suppositionsUnify = this.unifySuppositions(suppositions, substitutions,
|
|
155
|
+
suppositionsUnify = this.unifySuppositions(suppositions, substitutions, context);
|
|
165
156
|
|
|
166
157
|
if (suppositionsUnify) {
|
|
167
158
|
subproofUnifies = true;
|
|
@@ -23,6 +23,8 @@ export default define(class BracketedCombinator extends Combinator {
|
|
|
23
23
|
return statementUnifies;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
static name = "BracketedCombinator";
|
|
27
|
+
|
|
26
28
|
static fromNothing() {
|
|
27
29
|
const { Statement } = ontology,
|
|
28
30
|
bracketedStatementNode = combinatorBracketedContext.getBracketedStatementNode(),
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ontology from "../ontology";
|
|
4
|
+
import TemporaryContext from "../context/temporary";
|
|
4
5
|
|
|
5
6
|
import { define } from "../ontology";
|
|
6
|
-
import { statementFromJSON, statementToStatementJSON } from "../utilities/json";
|
|
7
|
+
import { termsFromJSON, framesFromJSON, statementFromJSON, termsToTermsJSON, framesToFramesJSON, statementToStatementJSON } from "../utilities/json";
|
|
7
8
|
|
|
8
9
|
export default define(class Conclusion {
|
|
9
|
-
constructor(node, string, statement) {
|
|
10
|
+
constructor(context, node, string, statement) {
|
|
11
|
+
this.context = context;
|
|
10
12
|
this.node = node;
|
|
11
13
|
this.string = string;
|
|
12
14
|
this.statement = statement;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
getContext() {
|
|
18
|
+
return this.context;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
getNode() {
|
|
16
22
|
return this.node;
|
|
17
23
|
}
|
|
@@ -27,6 +33,10 @@ export default define(class Conclusion {
|
|
|
27
33
|
verify(context) {
|
|
28
34
|
let verifies = false;
|
|
29
35
|
|
|
36
|
+
const temporaryContext = TemporaryContext.fromNothing(context);
|
|
37
|
+
|
|
38
|
+
context = temporaryContext; ///
|
|
39
|
+
|
|
30
40
|
const conclusionString = this.string; ///
|
|
31
41
|
|
|
32
42
|
context.trace(`Verifying the '${conclusionString}' conclusion...`, this.node);
|
|
@@ -43,35 +53,56 @@ export default define(class Conclusion {
|
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
if (verifies) {
|
|
56
|
+
this.context = context;
|
|
57
|
+
|
|
46
58
|
context.debug(`...verified the '${conclusionString}' conclusion.`, this.node);
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
return verifies;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
|
-
unifyStatement(statement, substitutions,
|
|
64
|
+
unifyStatement(statement, substitutions, context) {
|
|
53
65
|
let statementUnifies;
|
|
54
66
|
|
|
55
67
|
const conclusion = this, ///
|
|
56
68
|
statementString = statement.getString(),
|
|
57
69
|
conclusionString = conclusion.getString();
|
|
58
70
|
|
|
59
|
-
|
|
71
|
+
context.trace(`Unifying the '${statementString}' statement with the '${conclusionString}' conclusion...`);
|
|
72
|
+
|
|
73
|
+
const generalContext = this.context, ///
|
|
74
|
+
specificContext = context; ///
|
|
60
75
|
|
|
61
76
|
statementUnifies = this.statement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
62
77
|
|
|
63
78
|
if (statementUnifies) {
|
|
64
|
-
|
|
79
|
+
context.debug(`...unified the '${statementString}' statement with the '${conclusionString}' conclusion.`);
|
|
65
80
|
}
|
|
66
81
|
|
|
67
82
|
return statementUnifies;
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
toJSON() {
|
|
86
|
+
let frames,
|
|
87
|
+
terms;
|
|
88
|
+
|
|
89
|
+
frames = this.context.getFrames();
|
|
90
|
+
|
|
91
|
+
terms = this.context.getTerms();
|
|
92
|
+
|
|
71
93
|
const statementJSON = statementToStatementJSON(this.statement),
|
|
72
|
-
|
|
94
|
+
framesJSON = framesToFramesJSON(frames),
|
|
95
|
+
termsJSON = termsToTermsJSON(terms);
|
|
96
|
+
|
|
97
|
+
frames = framesJSON; ///
|
|
98
|
+
|
|
99
|
+
terms = termsJSON; ///
|
|
100
|
+
|
|
101
|
+
const statement = statementJSON, ///
|
|
73
102
|
json = {
|
|
74
|
-
statement
|
|
103
|
+
statement,
|
|
104
|
+
frames,
|
|
105
|
+
terms
|
|
75
106
|
};
|
|
76
107
|
|
|
77
108
|
return json;
|
|
@@ -80,10 +111,16 @@ export default define(class Conclusion {
|
|
|
80
111
|
static name = "Conclusion";
|
|
81
112
|
|
|
82
113
|
static fromJSON(json, context) {
|
|
83
|
-
const
|
|
114
|
+
const terms = termsFromJSON(json, context),
|
|
115
|
+
frames = framesFromJSON(json, context),
|
|
116
|
+
statement = statementFromJSON(json, context),
|
|
84
117
|
node = null,
|
|
85
118
|
string = statement.getString(),
|
|
86
|
-
|
|
119
|
+
temporaryContext = TemporaryContext.fromTermsAndFrames(terms, frames, context);
|
|
120
|
+
|
|
121
|
+
context = temporaryContext; ///
|
|
122
|
+
|
|
123
|
+
const conclusion = new Conclusion(context, node, string, statement);
|
|
87
124
|
|
|
88
125
|
return conclusion;
|
|
89
126
|
}
|
|
@@ -93,7 +130,11 @@ export default define(class Conclusion {
|
|
|
93
130
|
node = conclusionNode, ///
|
|
94
131
|
string = context.nodeAsString(node),
|
|
95
132
|
statement = Statement.fromConclusionNode(conclusionNode, context),
|
|
96
|
-
|
|
133
|
+
temporaryContext = null;
|
|
134
|
+
|
|
135
|
+
context = temporaryContext; ///
|
|
136
|
+
|
|
137
|
+
const conclusion = new Conclusion(context, node, string, statement);
|
|
97
138
|
|
|
98
139
|
return conclusion;
|
|
99
140
|
}
|
|
@@ -52,6 +52,8 @@ export default define(class BracketedConstructor extends Constructor {
|
|
|
52
52
|
return termUnifies;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
static name = "BracketedConstructor";
|
|
56
|
+
|
|
55
57
|
static fromNothing() {
|
|
56
58
|
const { Term } = ontology,
|
|
57
59
|
bracketedTermNode = constructorBracketedContext.getBracketedTermNode(),
|
|
@@ -5,6 +5,7 @@ import Substitutions from "../substitutions";
|
|
|
5
5
|
|
|
6
6
|
import { define } from "../ontology";
|
|
7
7
|
import { unifyStatementIntrinsically } from "../utilities/unification";
|
|
8
|
+
import { metavariableFromJSON, metavariableToMetavariableJSON } from "../utilities/json";
|
|
8
9
|
|
|
9
10
|
export default define(class Declaration {
|
|
10
11
|
constructor(string, node, statement, metavariable) {
|
|
@@ -310,14 +311,46 @@ export default define(class Declaration {
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
if (metaLemmaMetatheoremUnifies) {
|
|
314
|
+
context = generalContext; ///
|
|
315
|
+
|
|
313
316
|
context.trace(`...unified the '${metaLemmaMetatheoremString}' meta-lemma or metatheorem with the '${declarationString}' declaration...`);
|
|
314
317
|
}
|
|
315
318
|
|
|
316
319
|
return metaLemmaMetatheoremUnifies;
|
|
317
320
|
}
|
|
318
321
|
|
|
322
|
+
toJSON() {
|
|
323
|
+
let json = null;
|
|
324
|
+
|
|
325
|
+
const simple = this.isSimple();
|
|
326
|
+
|
|
327
|
+
if (simple) {
|
|
328
|
+
const metavariable = this.getMetavariable(),
|
|
329
|
+
metavariableJSON = metavariableToMetavariableJSON(metavariable);
|
|
330
|
+
|
|
331
|
+
json = metavariableJSON; ///
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return json;
|
|
335
|
+
}
|
|
336
|
+
|
|
319
337
|
static name = "Declaration";
|
|
320
338
|
|
|
339
|
+
static fromJSON(json, context) {
|
|
340
|
+
let declaration = null;
|
|
341
|
+
|
|
342
|
+
if (json !== null) {
|
|
343
|
+
const string = null,
|
|
344
|
+
node = null,
|
|
345
|
+
statement = null,
|
|
346
|
+
metavariable = metavariableFromJSON(json, context);
|
|
347
|
+
|
|
348
|
+
declaration = new Declaration(string, node, statement, metavariable)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return declaration;
|
|
352
|
+
}
|
|
353
|
+
|
|
321
354
|
static fromJudgementNode(judgementNode, context) {
|
|
322
355
|
const declarationNode = judgementNode.getDeclarationNode(),
|
|
323
356
|
declaration = declarationFromDeclarationNode(declarationNode, context);
|
|
@@ -344,8 +377,8 @@ function declarationFromDeclarationNode(declarationNode, context) {
|
|
|
344
377
|
const { Metavariable, Declaration, Statement } = ontology,
|
|
345
378
|
node = declarationNode, ///
|
|
346
379
|
string = context.nodeAsString(node),
|
|
347
|
-
metavariable = Metavariable.fromDeclarationNode(declarationNode, context),
|
|
348
380
|
statement = Statement.fromDeclarationNode(declarationNode, context),
|
|
381
|
+
metavariable = Metavariable.fromDeclarationNode(declarationNode, context),
|
|
349
382
|
declaration = new Declaration(string, node, statement, metavariable);
|
|
350
383
|
|
|
351
384
|
return declaration;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import ontology from "../ontology";
|
|
4
|
+
import TemporaryContext from "../context/temporary";
|
|
4
5
|
|
|
5
6
|
import { define } from "../ontology";
|
|
6
|
-
import { statementFromJSON, statementToStatementJSON } from "../utilities/json";
|
|
7
|
+
import { termsFromJSON, framesFromJSON, statementFromJSON, termsToTermsJSON, framesToFramesJSON, statementToStatementJSON } from "../utilities/json";
|
|
7
8
|
|
|
8
9
|
export default define(class Deduction {
|
|
9
|
-
constructor(node, string, statement) {
|
|
10
|
+
constructor(context, node, string, statement) {
|
|
11
|
+
this.context = context;
|
|
10
12
|
this.node = node;
|
|
11
13
|
this.string = string;
|
|
12
14
|
this.statement = statement;
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
getContext() {
|
|
18
|
+
return this.context;
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
getNode(node) {
|
|
16
22
|
return this.node;
|
|
17
23
|
}
|
|
@@ -27,6 +33,10 @@ export default define(class Deduction {
|
|
|
27
33
|
verify(context) {
|
|
28
34
|
let verifies = false;
|
|
29
35
|
|
|
36
|
+
const temporaryContext = TemporaryContext.fromNothing(context);
|
|
37
|
+
|
|
38
|
+
context = temporaryContext; ///
|
|
39
|
+
|
|
30
40
|
const deductionString = this.string; ///
|
|
31
41
|
|
|
32
42
|
context.trace(`Verifying the '${deductionString}' deduction...`, this.node);
|
|
@@ -42,25 +52,30 @@ export default define(class Deduction {
|
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
if (verifies) {
|
|
55
|
+
this.context = context;
|
|
56
|
+
|
|
45
57
|
context.debug(`...verified the '${deductionString}' deduction.`, this.node);
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
return verifies;
|
|
49
61
|
}
|
|
50
62
|
|
|
51
|
-
unifyStatement(statement, substitutions,
|
|
63
|
+
unifyStatement(statement, substitutions, context) {
|
|
52
64
|
let statementUnifies;
|
|
53
65
|
|
|
54
66
|
const deduction = this, ///
|
|
55
67
|
statementString = statement.getString(),
|
|
56
68
|
deductionString = deduction.getString();
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
context.trace(`Unifying the '${statementString}' statement with the '${deductionString}' deduction...`);
|
|
71
|
+
|
|
72
|
+
const generalContext = this.context, ///
|
|
73
|
+
specificContext = context; ///
|
|
59
74
|
|
|
60
75
|
statementUnifies = this.statement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
61
76
|
|
|
62
77
|
if (statementUnifies) {
|
|
63
|
-
|
|
78
|
+
context.debug(`...unified the '${statementString}' statement with the '${deductionString}' deduction.`);
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
return statementUnifies;
|
|
@@ -89,10 +104,26 @@ export default define(class Deduction {
|
|
|
89
104
|
}
|
|
90
105
|
|
|
91
106
|
toJSON() {
|
|
107
|
+
let frames,
|
|
108
|
+
terms;
|
|
109
|
+
|
|
110
|
+
frames = this.context.getFrames();
|
|
111
|
+
|
|
112
|
+
terms = this.context.getTerms();
|
|
113
|
+
|
|
92
114
|
const statementJSON = statementToStatementJSON(this.statement),
|
|
93
|
-
|
|
115
|
+
framesJSON = framesToFramesJSON(frames),
|
|
116
|
+
termsJSON = termsToTermsJSON(terms);
|
|
117
|
+
|
|
118
|
+
frames = framesJSON; ///
|
|
119
|
+
|
|
120
|
+
terms = termsJSON; ///
|
|
121
|
+
|
|
122
|
+
const statement = statementJSON, ///
|
|
94
123
|
json = {
|
|
95
|
-
statement
|
|
124
|
+
statement,
|
|
125
|
+
frames,
|
|
126
|
+
terms
|
|
96
127
|
};
|
|
97
128
|
|
|
98
129
|
return json;
|
|
@@ -101,10 +132,16 @@ export default define(class Deduction {
|
|
|
101
132
|
static name = "Deduction";
|
|
102
133
|
|
|
103
134
|
static fromJSON(json, context) {
|
|
104
|
-
const
|
|
135
|
+
const terms = termsFromJSON(json, context),
|
|
136
|
+
frames = framesFromJSON(json, context),
|
|
137
|
+
statement = statementFromJSON(json, context),
|
|
105
138
|
node = null,
|
|
106
139
|
string = statement.getString(),
|
|
107
|
-
|
|
140
|
+
temporaryContext = TemporaryContext.fromTermsAndFrames(terms, frames, context);
|
|
141
|
+
|
|
142
|
+
context = temporaryContext; ///
|
|
143
|
+
|
|
144
|
+
const deduction = new Deduction(context, node, string, statement);
|
|
108
145
|
|
|
109
146
|
return deduction;
|
|
110
147
|
}
|
|
@@ -114,7 +151,11 @@ export default define(class Deduction {
|
|
|
114
151
|
node = deductionNode, ///
|
|
115
152
|
string = context.nodeAsString(node),
|
|
116
153
|
statement = Statement.fromDeductionNode(deductionNode, context),
|
|
117
|
-
|
|
154
|
+
temporaryContext = null;
|
|
155
|
+
|
|
156
|
+
context = temporaryContext; ///
|
|
157
|
+
|
|
158
|
+
const deduction = new Deduction(context, node, string, statement);
|
|
118
159
|
|
|
119
160
|
return deduction;
|
|
120
161
|
}
|
package/src/ontology/frame.js
CHANGED
|
@@ -36,14 +36,27 @@ export default define(class Frame {
|
|
|
36
36
|
|
|
37
37
|
getLength() { return this.declarations.length; }
|
|
38
38
|
|
|
39
|
+
getDeclaration() {
|
|
40
|
+
let declaration = null;
|
|
41
|
+
|
|
42
|
+
const length = this.getLength();
|
|
43
|
+
|
|
44
|
+
if (length === 1) {
|
|
45
|
+
const firstDeclaration = first(this.declarations);
|
|
46
|
+
|
|
47
|
+
declaration = firstDeclaration; ///
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return declaration;
|
|
51
|
+
}
|
|
52
|
+
|
|
39
53
|
getMetavariable() {
|
|
40
54
|
let metavariable = null;
|
|
41
55
|
|
|
42
56
|
const simple = this.isSimple();
|
|
43
57
|
|
|
44
58
|
if (simple) {
|
|
45
|
-
const
|
|
46
|
-
declaration = firstDeclaration; ///
|
|
59
|
+
const declaration = this.getDeclaration();
|
|
47
60
|
|
|
48
61
|
metavariable = declaration.getMetavariable();
|
|
49
62
|
}
|
|
@@ -54,12 +67,9 @@ export default define(class Frame {
|
|
|
54
67
|
isSimple() {
|
|
55
68
|
let simple = false;
|
|
56
69
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
if (length === 1) {
|
|
60
|
-
const firstDeclaration = first(this.declarations),
|
|
61
|
-
declaration = firstDeclaration; ///
|
|
70
|
+
const declaration = this.getDeclaration();
|
|
62
71
|
|
|
72
|
+
if (declaration !== null) {
|
|
63
73
|
simple = declaration.isSimple();
|
|
64
74
|
}
|
|
65
75
|
|
|
@@ -73,6 +83,8 @@ export default define(class Frame {
|
|
|
73
83
|
return equalTo;
|
|
74
84
|
}
|
|
75
85
|
|
|
86
|
+
matchFrameNode(frameNode) { return this.node.match(frameNode); }
|
|
87
|
+
|
|
76
88
|
matchSubstitution(substitution, context) {
|
|
77
89
|
let substitutionMatches = false;
|
|
78
90
|
|
|
@@ -146,6 +158,10 @@ export default define(class Frame {
|
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
if (verifies) {
|
|
161
|
+
const frame = this; ///
|
|
162
|
+
|
|
163
|
+
context.addFrame(frame);
|
|
164
|
+
|
|
149
165
|
context.debug(`...verified the '${frameString}' frame.`);
|
|
150
166
|
}
|
|
151
167
|
|
|
@@ -244,8 +260,42 @@ export default define(class Frame {
|
|
|
244
260
|
return verifiesGivenMetaType;
|
|
245
261
|
}
|
|
246
262
|
|
|
263
|
+
toJSON() {
|
|
264
|
+
let json = null;
|
|
265
|
+
|
|
266
|
+
const simple = this.isSimple();
|
|
267
|
+
|
|
268
|
+
if (simple) {
|
|
269
|
+
const declaration = this.getDeclaration(),
|
|
270
|
+
declarationJSON = declaration.toJSON();
|
|
271
|
+
|
|
272
|
+
json = declarationJSON; ///
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return json;
|
|
276
|
+
}
|
|
277
|
+
|
|
247
278
|
static name = "Frame";
|
|
248
279
|
|
|
280
|
+
static fromJSON(json, context) {
|
|
281
|
+
let frame = null;
|
|
282
|
+
|
|
283
|
+
if (json !== null) {
|
|
284
|
+
const { Declaration } =ontology,
|
|
285
|
+
declaration = Declaration.fromJSON(json, context),
|
|
286
|
+
declarations = [
|
|
287
|
+
declaration
|
|
288
|
+
],
|
|
289
|
+
string = null,
|
|
290
|
+
node = null,
|
|
291
|
+
tokens = null;
|
|
292
|
+
|
|
293
|
+
frame = new Frame(string, node, tokens, declarations);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return frame;
|
|
297
|
+
}
|
|
298
|
+
|
|
249
299
|
static fromFrameNode(frameNode, context) {
|
|
250
300
|
let frame = null;
|
|
251
301
|
|
|
@@ -294,8 +344,7 @@ function frameFromFrameNode(frameNode, context) {
|
|
|
294
344
|
string = context.nodeAsString(node),
|
|
295
345
|
tokens = context.nodeAsTokens(node),
|
|
296
346
|
declarations = declarationsFromFrameNode(frameNode, context),
|
|
297
|
-
|
|
298
|
-
frame = new Frame(string, node, tokens, declarations, metavariables);
|
|
347
|
+
frame = new Frame(string, node, tokens, declarations);
|
|
299
348
|
|
|
300
349
|
return frame;
|
|
301
350
|
}
|
|
@@ -312,18 +361,6 @@ function declarationsFromFrameNode(frameNode, context) {
|
|
|
312
361
|
return declarations;
|
|
313
362
|
}
|
|
314
363
|
|
|
315
|
-
function metavariablesFromFrameNode(frameNode, context) {
|
|
316
|
-
const { Metavariable } = ontology,
|
|
317
|
-
metavariableNodes = frameNode.getMetavariableNodes(),
|
|
318
|
-
metavariables = metavariableNodes.map((metavariableNode) => {
|
|
319
|
-
const metavariable = Metavariable.fromMetavariableNode(metavariableNode, context);
|
|
320
|
-
|
|
321
|
-
return metavariable;
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
return metavariables;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
364
|
function declarationsStringFromDeclarations(declarations) {
|
|
328
365
|
const declarationsString = declarations.reduce((declarationsString, declaration) => {
|
|
329
366
|
const declarationString = declaration.getString();
|