@stevenvo780/autologic 2.0.1 → 2.2.0
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/README.md +2 -0
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.d.ts.map +1 -1
- package/dist/atoms/index.js +75 -3
- package/dist/atoms/index.js.map +1 -1
- package/dist/atoms/keyword-extractor.d.ts +9 -0
- package/dist/atoms/keyword-extractor.d.ts.map +1 -1
- package/dist/atoms/keyword-extractor.js +64 -2
- package/dist/atoms/keyword-extractor.js.map +1 -1
- package/dist/atoms/math-parser.d.ts +11 -0
- package/dist/atoms/math-parser.d.ts.map +1 -0
- package/dist/atoms/math-parser.js +44 -0
- package/dist/atoms/math-parser.js.map +1 -0
- package/dist/compiler-frontend.d.ts +9 -0
- package/dist/compiler-frontend.d.ts.map +1 -0
- package/dist/compiler-frontend.js +142 -0
- package/dist/compiler-frontend.js.map +1 -0
- package/dist/context/discourse-state.d.ts +10 -0
- package/dist/context/discourse-state.d.ts.map +1 -0
- package/dist/context/discourse-state.js +26 -0
- package/dist/context/discourse-state.js.map +1 -0
- package/dist/discourse/markers-es.d.ts.map +1 -1
- package/dist/discourse/markers-es.js +23 -0
- package/dist/discourse/markers-es.js.map +1 -1
- package/dist/discourse/pattern-detector.d.ts.map +1 -1
- package/dist/discourse/pattern-detector.js +2 -1
- package/dist/discourse/pattern-detector.js.map +1 -1
- package/dist/discourse/role-classifier.js +32 -3
- package/dist/discourse/role-classifier.js.map +1 -1
- package/dist/formalize.d.ts +16 -0
- package/dist/formalize.d.ts.map +1 -1
- package/dist/formalize.js +128 -0
- package/dist/formalize.js.map +1 -1
- package/dist/formula/argument-builder.d.ts.map +1 -1
- package/dist/formula/argument-builder.js +95 -16
- package/dist/formula/argument-builder.js.map +1 -1
- package/dist/formula/ast-compiler.d.ts +6 -0
- package/dist/formula/ast-compiler.d.ts.map +1 -0
- package/dist/formula/ast-compiler.js +105 -0
- package/dist/formula/ast-compiler.js.map +1 -0
- package/dist/formula/ast.d.ts +81 -0
- package/dist/formula/ast.d.ts.map +1 -0
- package/dist/formula/ast.js +52 -0
- package/dist/formula/ast.js.map +1 -0
- package/dist/formula/connectors.js +1 -1
- package/dist/formula/connectors.js.map +1 -1
- package/dist/formula/first-order.js +74 -7
- package/dist/formula/first-order.js.map +1 -1
- package/dist/formula/helpers.d.ts +8 -0
- package/dist/formula/helpers.d.ts.map +1 -0
- package/dist/formula/helpers.js +166 -0
- package/dist/formula/helpers.js.map +1 -0
- package/dist/formula/index.d.ts +1 -0
- package/dist/formula/index.d.ts.map +1 -1
- package/dist/formula/index.js +5 -3
- package/dist/formula/index.js.map +1 -1
- package/dist/formula/modal.d.ts.map +1 -1
- package/dist/formula/modal.js +56 -67
- package/dist/formula/modal.js.map +1 -1
- package/dist/formula/probabilistic.d.ts +3 -0
- package/dist/formula/probabilistic.d.ts.map +1 -0
- package/dist/formula/probabilistic.js +55 -0
- package/dist/formula/probabilistic.js.map +1 -0
- package/dist/formula/propositional.d.ts +2 -2
- package/dist/formula/propositional.d.ts.map +1 -1
- package/dist/formula/propositional.js +74 -102
- package/dist/formula/propositional.js.map +1 -1
- package/dist/formula/temporal.d.ts.map +1 -1
- package/dist/formula/temporal.js +87 -62
- package/dist/formula/temporal.js.map +1 -1
- package/dist/generator/validator.d.ts +20 -0
- package/dist/generator/validator.d.ts.map +1 -1
- package/dist/generator/validator.js +112 -0
- package/dist/generator/validator.js.map +1 -1
- package/dist/index.d.ts +6 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -17
- package/dist/index.js.map +1 -1
- package/dist/llm-parser.d.ts +29 -0
- package/dist/llm-parser.d.ts.map +1 -0
- package/dist/llm-parser.js +122 -0
- package/dist/llm-parser.js.map +1 -0
- package/dist/local-slm-web.d.ts +8 -0
- package/dist/local-slm-web.d.ts.map +1 -0
- package/dist/local-slm-web.js +87 -0
- package/dist/local-slm-web.js.map +1 -0
- package/dist/nl-linter/index.d.ts +10 -0
- package/dist/nl-linter/index.d.ts.map +1 -0
- package/dist/nl-linter/index.js +45 -0
- package/dist/nl-linter/index.js.map +1 -0
- package/dist/nl-linter/rules.d.ts +6 -0
- package/dist/nl-linter/rules.d.ts.map +1 -0
- package/dist/nl-linter/rules.js +93 -0
- package/dist/nl-linter/rules.js.map +1 -0
- package/dist/nl-linter/types.d.ts +14 -0
- package/dist/nl-linter/types.d.ts.map +1 -0
- package/dist/nl-linter/types.js +3 -0
- package/dist/nl-linter/types.js.map +1 -0
- package/dist/segmenter/clause-splitter.d.ts.map +1 -1
- package/dist/segmenter/clause-splitter.js +208 -10
- package/dist/segmenter/clause-splitter.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -4
- package/readme.md +666 -1
package/dist/formula/temporal.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildTemporal = buildTemporal;
|
|
4
4
|
const connectors_1 = require("./connectors");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
5
6
|
/**
|
|
6
7
|
* Construye fórmulas temporales LTL.
|
|
7
8
|
*/
|
|
@@ -25,110 +26,134 @@ function buildTemporalSentence(sentence, allAtoms, sentenceIdx, labelStart) {
|
|
|
25
26
|
const hasUntil = clauses.some(c => c.modifiers.some(m => m.type === 'temporal_until'));
|
|
26
27
|
const hasAlways = clauses.some(c => c.modifiers.some(m => m.type === 'temporal_always'));
|
|
27
28
|
const hasEventually = clauses.some(c => c.modifiers.some(m => m.type === 'temporal_eventually'));
|
|
28
|
-
if (sentence.type === 'conditional'
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (sentence.type === 'conditional') {
|
|
30
|
+
// Temporal condicional general: preservar wrappers sobre la implicación completa.
|
|
31
|
+
let condClauses = clauses.filter(c => c.role === 'condition' || c.role === 'premise');
|
|
32
|
+
let consClauses = clauses.filter(c => c.role === 'consequent' || c.role === 'conclusion' || c.role === 'assertion');
|
|
33
|
+
if (condClauses.length === 0 && clauses.length >= 2) {
|
|
34
|
+
condClauses = [clauses[0]];
|
|
35
|
+
consClauses = [clauses[1]];
|
|
36
|
+
}
|
|
32
37
|
if (condClauses.length > 0 && consClauses.length > 0) {
|
|
33
|
-
const ant =
|
|
34
|
-
const cons =
|
|
35
|
-
|
|
38
|
+
const ant = (0, helpers_1.resolveAtomId)(condClauses[0].text, allAtoms);
|
|
39
|
+
const cons = (0, helpers_1.resolveAtomId)(consClauses[0].text, allAtoms);
|
|
40
|
+
const implication = `${(0, helpers_1.applyLogicalModifiers)(ant, (0, helpers_1.stripModifierFamily)(condClauses[0].modifiers, 'temporal'), 'temporal.ltl')} -> ${(0, helpers_1.applyLogicalModifiers)(cons, consClauses[0].modifiers.map((modifier) => modifier.type), 'temporal.ltl')}`;
|
|
41
|
+
formulas.push({
|
|
42
|
+
formula: (0, helpers_1.applyLogicalModifiers)(implication, (0, helpers_1.pickLeadingSentenceModifiers)(clauses[0].modifiers, 'temporal'), 'temporal.ltl'),
|
|
43
|
+
stType: 'axiom',
|
|
44
|
+
label: `a${label++}`,
|
|
45
|
+
sourceText: sentence.original,
|
|
46
|
+
sourceSentence: sentenceIdx,
|
|
47
|
+
comment: `Temporal: "${sentence.original}"`,
|
|
48
|
+
});
|
|
49
|
+
const supplementalClauses = clauses.filter(clause => clause !== condClauses[0] && clause !== consClauses[0]);
|
|
50
|
+
for (const clause of supplementalClauses) {
|
|
51
|
+
const atom = (0, helpers_1.resolveAtomId)(clause.text, allAtoms);
|
|
36
52
|
formulas.push({
|
|
37
|
-
formula:
|
|
38
|
-
stType: 'axiom',
|
|
53
|
+
formula: (0, helpers_1.applyLogicalModifiers)(atom, sanitizeStandaloneTemporalModifiers(clause.modifiers.map((modifier) => modifier.type)), 'temporal.ltl'),
|
|
54
|
+
stType: clause.role === 'conclusion' ? 'derive' : 'axiom',
|
|
39
55
|
label: `a${label++}`,
|
|
40
|
-
sourceText:
|
|
56
|
+
sourceText: clause.text,
|
|
41
57
|
sourceSentence: sentenceIdx,
|
|
42
|
-
comment: `
|
|
58
|
+
comment: `Subcláusula temporal: "${clause.text}"`,
|
|
43
59
|
});
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
63
|
else if (hasUntil && clauses.length >= 2) {
|
|
48
64
|
// "A hasta que B" → A until B
|
|
49
|
-
const atomsList = clauses.map(c =>
|
|
65
|
+
const atomsList = clauses.map(c => (0, helpers_1.resolveAtomId)(c.text, allAtoms));
|
|
50
66
|
if (atomsList.length >= 2) {
|
|
51
67
|
formulas.push({
|
|
52
|
-
formula: `${atomsList[0].
|
|
68
|
+
formula: `${(0, helpers_1.applyLogicalModifiers)(atomsList[0], (0, helpers_1.stripModifierFamily)(clauses[0].modifiers, 'temporal'), 'temporal.ltl')} ${connectors_1.ST_OPERATORS.temporal_until} ${(0, helpers_1.applyLogicalModifiers)(atomsList[1], (0, helpers_1.stripModifierFamily)(clauses[1].modifiers, 'temporal'), 'temporal.ltl')}`,
|
|
53
69
|
stType: 'axiom',
|
|
54
70
|
label: `a${label++}`,
|
|
55
71
|
sourceText: sentence.original,
|
|
56
72
|
sourceSentence: sentenceIdx,
|
|
57
73
|
comment: `Temporal until: "${sentence.original}"`,
|
|
58
74
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// "Siempre A" → always A
|
|
63
|
-
for (const clause of clauses) {
|
|
64
|
-
const atom = findAtom(clause.text, allAtoms);
|
|
65
|
-
if (atom) {
|
|
75
|
+
for (let clauseIndex = 2; clauseIndex < clauses.length; clauseIndex++) {
|
|
76
|
+
const clause = clauses[clauseIndex];
|
|
77
|
+
const atom = (0, helpers_1.resolveAtomId)(clause.text, allAtoms);
|
|
66
78
|
formulas.push({
|
|
67
|
-
formula:
|
|
68
|
-
stType: 'axiom',
|
|
79
|
+
formula: (0, helpers_1.applyLogicalModifiers)(atom, sanitizeStandaloneTemporalModifiers(clause.modifiers.map((modifier) => modifier.type)), 'temporal.ltl'),
|
|
80
|
+
stType: clause.role === 'conclusion' ? 'derive' : 'axiom',
|
|
69
81
|
label: `a${label++}`,
|
|
70
82
|
sourceText: clause.text,
|
|
71
83
|
sourceSentence: sentenceIdx,
|
|
72
|
-
comment: `
|
|
84
|
+
comment: `Subcláusula temporal: "${clause.text}"`,
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
}
|
|
89
|
+
else if (hasAlways) {
|
|
90
|
+
// "Siempre A" → G(A)
|
|
91
|
+
for (const clause of clauses) {
|
|
92
|
+
const atom = (0, helpers_1.resolveAtomId)(clause.text, allAtoms);
|
|
93
|
+
formulas.push({
|
|
94
|
+
formula: (0, helpers_1.applyLogicalModifiers)(atom, clause.modifiers.map((modifier) => modifier.type), 'temporal.ltl'),
|
|
95
|
+
stType: 'axiom',
|
|
96
|
+
label: `a${label++}`,
|
|
97
|
+
sourceText: clause.text,
|
|
98
|
+
sourceSentence: sentenceIdx,
|
|
99
|
+
comment: `Temporal always: "${clause.text}"`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
77
103
|
else if (hasEventually) {
|
|
78
|
-
// "Eventualmente A" →
|
|
104
|
+
// "Eventualmente A" → F(A)
|
|
79
105
|
for (const clause of clauses) {
|
|
80
|
-
const atom =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
}
|
|
106
|
+
const atom = (0, helpers_1.resolveAtomId)(clause.text, allAtoms);
|
|
107
|
+
formulas.push({
|
|
108
|
+
formula: (0, helpers_1.applyLogicalModifiers)(atom, clause.modifiers.map((modifier) => modifier.type), 'temporal.ltl'),
|
|
109
|
+
stType: 'axiom',
|
|
110
|
+
label: `a${label++}`,
|
|
111
|
+
sourceText: clause.text,
|
|
112
|
+
sourceSentence: sentenceIdx,
|
|
113
|
+
comment: `Temporal eventually: "${clause.text}"`,
|
|
114
|
+
});
|
|
91
115
|
}
|
|
92
116
|
}
|
|
93
117
|
else {
|
|
94
118
|
// Temporal genérico: tratar como condicional con next
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
119
|
+
if (clauses.length >= 2) {
|
|
120
|
+
let condClauses = clauses.filter(c => c.role === 'condition' || c.role === 'premise');
|
|
121
|
+
let restClauses = clauses.filter(c => c.role !== 'condition' && c.role !== 'premise');
|
|
122
|
+
if (condClauses.length === 0) {
|
|
123
|
+
condClauses = [clauses[0]];
|
|
124
|
+
restClauses = clauses.slice(1);
|
|
125
|
+
}
|
|
98
126
|
if (condClauses.length > 0 && restClauses.length > 0) {
|
|
99
|
-
const ant =
|
|
100
|
-
const cons =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
127
|
+
const ant = (0, helpers_1.resolveAtomId)(condClauses[0].text, allAtoms);
|
|
128
|
+
const cons = (0, helpers_1.resolveAtomId)(restClauses[0].text, allAtoms);
|
|
129
|
+
const implication = `${(0, helpers_1.applyLogicalModifiers)(ant, (0, helpers_1.stripModifierFamily)(condClauses[0].modifiers, 'temporal'), 'temporal.ltl')} -> ${(0, helpers_1.applyLogicalModifiers)(cons, ['temporal_next', ...restClauses[0].modifiers.map((modifier) => modifier.type)], 'temporal.ltl')}`;
|
|
130
|
+
formulas.push({
|
|
131
|
+
formula: (0, helpers_1.applyLogicalModifiers)(implication, (0, helpers_1.pickLeadingSentenceModifiers)(clauses[0].modifiers, 'temporal'), 'temporal.ltl'),
|
|
132
|
+
stType: 'axiom',
|
|
133
|
+
label: `a${label++}`,
|
|
134
|
+
sourceText: sentence.original,
|
|
135
|
+
sourceSentence: sentenceIdx,
|
|
136
|
+
comment: `Temporal: "${sentence.original}"`,
|
|
137
|
+
});
|
|
111
138
|
}
|
|
112
139
|
}
|
|
113
140
|
else {
|
|
114
141
|
// Aserción temporal simple
|
|
115
142
|
for (const clause of clauses) {
|
|
116
|
-
const atom =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
}
|
|
143
|
+
const atom = (0, helpers_1.resolveAtomId)(clause.text, allAtoms);
|
|
144
|
+
formulas.push({
|
|
145
|
+
formula: (0, helpers_1.applyLogicalModifiers)(atom, clause.modifiers.map((modifier) => modifier.type), 'temporal.ltl'),
|
|
146
|
+
stType: 'axiom',
|
|
147
|
+
label: `a${label++}`,
|
|
148
|
+
sourceText: clause.text,
|
|
149
|
+
sourceSentence: sentenceIdx,
|
|
150
|
+
});
|
|
126
151
|
}
|
|
127
152
|
}
|
|
128
153
|
}
|
|
129
154
|
return formulas;
|
|
130
155
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
156
|
+
function sanitizeStandaloneTemporalModifiers(modifiers) {
|
|
157
|
+
return modifiers.filter((modifier) => modifier !== 'temporal_until');
|
|
133
158
|
}
|
|
134
159
|
//# sourceMappingURL=temporal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/formula/temporal.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/formula/temporal.ts"],"names":[],"mappings":";;AAiBA,sCAeC;AA1BD,6CAA4C;AAC5C,uCAKmB;AAEnB;;GAEG;AACH,SAAgB,aAAa,CAC3B,SAA6B,EAC7B,WAAwB;IAExB,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;QACnD,MAAM,QA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B,UAAU,EAAE,MAAM,CAAC,IAAI;oBACvB,cAAc,EAAE,WAAW;iBAC5B,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,mCAAmC,CAAC,SAAmB;IAC9D,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,gBAAgB,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -3,20 +3,40 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Intenta importar st-lang dinámicamente (peerDep).
|
|
5
5
|
* Si no está disponible, reporta warning pero no falla.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: child_process is loaded dynamically to keep this module
|
|
8
|
+
* importable in browser/webpack contexts (Next.js client bundles).
|
|
6
9
|
*/
|
|
7
10
|
import type { Diagnostic } from '../types';
|
|
8
11
|
interface ValidationResult {
|
|
9
12
|
ok: boolean;
|
|
10
13
|
errors: string[];
|
|
11
14
|
}
|
|
15
|
+
interface ExecutionResult {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
exitCode: number;
|
|
18
|
+
timedOut: boolean;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
errors: string[];
|
|
21
|
+
resultStatuses: string[];
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* Valida código ST usando el parser de st-lang.
|
|
14
25
|
* Requiere que @stevenvo780/st-lang esté instalado (peerDependency).
|
|
15
26
|
*/
|
|
16
27
|
export declare function validateST(code: string): ValidationResult;
|
|
28
|
+
/**
|
|
29
|
+
* Ejecuta código ST para detectar errores reales de parser/runtime.
|
|
30
|
+
* Si st-lang no está disponible, no bloquea la formalización.
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeST(code: string): ExecutionResult;
|
|
17
33
|
/**
|
|
18
34
|
* Convierte errores de validación en diagnósticos.
|
|
19
35
|
*/
|
|
20
36
|
export declare function validationToDiagnostics(validation: ValidationResult): Diagnostic[];
|
|
37
|
+
/**
|
|
38
|
+
* Convierte errores de ejecución en diagnósticos.
|
|
39
|
+
*/
|
|
40
|
+
export declare function executionToDiagnostics(execution: ExecutionResult): Diagnostic[];
|
|
21
41
|
export {};
|
|
22
42
|
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/generator/validator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/generator/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,UAAU,gBAAgB;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,UAAU,eAAe;IACvB,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAUD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAiCzD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CA6FvD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,EAAE,CAOlF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,eAAe,GAAG,UAAU,EAAE,CAO/E"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateST = validateST;
|
|
4
|
+
exports.executeST = executeST;
|
|
4
5
|
exports.validationToDiagnostics = validationToDiagnostics;
|
|
6
|
+
exports.executionToDiagnostics = executionToDiagnostics;
|
|
7
|
+
const DEFAULT_EXECUTION_TIMEOUT_MS = 4000;
|
|
8
|
+
function getExecutionTimeoutMs() {
|
|
9
|
+
const raw = process.env.AUTOLOGIC_ST_EXEC_TIMEOUT_MS;
|
|
10
|
+
const parsed = raw ? Number(raw) : NaN;
|
|
11
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_EXECUTION_TIMEOUT_MS;
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Valida código ST usando el parser de st-lang.
|
|
7
15
|
* Requiere que @stevenvo780/st-lang esté instalado (peerDependency).
|
|
@@ -38,6 +46,98 @@ function validateST(code) {
|
|
|
38
46
|
return { ok: true, errors: [] };
|
|
39
47
|
}
|
|
40
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Ejecuta código ST para detectar errores reales de parser/runtime.
|
|
51
|
+
* Si st-lang no está disponible, no bloquea la formalización.
|
|
52
|
+
*/
|
|
53
|
+
function executeST(code) {
|
|
54
|
+
const startedAt = Date.now();
|
|
55
|
+
try {
|
|
56
|
+
// Dynamic require to avoid breaking browser/webpack bundles
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
58
|
+
const cp = require('child_process');
|
|
59
|
+
const spawnSync = cp.spawnSync;
|
|
60
|
+
const runner = String.raw `
|
|
61
|
+
const fs = require('node:fs');
|
|
62
|
+
const input = fs.readFileSync(0, 'utf8');
|
|
63
|
+
const stLang = require('@stevenvo780/st-lang');
|
|
64
|
+
const result = stLang.evaluate(input);
|
|
65
|
+
const diagnostics = Array.isArray(result?.diagnostics) ? result.diagnostics : [];
|
|
66
|
+
const stderr = typeof result?.stderr === 'string' ? result.stderr.trim() : '';
|
|
67
|
+
const errors = diagnostics
|
|
68
|
+
.filter((d) => d?.severity === 'error')
|
|
69
|
+
.map((d) => d?.message || 'Error desconocido');
|
|
70
|
+
if (stderr) errors.push(stderr);
|
|
71
|
+
process.stdout.write(JSON.stringify({
|
|
72
|
+
ok: result?.exitCode === 0,
|
|
73
|
+
exitCode: typeof result?.exitCode === 'number' ? result.exitCode : 0,
|
|
74
|
+
errors: Array.from(new Set(errors)).filter((error) => typeof error === 'string' && error.length > 0),
|
|
75
|
+
resultStatuses: Array.isArray(result?.results)
|
|
76
|
+
? result.results.map((entry) => entry?.status || 'unknown')
|
|
77
|
+
: [],
|
|
78
|
+
}));`;
|
|
79
|
+
const child = spawnSync(process.execPath, ['-e', runner], {
|
|
80
|
+
input: code,
|
|
81
|
+
encoding: 'utf8',
|
|
82
|
+
timeout: getExecutionTimeoutMs(),
|
|
83
|
+
maxBuffer: 1024 * 1024,
|
|
84
|
+
env: process.env,
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
});
|
|
87
|
+
const durationMs = Date.now() - startedAt;
|
|
88
|
+
if (child.error && 'code' in child.error && child.error.code === 'ETIMEDOUT') {
|
|
89
|
+
return {
|
|
90
|
+
ok: false,
|
|
91
|
+
exitCode: -1,
|
|
92
|
+
timedOut: true,
|
|
93
|
+
durationMs,
|
|
94
|
+
errors: [`Tiempo de ejecución ST excedido (${getExecutionTimeoutMs()} ms)`],
|
|
95
|
+
resultStatuses: [],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (child.error) {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
exitCode: -1,
|
|
102
|
+
timedOut: false,
|
|
103
|
+
durationMs,
|
|
104
|
+
errors: [child.error.message],
|
|
105
|
+
resultStatuses: [],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const stdout = (child.stdout || '').trim();
|
|
109
|
+
if (!stdout) {
|
|
110
|
+
const stderr = (child.stderr || '').trim();
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
exitCode: child.status ?? -1,
|
|
114
|
+
timedOut: false,
|
|
115
|
+
durationMs,
|
|
116
|
+
errors: stderr ? [stderr] : ['ST no devolvió salida estructurada'],
|
|
117
|
+
resultStatuses: [],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const parsed = JSON.parse(stdout);
|
|
121
|
+
return {
|
|
122
|
+
ok: parsed.ok,
|
|
123
|
+
exitCode: parsed.exitCode,
|
|
124
|
+
timedOut: false,
|
|
125
|
+
durationMs,
|
|
126
|
+
errors: parsed.errors,
|
|
127
|
+
resultStatuses: parsed.resultStatuses,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
exitCode: 0,
|
|
134
|
+
timedOut: false,
|
|
135
|
+
durationMs: Date.now() - startedAt,
|
|
136
|
+
errors: [],
|
|
137
|
+
resultStatuses: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
41
141
|
/**
|
|
42
142
|
* Convierte errores de validación en diagnósticos.
|
|
43
143
|
*/
|
|
@@ -50,4 +150,16 @@ function validationToDiagnostics(validation) {
|
|
|
50
150
|
code: 'ST_VALIDATION',
|
|
51
151
|
}));
|
|
52
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Convierte errores de ejecución en diagnósticos.
|
|
155
|
+
*/
|
|
156
|
+
function executionToDiagnostics(execution) {
|
|
157
|
+
if (execution.ok)
|
|
158
|
+
return [];
|
|
159
|
+
return execution.errors.map(error => ({
|
|
160
|
+
severity: execution.timedOut ? 'warning' : 'error',
|
|
161
|
+
message: `ST Execution (${execution.durationMs} ms${execution.timedOut ? ', timeout' : ''}): ${error}`,
|
|
162
|
+
code: 'ST_EXECUTION',
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
53
165
|
//# sourceMappingURL=validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/generator/validator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/generator/validator.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AS,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,EAAE;QACtG,IAAI,EAAE,cAAc;KACrB,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,25 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
* @module @stevenvo780/autologic
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { formalize, Autologic } from '@stevenvo780/autologic';
|
|
10
|
-
*
|
|
11
|
-
* // Uso stateless
|
|
12
|
-
* const result = formalize("Si llueve, la calle se moja.", {
|
|
13
|
-
* profile: 'classical.propositional',
|
|
14
|
-
* language: 'es',
|
|
15
|
-
* });
|
|
16
|
-
* console.log(result.stCode);
|
|
17
|
-
*
|
|
18
|
-
* // Uso con estado
|
|
19
|
-
* const al = new Autologic({ language: 'es' });
|
|
20
|
-
* const r = al.formalize("Todo humano es mortal. Sócrates es humano.");
|
|
21
|
-
* ```
|
|
22
6
|
*/
|
|
23
|
-
export { formalize } from './formalize';
|
|
7
|
+
export { formalize, formalizeWithLLM } from './formalize';
|
|
8
|
+
export type { FormalizeWithLLMOptions, FormalizationLLMResult } from './formalize';
|
|
9
|
+
export { lintNaturalLanguage, DEFAULT_RULES } from './nl-linter';
|
|
10
|
+
export type { NLLinterDiagnostic, NLRule } from './nl-linter';
|
|
24
11
|
export { Autologic } from './autologic';
|
|
12
|
+
export { parseTextWithLLM, llmResultToST } from './llm-parser';
|
|
13
|
+
export type { LLMConfig, LLMParsedResult } from './llm-parser';
|
|
25
14
|
export type { FormalizeOptions, FormalizationResult, AutologicConfig, LogicProfile, Language, AtomStyle, DiscourseAnalysis, AnalyzedSentence, AnalyzedClause, SentenceType, ClauseRole, ClauseModifier, MarkerRole, MarkerDefinition, DetectedMarker, ArgumentStructure, ArgumentRelation, ArgumentPattern, Sentence, Clause, AtomEntry, FormulaEntry, STStatementType, Diagnostic, Token, } from './types';
|
|
26
15
|
export { segment } from './segmenter';
|
|
27
16
|
export { analyzeDiscourse } from './discourse';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/D,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,MAAM,EACN,SAAS,EACT,YAAY,EACZ,eAAe,EACf,UAAU,EACV,KAAK,GACN,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,30 +4,21 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
* @module @stevenvo780/autologic
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { formalize, Autologic } from '@stevenvo780/autologic';
|
|
11
|
-
*
|
|
12
|
-
* // Uso stateless
|
|
13
|
-
* const result = formalize("Si llueve, la calle se moja.", {
|
|
14
|
-
* profile: 'classical.propositional',
|
|
15
|
-
* language: 'es',
|
|
16
|
-
* });
|
|
17
|
-
* console.log(result.stCode);
|
|
18
|
-
*
|
|
19
|
-
* // Uso con estado
|
|
20
|
-
* const al = new Autologic({ language: 'es' });
|
|
21
|
-
* const r = al.formalize("Todo humano es mortal. Sócrates es humano.");
|
|
22
|
-
* ```
|
|
23
7
|
*/
|
|
24
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.validateST = exports.emitST = exports.buildFormulas = exports.extractAtoms = exports.analyzeDiscourse = exports.segment = exports.Autologic = exports.formalize = void 0;
|
|
9
|
+
exports.validateST = exports.emitST = exports.buildFormulas = exports.extractAtoms = exports.analyzeDiscourse = exports.segment = exports.llmResultToST = exports.parseTextWithLLM = exports.Autologic = exports.DEFAULT_RULES = exports.lintNaturalLanguage = exports.formalizeWithLLM = exports.formalize = void 0;
|
|
26
10
|
// ── API pública principal ─────────────────────
|
|
27
11
|
var formalize_1 = require("./formalize");
|
|
28
12
|
Object.defineProperty(exports, "formalize", { enumerable: true, get: function () { return formalize_1.formalize; } });
|
|
13
|
+
Object.defineProperty(exports, "formalizeWithLLM", { enumerable: true, get: function () { return formalize_1.formalizeWithLLM; } });
|
|
14
|
+
var nl_linter_1 = require("./nl-linter");
|
|
15
|
+
Object.defineProperty(exports, "lintNaturalLanguage", { enumerable: true, get: function () { return nl_linter_1.lintNaturalLanguage; } });
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_RULES", { enumerable: true, get: function () { return nl_linter_1.DEFAULT_RULES; } });
|
|
29
17
|
var autologic_1 = require("./autologic");
|
|
30
18
|
Object.defineProperty(exports, "Autologic", { enumerable: true, get: function () { return autologic_1.Autologic; } });
|
|
19
|
+
var llm_parser_1 = require("./llm-parser");
|
|
20
|
+
Object.defineProperty(exports, "parseTextWithLLM", { enumerable: true, get: function () { return llm_parser_1.parseTextWithLLM; } });
|
|
21
|
+
Object.defineProperty(exports, "llmResultToST", { enumerable: true, get: function () { return llm_parser_1.llmResultToST; } });
|
|
31
22
|
// ── Utilidades expuestas ──────────────────────
|
|
32
23
|
var segmenter_1 = require("./segmenter");
|
|
33
24
|
Object.defineProperty(exports, "segment", { enumerable: true, get: function () { return segmenter_1.segment; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iDAAiD;AACjD,yCAA0D;AAAjD,sGAAA,SAAS,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAEpC,yCAAiE;AAAxD,gHAAA,mBAAmB,OAAA;AAAE,0GAAA,aAAa,OAAA;AAE3C,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,2CAA+D;AAAtD,8GAAA,gBAAgB,OAAA;AAAE,2GAAA,aAAa,OAAA;AAgCxC,iDAAiD;AACjD,yCAAsC;AAA7B,oGAAA,OAAO,OAAA;AAChB,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,qCAA0C;AAAjC,wGAAA,aAAa,OAAA;AACtB,qDAAgD;AAAvC,oGAAA,MAAM,OAAA;AACf,mDAAmD;AAA1C,uGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LogicNode } from './formula/ast';
|
|
2
|
+
import { LogicProfile } from './types';
|
|
3
|
+
export interface LLMConfig {
|
|
4
|
+
provider: 'openai' | 'anthropic' | 'gemini' | 'custom' | 'ollama' | 'web-distilled';
|
|
5
|
+
apiKey: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LLMParsedResult {
|
|
10
|
+
axioms: Array<{
|
|
11
|
+
name: string;
|
|
12
|
+
formulaJSON: LogicNode;
|
|
13
|
+
}>;
|
|
14
|
+
conclusions: Array<{
|
|
15
|
+
formulaJSON: LogicNode;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Llama a la API del LLM (usando fetch isomorfico) para abstraer el texto a AST.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseTextWithLLM(text: string, profile: LogicProfile, config: LLMConfig): Promise<LLMParsedResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Transforma la respuesta estructurada del LLM directamente a líneas de código ST seguras.
|
|
24
|
+
*/
|
|
25
|
+
export declare function llmResultToST(result: LLMParsedResult): {
|
|
26
|
+
formula: string;
|
|
27
|
+
type: 'axiom' | 'check';
|
|
28
|
+
}[];
|
|
29
|
+
//# sourceMappingURL=llm-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-parser.d.ts","sourceRoot":"","sources":["../src/llm-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAO,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,eAAe,CAAC;IACpF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACxD,WAAW,EAAE,KAAK,CAAC;QAAE,WAAW,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CAChD;AA2BD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,eAAe,CAAC,CAiFvH;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAA;CAAE,EAAE,CAYrG"}
|