occam-verify-cli 1.0.388 → 1.0.404
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/assignment/equality.js +2 -2
- package/lib/context/file.js +11 -11
- package/lib/context/local.js +38 -61
- package/lib/context/partial.js +10 -10
- package/lib/context/temporary.js +755 -0
- package/lib/mixins/statement/verify.js +38 -16
- package/lib/mixins/step/unify.js +7 -8
- package/lib/node/argument.js +4 -4
- package/lib/node/assertion/contained.js +6 -6
- package/lib/node/assertion/defined.js +6 -6
- package/lib/node/assertion/property.js +6 -6
- package/lib/node/assertion/satisfies.js +6 -6
- package/lib/node/assertion/subproof.js +6 -6
- package/lib/node/assertion/type.js +6 -6
- package/lib/node/assertion.js +107 -0
- package/lib/node/assumption.js +134 -0
- package/lib/node/axiom.js +6 -6
- package/lib/node/{topLevelAssertion.js → axiomLemmaTheoremConjecture.js} +12 -12
- package/lib/node/body.js +4 -5
- package/lib/node/combinator.js +4 -4
- package/lib/node/conclusion.js +4 -4
- package/lib/node/conjecture.js +6 -6
- package/lib/node/constructor.js +4 -4
- package/lib/node/declaration/combinator.js +6 -6
- package/lib/node/declaration/complexType.js +6 -6
- package/lib/node/declaration/constructor.js +6 -6
- package/lib/node/declaration/metavariable.js +6 -6
- package/lib/node/declaration/property.js +6 -6
- package/lib/node/declaration/simpleType.js +6 -6
- package/lib/node/declaration/typePrefix.js +6 -6
- package/lib/node/declaration/variable.js +6 -6
- package/lib/node/declaration.js +6 -22
- package/lib/node/deduction.js +4 -4
- package/lib/node/derivation.js +4 -4
- package/lib/node/document.js +107 -0
- package/lib/node/equality.js +4 -4
- package/lib/node/error.js +4 -4
- package/lib/node/frame.js +25 -14
- package/lib/node/header.js +4 -4
- package/lib/node/hypothesis.js +4 -4
- package/lib/node/judgement.js +8 -8
- package/lib/node/label.js +4 -4
- package/lib/node/labels.js +4 -4
- package/lib/node/lemma.js +6 -6
- package/lib/node/metaArgument.js +4 -4
- package/lib/node/metaLemma.js +6 -6
- package/lib/node/{topLevelMetaAssertion.js → metaLemmaMetaTheorem.js} +12 -12
- package/lib/node/metaType.js +4 -4
- package/lib/node/metatheorem.js +6 -6
- package/lib/node/metavariable.js +4 -4
- package/lib/node/nonsense.js +4 -4
- package/lib/node/parameter.js +4 -4
- package/lib/node/parenthesisedLabel.js +4 -4
- package/lib/node/parenthesisedLabels.js +4 -4
- package/lib/node/placeholder.js +107 -0
- package/lib/node/premise.js +4 -4
- package/lib/node/procedureCall.js +4 -4
- package/lib/node/procedureReference.js +4 -4
- package/lib/node/proof.js +4 -4
- package/lib/node/property.js +4 -4
- package/lib/node/propertyRelation.js +4 -4
- package/lib/node/qualification.js +4 -4
- package/lib/node/reference.js +4 -4
- package/lib/node/rule.js +4 -4
- package/lib/node/section.js +4 -4
- package/lib/node/signature.js +4 -4
- package/lib/node/statement.js +15 -4
- package/lib/node/step.js +4 -4
- package/lib/node/subDerivation.js +4 -4
- package/lib/node/subproof.js +4 -4
- package/lib/node/substitution/frame.js +28 -6
- package/lib/node/substitution/statement.js +6 -6
- package/lib/node/substitution/term.js +28 -6
- package/lib/node/substitution.js +107 -0
- package/lib/node/supposition.js +4 -4
- package/lib/node/term.js +27 -4
- package/lib/node/theorem.js +6 -6
- package/lib/node/type.js +4 -4
- package/lib/node/typePrefix.js +4 -4
- package/lib/node/types.js +4 -4
- package/lib/node/variable.js +4 -4
- package/lib/nominal/parser.js +3 -3
- package/lib/nonTerminalNode.js +222 -0
- package/lib/nonTerminalNodeMap.js +5 -3
- package/lib/ontology/assertion/contained.js +80 -39
- package/lib/ontology/assertion/defined.js +80 -39
- package/lib/ontology/assertion/property.js +71 -29
- package/lib/ontology/assertion/satisfies.js +73 -25
- 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/assumption.js +379 -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/combinator.js +75 -33
- package/lib/ontology/declaration/complexType.js +110 -63
- package/lib/ontology/declaration/constructor.js +81 -38
- package/lib/ontology/declaration/metavariable.js +87 -39
- package/lib/ontology/declaration/simpleType.js +95 -48
- package/lib/ontology/declaration/typePrefix.js +87 -40
- package/lib/ontology/declaration/variable.js +87 -39
- package/lib/ontology/declaration.js +13 -313
- package/lib/ontology/deduction.js +38 -9
- package/lib/ontology/equivalence.js +295 -0
- package/lib/ontology/equivalences.js +264 -0
- package/lib/ontology/frame.js +83 -51
- package/lib/ontology/hypothesis.js +11 -11
- package/lib/ontology/judgement.js +8 -8
- package/lib/ontology/label.js +5 -6
- package/lib/ontology/metavariable.js +14 -15
- package/lib/ontology/premise.js +60 -21
- 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 +6 -13
- package/lib/ontology/rule.js +69 -71
- package/lib/ontology/section.js +2 -2
- package/lib/ontology/signature.js +2 -2
- package/lib/ontology/statement.js +36 -24
- package/lib/ontology/step.js +38 -26
- package/lib/ontology/subproof.js +12 -13
- package/lib/ontology/substitution/frame.js +69 -21
- package/lib/ontology/substitution/reference.js +24 -9
- package/lib/ontology/substitution/statement.js +137 -76
- package/lib/ontology/substitution/term.js +75 -35
- package/lib/ontology/substitution.js +50 -44
- package/lib/ontology/substitutions.js +425 -0
- package/lib/ontology/supposition.js +69 -29
- package/lib/ontology/term.js +35 -37
- package/lib/ontology/topLevelAssertion.js +16 -17
- package/lib/ontology/topLevelMetaAssertion.js +3 -4
- package/lib/ontology/variable.js +9 -14
- package/lib/preamble.js +7 -4
- package/lib/ruleNames.js +20 -12
- package/lib/unifier/intrinsicLevel.js +4 -5
- package/lib/unifier/metaLevel.js +24 -24
- package/lib/utilities/brackets.js +4 -21
- package/lib/utilities/context.js +6 -6
- package/lib/utilities/frame.js +18 -0
- package/lib/utilities/json.js +24 -1
- package/lib/utilities/metavariable.js +18 -0
- package/lib/utilities/statement.js +18 -0
- package/lib/utilities/substitutions.js +43 -30
- package/lib/utilities/unification.js +10 -16
- package/lib/utilities/variable.js +18 -0
- package/package.json +10 -10
- package/src/action/verify.js +2 -2
- package/src/assignment/equality.js +1 -1
- package/src/context/file.js +13 -11
- package/src/context/local.js +40 -65
- package/src/context/partial.js +9 -14
- package/src/context/temporary.js +463 -0
- package/src/mixins/statement/verify.js +60 -23
- package/src/mixins/step/unify.js +6 -6
- package/src/node/argument.js +1 -1
- package/src/node/assertion/contained.js +3 -3
- package/src/node/assertion/defined.js +3 -3
- package/src/node/assertion/property.js +3 -3
- package/src/node/assertion/satisfies.js +3 -3
- package/src/node/assertion/subproof.js +3 -3
- package/src/node/assertion/type.js +3 -3
- package/src/node/assertion.js +7 -0
- package/src/node/assumption.js +35 -0
- package/src/node/axiom.js +3 -3
- package/src/node/{topLevelAssertion.js → axiomLemmaTheoremConjecture.js} +2 -2
- package/src/node/body.js +1 -3
- package/src/node/combinator.js +1 -1
- package/src/node/conclusion.js +1 -1
- package/src/node/conjecture.js +3 -3
- package/src/node/constructor.js +1 -1
- package/src/node/declaration/combinator.js +3 -3
- package/src/node/declaration/complexType.js +3 -3
- package/src/node/declaration/constructor.js +3 -3
- package/src/node/declaration/metavariable.js +3 -3
- package/src/node/declaration/property.js +3 -3
- package/src/node/declaration/simpleType.js +3 -3
- package/src/node/declaration/typePrefix.js +3 -3
- package/src/node/declaration/variable.js +3 -3
- package/src/node/declaration.js +2 -18
- package/src/node/deduction.js +1 -1
- package/src/node/derivation.js +1 -1
- package/src/node/document.js +7 -0
- package/src/node/equality.js +1 -1
- package/src/node/error.js +1 -1
- package/src/node/frame.js +23 -11
- package/src/node/header.js +1 -1
- package/src/node/hypothesis.js +1 -1
- package/src/node/judgement.js +6 -6
- package/src/node/label.js +1 -1
- package/src/node/labels.js +1 -1
- package/src/node/lemma.js +3 -3
- package/src/node/metaArgument.js +1 -1
- package/src/node/metaLemma.js +3 -3
- package/src/node/{topLevelMetaAssertion.js → metaLemmaMetaTheorem.js} +2 -2
- package/src/node/metaType.js +1 -1
- package/src/node/metatheorem.js +3 -3
- package/src/node/metavariable.js +1 -1
- package/src/node/nonsense.js +1 -1
- package/src/node/parameter.js +1 -1
- package/src/node/parenthesisedLabel.js +1 -1
- package/src/node/parenthesisedLabels.js +1 -1
- package/src/node/placeholder.js +7 -0
- package/src/node/premise.js +1 -1
- package/src/node/procedureCall.js +1 -1
- package/src/node/procedureReference.js +1 -1
- package/src/node/proof.js +1 -1
- package/src/node/property.js +1 -1
- package/src/node/propertyRelation.js +1 -1
- package/src/node/qualification.js +1 -1
- package/src/node/reference.js +1 -1
- package/src/node/rule.js +2 -2
- package/src/node/section.js +1 -1
- package/src/node/signature.js +1 -1
- package/src/node/statement.js +13 -1
- package/src/node/step.js +1 -1
- package/src/node/subDerivation.js +1 -1
- package/src/node/subproof.js +1 -1
- package/src/node/substitution/frame.js +29 -3
- package/src/node/substitution/statement.js +3 -3
- package/src/node/substitution/term.js +29 -3
- package/src/node/substitution.js +7 -0
- package/src/node/supposition.js +1 -1
- package/src/node/term.js +27 -1
- package/src/node/theorem.js +3 -3
- package/src/node/type.js +1 -1
- package/src/node/typePrefix.js +1 -1
- package/src/node/types.js +1 -1
- package/src/node/variable.js +1 -1
- package/src/nominal/parser.js +2 -2
- package/src/{node/nonTerminal.js → nonTerminalNode.js} +31 -25
- package/src/nonTerminalNodeMap.js +10 -5
- package/src/ontology/assertion/contained.js +21 -32
- package/src/ontology/assertion/defined.js +20 -31
- package/src/ontology/assertion/property.js +7 -20
- package/src/ontology/assertion/satisfies.js +8 -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/assumption.js +385 -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/combinator.js +15 -24
- package/src/ontology/declaration/complexType.js +57 -53
- package/src/ontology/declaration/constructor.js +25 -31
- package/src/ontology/declaration/metavariable.js +25 -30
- package/src/ontology/declaration/simpleType.js +34 -38
- package/src/ontology/declaration/typePrefix.js +23 -31
- package/src/ontology/declaration/variable.js +26 -31
- package/src/ontology/declaration.js +8 -339
- package/src/ontology/deduction.js +51 -10
- package/src/{equivalence.js → ontology/equivalence.js} +4 -3
- package/src/{equivalences.js → ontology/equivalences.js} +14 -12
- package/src/ontology/frame.js +93 -66
- package/src/ontology/hypothesis.js +8 -8
- package/src/ontology/judgement.js +8 -8
- package/src/ontology/label.js +2 -7
- package/src/ontology/metavariable.js +14 -17
- package/src/ontology/premise.js +82 -25
- 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 +5 -9
- package/src/ontology/rule.js +79 -82
- package/src/ontology/section.js +1 -1
- package/src/ontology/signature.js +1 -1
- package/src/ontology/statement.js +37 -27
- package/src/ontology/step.js +45 -28
- package/src/ontology/subproof.js +10 -10
- package/src/ontology/substitution/frame.js +72 -26
- package/src/ontology/substitution/reference.js +8 -6
- package/src/ontology/substitution/statement.js +95 -76
- package/src/ontology/substitution/term.js +81 -41
- package/src/ontology/substitution.js +35 -34
- package/src/{substitutions.js → ontology/substitutions.js} +29 -28
- package/src/ontology/supposition.js +88 -28
- package/src/ontology/term.js +31 -43
- package/src/ontology/topLevelAssertion.js +16 -18
- package/src/ontology/topLevelMetaAssertion.js +3 -3
- package/src/ontology/variable.js +10 -17
- package/src/preamble.js +6 -3
- package/src/ruleNames.js +10 -8
- package/src/unifier/intrinsicLevel.js +5 -6
- package/src/unifier/metaLevel.js +32 -29
- package/src/utilities/brackets.js +3 -29
- package/src/utilities/context.js +5 -5
- package/src/utilities/frame.js +13 -0
- package/src/utilities/json.js +28 -0
- package/src/utilities/metavariable.js +13 -0
- package/src/utilities/statement.js +13 -0
- package/src/utilities/substitutions.js +59 -33
- package/src/utilities/unification.js +8 -24
- package/src/utilities/variable.js +13 -0
- package/lib/equivalence.js +0 -294
- package/lib/equivalences.js +0 -263
- package/lib/node/nonTerminal.js +0 -218
- package/lib/substitutions.js +0 -424
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import ontology from "../../ontology";
|
|
3
4
|
import Substitution from "../substitution";
|
|
4
|
-
import Substitutions from "../../substitutions";
|
|
5
5
|
import StatementSubstitutionPartialContext from "../../context/partial/substitution/statement";
|
|
6
6
|
|
|
7
7
|
import { define } from "../../ontology";
|
|
@@ -10,8 +10,8 @@ import { stripBracketsFromStatement } from "../../utilities/brackets";
|
|
|
10
10
|
import { statementFromJSON, statementToStatementJSON, metavariableFromJSON, metavariableToMetavariableJSON } from "../../utilities/json";
|
|
11
11
|
|
|
12
12
|
export default define(class StatementSubstitution extends Substitution {
|
|
13
|
-
constructor(string, node, tokens, resolved, statement, metavariable, substitution) {
|
|
14
|
-
super(string, node, tokens);
|
|
13
|
+
constructor(context, string, node, tokens, resolved, statement, metavariable, substitution) {
|
|
14
|
+
super(context, string, node, tokens);
|
|
15
15
|
|
|
16
16
|
this.resolved = resolved;
|
|
17
17
|
this.statement = statement;
|
|
@@ -35,112 +35,103 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
35
35
|
return this.substitution;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
getReplacementNode() {
|
|
39
|
+
const statementNode = this.statement.getNode(),
|
|
40
|
+
replacementNode = statementNode; ///
|
|
41
|
+
|
|
42
|
+
return replacementNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isSimple() {
|
|
46
|
+
const simple = (this.substitution === null);
|
|
47
|
+
|
|
48
|
+
return simple;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isStatementEqualToStatement(statement, context) {
|
|
39
52
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
40
53
|
|
|
41
|
-
const
|
|
54
|
+
const statementEqualToStatement = this.statement.isEqualTo(statement);
|
|
42
55
|
|
|
43
|
-
return
|
|
56
|
+
return statementEqualToStatement;
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
isMetavariableEqualToMetavariable(metavariable) { return this.metavariable.isEqualTo(metavariable); }
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
let
|
|
61
|
+
isSubstitutionEqualToSubstitution(substitution) {
|
|
62
|
+
let substitutionEqualToSubstitution;
|
|
50
63
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
} else if ((substitution === null) && (this.substitution === null)) {
|
|
54
|
-
substitutionEqualTo = true;
|
|
55
|
-
} else if ((substitution !== null) && (this.substitution === null)) {
|
|
56
|
-
substitutionEqualTo = false;
|
|
57
|
-
} else if ((substitution === null) && (this.substitution !== null)) {
|
|
58
|
-
substitutionEqualTo = false;
|
|
64
|
+
if (this.substitution === null) {
|
|
65
|
+
substitutionEqualToSubstitution = (substitution === null);
|
|
59
66
|
} else {
|
|
60
|
-
|
|
67
|
+
if (substitution === null) {
|
|
68
|
+
substitutionEqualToSubstitution = false;
|
|
69
|
+
} else {
|
|
70
|
+
substitutionEqualToSubstitution = this.substitution.isEqualTo(substitution);
|
|
71
|
+
}
|
|
61
72
|
}
|
|
62
73
|
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
isSimple() {
|
|
67
|
-
const simple = (this.substitution === null);
|
|
68
|
-
|
|
69
|
-
return simple;
|
|
74
|
+
return substitutionEqualToSubstitution;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
matchParameter(parameter) { return this.metavariable.matchParameter(parameter); }
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
replacementNode = statementNode; ///
|
|
79
|
+
resolve(substitutions, context) {
|
|
80
|
+
const substitutionString = this.string; ///
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
}
|
|
82
|
+
context.trace(`Resolving the ${substitutionString} substitution...`);
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
const substitutionString = this.string; ///
|
|
84
|
+
substitutions.snapshot();
|
|
83
85
|
|
|
84
86
|
const metavariable = this.getMetavariable(),
|
|
85
87
|
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable);
|
|
86
88
|
|
|
87
89
|
if (simpleSubstitution !== null) {
|
|
88
|
-
|
|
90
|
+
let context;
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
substitutionResolved = substitution.resolveSubstitution(this.substitution, this.statement, substitutions, generalContext, specificContext);
|
|
92
|
+
context = this.getContext();
|
|
92
93
|
|
|
93
|
-
this.
|
|
94
|
+
const substitution = simpleSubstitution.unifyStatement(this.statement, context);
|
|
94
95
|
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
resolveSubstitution(substitution, statement, substitutions, generalContext, specificContext) {
|
|
102
|
-
let substitutionResolved = false;
|
|
103
|
-
|
|
104
|
-
const substitutionString = substitution.getString();
|
|
96
|
+
if (substitution !== null) {
|
|
97
|
+
context = simpleSubstitution.getContext();
|
|
105
98
|
|
|
106
|
-
|
|
99
|
+
const terms = context.getTerms(),
|
|
100
|
+
frames = context.getFrames();
|
|
107
101
|
|
|
108
|
-
|
|
109
|
-
specificSubstitution = this.unifyStatement(statement, specificContext, specificContext); ///
|
|
102
|
+
context = substitution.getContext();
|
|
110
103
|
|
|
111
|
-
|
|
112
|
-
substitutions.snapshot();
|
|
104
|
+
context.addTerms(terms);
|
|
113
105
|
|
|
114
|
-
|
|
115
|
-
specificSubstitutionString = specificSubstitution.getString();
|
|
106
|
+
context.addFrames(frames);
|
|
116
107
|
|
|
117
|
-
|
|
108
|
+
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (substitutionUnifies) {
|
|
123
|
-
specificContext.trace(`...unified the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution.`);
|
|
110
|
+
if (substitutionUnifies) {
|
|
111
|
+
this.resolved = true;
|
|
112
|
+
}
|
|
124
113
|
}
|
|
114
|
+
}
|
|
125
115
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
this.resolved ?
|
|
117
|
+
substitutions.continue() :
|
|
118
|
+
substitutions.rollback(context);
|
|
129
119
|
|
|
130
|
-
|
|
120
|
+
if (this.resolved) {
|
|
121
|
+
context.debug(`...resolved the ${substitutionString} substitution.`);
|
|
131
122
|
}
|
|
123
|
+
}
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
125
|
+
unifyStatement(statement, context) {
|
|
126
|
+
let substitution = null;
|
|
136
127
|
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
const { Substitutions } = ontology,
|
|
129
|
+
substitutions = Substitutions.fromNothing(),
|
|
130
|
+
specificContext = context; ///
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
let specificSubstitution = null;
|
|
132
|
+
context = this.getContext();
|
|
142
133
|
|
|
143
|
-
const
|
|
134
|
+
const generalContext = context, ///
|
|
144
135
|
statementUnifies = this.statement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
145
136
|
|
|
146
137
|
if (statementUnifies) {
|
|
@@ -149,11 +140,37 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
149
140
|
if (substitutionsNonTrivialLength === 1) {
|
|
150
141
|
const firstSubstitution = substitutions.getFirstSubstitution();
|
|
151
142
|
|
|
152
|
-
|
|
143
|
+
substitution = firstSubstitution; ///
|
|
153
144
|
}
|
|
154
145
|
}
|
|
155
146
|
|
|
156
|
-
return
|
|
147
|
+
return substitution;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
unifySubstitution(substitution, substitutions, context) {
|
|
151
|
+
const generalSubstitution = this.substitution, ///
|
|
152
|
+
specificSubstitution = substitution, ///
|
|
153
|
+
generalSubstitutionString = generalSubstitution.getString(),
|
|
154
|
+
specificSubstitutionString = specificSubstitution.getString();
|
|
155
|
+
|
|
156
|
+
context.trace(`Unifying the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution...`);
|
|
157
|
+
|
|
158
|
+
let substitutionContext;
|
|
159
|
+
|
|
160
|
+
substitutionContext = this.substitution.getContext();
|
|
161
|
+
|
|
162
|
+
const generalContext = substitutionContext; ///
|
|
163
|
+
|
|
164
|
+
substitutionContext = substitution.getContext();
|
|
165
|
+
|
|
166
|
+
const specificContext = substitutionContext, ///
|
|
167
|
+
substitutionUnifies = unifySubstitution(generalSubstitution, specificSubstitution, substitutions, generalContext, specificContext);
|
|
168
|
+
|
|
169
|
+
if (substitutionUnifies) {
|
|
170
|
+
context.trace(`...unified the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution.`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return substitutionUnifies;
|
|
157
174
|
}
|
|
158
175
|
|
|
159
176
|
toJSON() {
|
|
@@ -171,6 +188,8 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
171
188
|
return json;
|
|
172
189
|
}
|
|
173
190
|
|
|
191
|
+
static name = "StatementSubstitution";
|
|
192
|
+
|
|
174
193
|
static fromJSON(json, context) {
|
|
175
194
|
const { string } = json,
|
|
176
195
|
lexer = context.getLexer(),
|
|
@@ -182,7 +201,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
182
201
|
statement = statementFromJSON(json, context),
|
|
183
202
|
metavariable = metavariableFromJSON(json, context),
|
|
184
203
|
substitution = null, ///
|
|
185
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
204
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
186
205
|
|
|
187
206
|
return statementSubstitution;
|
|
188
207
|
}
|
|
@@ -198,7 +217,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
198
217
|
tokens = statementSubstitutionPartialContext.getTokens(),
|
|
199
218
|
resolved = true,
|
|
200
219
|
substitution = null,
|
|
201
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
220
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
202
221
|
|
|
203
222
|
return statementSubstitution;
|
|
204
223
|
}
|
|
@@ -213,7 +232,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
213
232
|
node = statementSubstitutionPartialContext.getNode(),
|
|
214
233
|
tokens = statementSubstitutionPartialContext.getTokens(),
|
|
215
234
|
resolved = false,
|
|
216
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
235
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
217
236
|
|
|
218
237
|
return statementSubstitution;
|
|
219
238
|
}
|
|
@@ -6,11 +6,12 @@ import TermSubstitutionPartialContext from "../../context/partial/substitution/t
|
|
|
6
6
|
|
|
7
7
|
import { define } from "../../ontology";
|
|
8
8
|
import { stripBracketsFromTerm } from "../../utilities/brackets";
|
|
9
|
-
import {
|
|
9
|
+
import { termVariableIdentifierFromTermNode } from "../../utilities/variable";
|
|
10
|
+
|
|
10
11
|
|
|
11
12
|
export default define(class TermSubstitution extends Substitution {
|
|
12
|
-
constructor(string, node, tokens, term, variable) {
|
|
13
|
-
super(string, node, tokens);
|
|
13
|
+
constructor(context, string, node, tokens, term, variable) {
|
|
14
|
+
super(context, string, node, tokens);
|
|
14
15
|
|
|
15
16
|
this.term = term;
|
|
16
17
|
this.variable = variable;
|
|
@@ -24,6 +25,13 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
24
25
|
return this.variable;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
getReplacementNode() {
|
|
29
|
+
const termNode = this.term.getNode(),
|
|
30
|
+
replacementNode = termNode; ///
|
|
31
|
+
|
|
32
|
+
return replacementNode;
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
isTrivial() {
|
|
28
36
|
const termString = this.term.getString(),
|
|
29
37
|
variableString = this.variable.getString(),
|
|
@@ -32,68 +40,100 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
32
40
|
return trivial;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
isTermEqualToTerm(term, context) {
|
|
36
44
|
term = stripBracketsFromTerm(term, context); ///
|
|
37
45
|
|
|
38
|
-
const
|
|
46
|
+
const termEqualToTerm = this.term.isEqualTo(term);
|
|
39
47
|
|
|
40
|
-
return
|
|
48
|
+
return termEqualToTerm;
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
isVariableEqualTo(variable) { return this.variable.isEqualTo(variable); }
|
|
44
|
-
|
|
45
51
|
matchParameter(parameter) { return this.variable.matchParameter(parameter); }
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
replacementNode = termNode; ///
|
|
53
|
+
verify(context) {
|
|
54
|
+
let verifies = false;
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
const termSubstitutionString = this.string; ///
|
|
57
|
+
|
|
58
|
+
context.trace(`Verifiying the '${termSubstitutionString}' term substitutin...`);
|
|
59
|
+
|
|
60
|
+
const termSimple = this.term.isSimple();
|
|
61
|
+
|
|
62
|
+
if (termSimple) {
|
|
63
|
+
if (this.variable === null) {
|
|
64
|
+
context.debug(`The specific term is not simple.`);
|
|
65
|
+
} else {
|
|
66
|
+
const variableIdentifier = this.variable.getIdentifier(),
|
|
67
|
+
variablePresent = context.isVariablePresentByVariableIdentifier(variableIdentifier);
|
|
68
|
+
|
|
69
|
+
if (variablePresent) {
|
|
70
|
+
const termNode = this.term.getNode(),
|
|
71
|
+
termVariableIdentifier = termVariableIdentifierFromTermNode(termNode),
|
|
72
|
+
termVariablePresent = context.isVariablePresentByVariableIdentifier(termVariableIdentifier);
|
|
73
|
+
|
|
74
|
+
if (termVariablePresent) {
|
|
75
|
+
verifies = true;
|
|
76
|
+
} else {
|
|
77
|
+
const variableString = variable.getString();
|
|
78
|
+
|
|
79
|
+
context.debug(`The '${variableString}' variable is not present.`);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
const variableString = this.variable.getString();
|
|
83
|
+
|
|
84
|
+
context.debug(`The '${variableString}' variable is not present.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
context.debug(`The general term is not simple.`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (verifies) {
|
|
92
|
+
const substititoin = this; ///
|
|
93
|
+
|
|
94
|
+
context.addSubstitution(substititoin);
|
|
95
|
+
|
|
96
|
+
context.debug(`...verified the '${termSubstitutionString}' term substitutin.`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return verifies;
|
|
52
100
|
}
|
|
53
101
|
|
|
54
|
-
static
|
|
102
|
+
static name = "TermSubstitution";
|
|
103
|
+
|
|
104
|
+
static fromStatement(statement, context) {
|
|
55
105
|
let termSubstitution = null;
|
|
56
106
|
|
|
57
|
-
const
|
|
107
|
+
const statementNode = statement.getNode(),
|
|
108
|
+
termSubstitutionNode = statementNode.getTermSubstitutionNode();
|
|
58
109
|
|
|
59
110
|
if (termSubstitutionNode !== null) {
|
|
60
|
-
const
|
|
111
|
+
const { Term, Variable } = ontology,
|
|
61
112
|
firstTermNode = termSubstitutionNode.getFirstTermNode(),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
string = stringFromTermAndVariable(term, variable);
|
|
73
|
-
|
|
74
|
-
termSubstitution = new TermSubstitution(string, node, tokens, term, variable);
|
|
75
|
-
}
|
|
113
|
+
lastVariableNode = termSubstitutionNode.getLastVariableNode(),
|
|
114
|
+
termNode = firstTermNode, ///
|
|
115
|
+
variableNode = lastVariableNode, ///
|
|
116
|
+
term = Term.fromTermNode(termNode, context),
|
|
117
|
+
variable = Variable.fromVariableNode(variableNode, context),
|
|
118
|
+
node = termSubstitutionNode, ///
|
|
119
|
+
tokens = context.nodeAsTokens(node),
|
|
120
|
+
string = stringFromTermAndVariable(term, variable);
|
|
121
|
+
|
|
122
|
+
termSubstitution = new TermSubstitution(context, string, node, tokens, term, variable);
|
|
76
123
|
}
|
|
77
124
|
|
|
78
125
|
return termSubstitution;
|
|
79
126
|
}
|
|
80
127
|
|
|
81
128
|
static fromTernAndVariable(term, variable, context) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
termNode = stripBracketsFromTermNode(termNode); ///
|
|
85
|
-
|
|
86
|
-
const { Term } = ontology;
|
|
87
|
-
|
|
88
|
-
term = Term.fromTermNode(termNode, context);
|
|
89
|
-
|
|
90
|
-
const string = stringFromTermAndVariable(term, variable),
|
|
91
|
-
lexer = context.getLexer(),
|
|
129
|
+
const lexer = context.getLexer(),
|
|
92
130
|
parser = context.getParser(),
|
|
131
|
+
string = stringFromTermAndVariable(term, variable),
|
|
93
132
|
termSubstitutionPartialContext = TermSubstitutionPartialContext.fromStringLexerAndParser(string, lexer, parser),
|
|
94
133
|
node = termSubstitutionPartialContext.getNode(),
|
|
95
|
-
tokens = termSubstitutionPartialContext.getTokens()
|
|
96
|
-
|
|
134
|
+
tokens = termSubstitutionPartialContext.getTokens();
|
|
135
|
+
|
|
136
|
+
const termSubstitution = new TermSubstitution(context, string, node, tokens, term, variable);
|
|
97
137
|
|
|
98
138
|
return termSubstitution;
|
|
99
139
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export default class Substitution {
|
|
4
|
-
constructor(string, node, tokens) {
|
|
4
|
+
constructor(context, string, node, tokens) {
|
|
5
|
+
this.context = context;
|
|
5
6
|
this.string = string;
|
|
6
7
|
this.node = node;
|
|
7
8
|
this.tokens = tokens;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
getContext() {
|
|
12
|
+
return this.context;
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
getString() {
|
|
11
16
|
return this.string;
|
|
12
17
|
}
|
|
@@ -61,6 +66,12 @@ export default class Substitution {
|
|
|
61
66
|
return substitution;
|
|
62
67
|
}
|
|
63
68
|
|
|
69
|
+
getReplacementNode() {
|
|
70
|
+
const replacementNode = null;
|
|
71
|
+
|
|
72
|
+
return replacementNode;
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
isSimple() {
|
|
65
76
|
const simple = true;
|
|
66
77
|
|
|
@@ -87,52 +98,40 @@ export default class Substitution {
|
|
|
87
98
|
return equalTo;
|
|
88
99
|
}
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
return termEqualTo;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
isFrameEqualTo(frame) {
|
|
97
|
-
const frameEqualTo = false;
|
|
98
|
-
|
|
99
|
-
return frameEqualTo;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
isVariableEqualTo(variable) {
|
|
103
|
-
const variableEqualTo = false;
|
|
101
|
+
isTermEqualToTerm(term, context) {
|
|
102
|
+
const termEqualToTerm = false;
|
|
104
103
|
|
|
105
|
-
return
|
|
104
|
+
return termEqualToTerm;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
|
|
109
|
-
const
|
|
107
|
+
isFrameEqualToFrame(frame) {
|
|
108
|
+
const frameEqualToFrame = false;
|
|
110
109
|
|
|
111
|
-
return
|
|
110
|
+
return frameEqualToFrame;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
|
|
115
|
-
const
|
|
113
|
+
isReferenceEqualToReference(reference, context) {
|
|
114
|
+
const referenceEqualToReference = false;
|
|
116
115
|
|
|
117
|
-
return
|
|
116
|
+
return referenceEqualToReference;
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
const
|
|
119
|
+
isStatementEqualToStatement(statement, context) {
|
|
120
|
+
const statementEqualToStatement = false;
|
|
122
121
|
|
|
123
|
-
return
|
|
122
|
+
return statementEqualToStatement;
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
const
|
|
125
|
+
isMetavariableEqualToMetavariable(metavariable) {
|
|
126
|
+
const metavariableEqualToMetavariable = false;
|
|
128
127
|
|
|
129
|
-
return
|
|
128
|
+
return metavariableEqualToMetavariable;
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
const
|
|
131
|
+
isSubstitutionEqualToSubstitution(substitution) {
|
|
132
|
+
const substitutionEqualToSubstitution = (substitution === null);
|
|
134
133
|
|
|
135
|
-
return
|
|
134
|
+
return substitutionEqualToSubstitution;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
matchParameter(parameter) {
|
|
@@ -141,9 +140,11 @@ export default class Substitution {
|
|
|
141
140
|
return parameterMatches;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
|
|
145
|
-
const replacementNode = null;
|
|
143
|
+
matchSubstitutionNode(substitutionNode) { return this.node.match(substitutionNode); }
|
|
146
144
|
|
|
147
|
-
|
|
145
|
+
resolve(substitutions, context) {
|
|
146
|
+
const resolved = true;
|
|
147
|
+
|
|
148
|
+
return resolved;
|
|
148
149
|
}
|
|
149
150
|
}
|