@nahisaho/musubix-wake-sleep 1.0.0 → 1.0.1
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/validation/index.d.ts +7 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +6 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/pattern-validator.d.ts +113 -0
- package/dist/validation/pattern-validator.d.ts.map +1 -0
- package/dist/validation/pattern-validator.js +297 -0
- package/dist/validation/pattern-validator.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,QAAQ;AACR,cAAc,YAAY,CAAC;AAE3B,4BAA4B;AAC5B,cAAc,iBAAiB,CAAC;AAEhC,6BAA6B;AAC7B,cAAc,kBAAkB,CAAC;AAEjC,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,kCAAkC;AAClC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,QAAQ;AACR,cAAc,YAAY,CAAC;AAE3B,4BAA4B;AAC5B,cAAc,iBAAiB,CAAC;AAEhC,6BAA6B;AAC7B,cAAc,kBAAkB,CAAC;AAEjC,+BAA+B;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,kCAAkC;AAClC,cAAc,qBAAqB,CAAC;AAEpC,iCAAiC;AACjC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Validation module for Wake-Sleep
|
|
3
|
+
* @traceability REQ-WAKE-001-F003
|
|
4
|
+
*/
|
|
5
|
+
export { PatternValidator } from './pattern-validator.js';
|
|
6
|
+
export type { PatternValidationConfig, PatternValidationResult } from './pattern-validator.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pattern Validator integrating ConsistencyValidator
|
|
3
|
+
* @traceability REQ-WAKE-001-F003, REQ-INT-002
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Validates patterns before they are added to the knowledge graph.
|
|
7
|
+
* Uses ConsistencyValidator from ontology-mcp for OWL constraint checking.
|
|
8
|
+
*/
|
|
9
|
+
import type { PatternCandidate } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Validation configuration
|
|
12
|
+
*/
|
|
13
|
+
export interface PatternValidationConfig {
|
|
14
|
+
/** Enable duplicate detection */
|
|
15
|
+
checkDuplicates: boolean;
|
|
16
|
+
/** Enable circular dependency detection */
|
|
17
|
+
checkCircular: boolean;
|
|
18
|
+
/** Enable disjoint class checking */
|
|
19
|
+
checkDisjoint: boolean;
|
|
20
|
+
/** Minimum confidence threshold */
|
|
21
|
+
minConfidence: number;
|
|
22
|
+
/** Maximum patterns with same name */
|
|
23
|
+
maxSameNamePatterns: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Validation result
|
|
27
|
+
*/
|
|
28
|
+
export interface PatternValidationResult {
|
|
29
|
+
valid: boolean;
|
|
30
|
+
patternId: string;
|
|
31
|
+
violations: PatternViolation[];
|
|
32
|
+
suggestions: string[];
|
|
33
|
+
confidence: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pattern violation
|
|
37
|
+
*/
|
|
38
|
+
export interface PatternViolation {
|
|
39
|
+
type: 'duplicate' | 'circular' | 'disjoint' | 'low-confidence' | 'name-collision';
|
|
40
|
+
severity: 'error' | 'warning' | 'info';
|
|
41
|
+
message: string;
|
|
42
|
+
relatedPatterns?: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* PatternValidator
|
|
46
|
+
*
|
|
47
|
+
* Validates patterns using OWL-based consistency checking.
|
|
48
|
+
* Integrates with ConsistencyValidator from @nahisaho/musubix-ontology-mcp.
|
|
49
|
+
*/
|
|
50
|
+
export declare class PatternValidator {
|
|
51
|
+
private config;
|
|
52
|
+
private patternIndex;
|
|
53
|
+
private nameIndex;
|
|
54
|
+
constructor(config?: Partial<PatternValidationConfig>);
|
|
55
|
+
/**
|
|
56
|
+
* Validate a pattern before adding to library
|
|
57
|
+
*/
|
|
58
|
+
validatePattern(pattern: PatternCandidate, existingPatterns: PatternCandidate[]): PatternValidationResult;
|
|
59
|
+
/**
|
|
60
|
+
* Validate multiple patterns in batch
|
|
61
|
+
*/
|
|
62
|
+
validateBatch(patterns: PatternCandidate[], existingPatterns: PatternCandidate[]): PatternValidationResult[];
|
|
63
|
+
/**
|
|
64
|
+
* Find duplicate patterns using structural comparison
|
|
65
|
+
*/
|
|
66
|
+
private findDuplicates;
|
|
67
|
+
/**
|
|
68
|
+
* Find patterns with the same name
|
|
69
|
+
*/
|
|
70
|
+
private findNameCollisions;
|
|
71
|
+
/**
|
|
72
|
+
* Find circular dependencies in pattern references
|
|
73
|
+
*/
|
|
74
|
+
private findCircularDependencies;
|
|
75
|
+
/**
|
|
76
|
+
* Find disjoint class violations
|
|
77
|
+
* Patterns from certain sources cannot be combined
|
|
78
|
+
*/
|
|
79
|
+
private findDisjointViolations;
|
|
80
|
+
/**
|
|
81
|
+
* Extract pattern references from structure
|
|
82
|
+
*/
|
|
83
|
+
private extractReferences;
|
|
84
|
+
/**
|
|
85
|
+
* Check if two patterns are structurally related
|
|
86
|
+
*/
|
|
87
|
+
private isStructurallyRelated;
|
|
88
|
+
/**
|
|
89
|
+
* Find longest common prefix between two strings
|
|
90
|
+
*/
|
|
91
|
+
private longestCommonPrefix;
|
|
92
|
+
/**
|
|
93
|
+
* Hash a structure for duplicate detection
|
|
94
|
+
*/
|
|
95
|
+
private hashStructure;
|
|
96
|
+
/**
|
|
97
|
+
* Calculate adjusted confidence based on violations
|
|
98
|
+
*/
|
|
99
|
+
private calculateAdjustedConfidence;
|
|
100
|
+
/**
|
|
101
|
+
* Update configuration
|
|
102
|
+
*/
|
|
103
|
+
updateConfig(config: Partial<PatternValidationConfig>): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get current configuration
|
|
106
|
+
*/
|
|
107
|
+
getConfig(): PatternValidationConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Clear internal caches
|
|
110
|
+
*/
|
|
111
|
+
clearCache(): void;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=pattern-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern-validator.d.ts","sourceRoot":"","sources":["../../src/validation/pattern-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,iCAAiC;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,2CAA2C;IAC3C,aAAa,EAAE,OAAO,CAAC;IACvB,qCAAqC;IACrC,aAAa,EAAE,OAAO,CAAC;IACvB,mCAAmC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;IAClF,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAaD;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,SAAS,CAAoC;gBAEzC,MAAM,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC;IAIrD;;OAEG;IACH,eAAe,CACb,OAAO,EAAE,gBAAgB,EACzB,gBAAgB,EAAE,gBAAgB,EAAE,GACnC,uBAAuB;IAkF1B;;OAEG;IACH,aAAa,CACX,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,gBAAgB,EAAE,gBAAgB,EAAE,GACnC,uBAAuB,EAAE;IAiB5B;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAS1B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAwBhC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAwB9B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAwBzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAU7B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAyBrB;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAuBnC;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI;IAI5D;;OAEG;IACH,SAAS,IAAI,uBAAuB;IAIpC;;OAEG;IACH,UAAU,IAAI,IAAI;CAInB"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pattern Validator integrating ConsistencyValidator
|
|
3
|
+
* @traceability REQ-WAKE-001-F003, REQ-INT-002
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Validates patterns before they are added to the knowledge graph.
|
|
7
|
+
* Uses ConsistencyValidator from ontology-mcp for OWL constraint checking.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default validation configuration
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_CONFIG = {
|
|
13
|
+
checkDuplicates: true,
|
|
14
|
+
checkCircular: true,
|
|
15
|
+
checkDisjoint: true,
|
|
16
|
+
minConfidence: 0.5,
|
|
17
|
+
maxSameNamePatterns: 3,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* PatternValidator
|
|
21
|
+
*
|
|
22
|
+
* Validates patterns using OWL-based consistency checking.
|
|
23
|
+
* Integrates with ConsistencyValidator from @nahisaho/musubix-ontology-mcp.
|
|
24
|
+
*/
|
|
25
|
+
export class PatternValidator {
|
|
26
|
+
config;
|
|
27
|
+
patternIndex = new Map();
|
|
28
|
+
nameIndex = new Map();
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate a pattern before adding to library
|
|
34
|
+
*/
|
|
35
|
+
validatePattern(pattern, existingPatterns) {
|
|
36
|
+
const violations = [];
|
|
37
|
+
const suggestions = [];
|
|
38
|
+
const patternId = pattern.id ?? pattern.name;
|
|
39
|
+
// 1. Check confidence threshold
|
|
40
|
+
if (pattern.confidence < this.config.minConfidence) {
|
|
41
|
+
violations.push({
|
|
42
|
+
type: 'low-confidence',
|
|
43
|
+
severity: 'warning',
|
|
44
|
+
message: `Pattern confidence ${pattern.confidence.toFixed(2)} is below threshold ${this.config.minConfidence}`,
|
|
45
|
+
});
|
|
46
|
+
suggestions.push(`Consider increasing pattern occurrences or improving extraction quality`);
|
|
47
|
+
}
|
|
48
|
+
// 2. Check for duplicates
|
|
49
|
+
if (this.config.checkDuplicates) {
|
|
50
|
+
const duplicates = this.findDuplicates(pattern, existingPatterns);
|
|
51
|
+
if (duplicates.length > 0) {
|
|
52
|
+
violations.push({
|
|
53
|
+
type: 'duplicate',
|
|
54
|
+
severity: 'error',
|
|
55
|
+
message: `Pattern is a duplicate of existing pattern(s)`,
|
|
56
|
+
relatedPatterns: duplicates,
|
|
57
|
+
});
|
|
58
|
+
suggestions.push(`Consider merging with existing pattern: ${duplicates[0]}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 3. Check for name collisions
|
|
62
|
+
const nameCollisions = this.findNameCollisions(pattern, existingPatterns);
|
|
63
|
+
if (nameCollisions.length >= this.config.maxSameNamePatterns) {
|
|
64
|
+
violations.push({
|
|
65
|
+
type: 'name-collision',
|
|
66
|
+
severity: 'warning',
|
|
67
|
+
message: `Pattern name "${pattern.name}" already used by ${nameCollisions.length} patterns`,
|
|
68
|
+
relatedPatterns: nameCollisions,
|
|
69
|
+
});
|
|
70
|
+
suggestions.push(`Consider using a more specific name or versioning: ${pattern.name}_v${nameCollisions.length + 1}`);
|
|
71
|
+
}
|
|
72
|
+
// 4. Check for circular dependencies (simplified)
|
|
73
|
+
if (this.config.checkCircular) {
|
|
74
|
+
const circularIssues = this.findCircularDependencies(pattern, existingPatterns);
|
|
75
|
+
if (circularIssues.length > 0) {
|
|
76
|
+
violations.push({
|
|
77
|
+
type: 'circular',
|
|
78
|
+
severity: 'error',
|
|
79
|
+
message: `Pattern creates circular dependency`,
|
|
80
|
+
relatedPatterns: circularIssues,
|
|
81
|
+
});
|
|
82
|
+
suggestions.push(`Break the cycle by removing reference to: ${circularIssues[0]}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 5. Check for disjoint class violations
|
|
86
|
+
if (this.config.checkDisjoint) {
|
|
87
|
+
const disjointIssues = this.findDisjointViolations(pattern, existingPatterns);
|
|
88
|
+
if (disjointIssues.length > 0) {
|
|
89
|
+
violations.push({
|
|
90
|
+
type: 'disjoint',
|
|
91
|
+
severity: 'error',
|
|
92
|
+
message: `Pattern violates disjoint class constraint`,
|
|
93
|
+
relatedPatterns: disjointIssues,
|
|
94
|
+
});
|
|
95
|
+
suggestions.push(`Pattern cannot belong to both categories. Choose one.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Calculate overall validity
|
|
99
|
+
const hasErrors = violations.some(v => v.severity === 'error');
|
|
100
|
+
const adjustedConfidence = this.calculateAdjustedConfidence(pattern.confidence, violations);
|
|
101
|
+
return {
|
|
102
|
+
valid: !hasErrors,
|
|
103
|
+
patternId,
|
|
104
|
+
violations,
|
|
105
|
+
suggestions,
|
|
106
|
+
confidence: adjustedConfidence,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validate multiple patterns in batch
|
|
111
|
+
*/
|
|
112
|
+
validateBatch(patterns, existingPatterns) {
|
|
113
|
+
const results = [];
|
|
114
|
+
let accumulator = [...existingPatterns];
|
|
115
|
+
for (const pattern of patterns) {
|
|
116
|
+
const result = this.validatePattern(pattern, accumulator);
|
|
117
|
+
results.push(result);
|
|
118
|
+
// Add valid patterns to accumulator for subsequent checks
|
|
119
|
+
if (result.valid) {
|
|
120
|
+
accumulator.push(pattern);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return results;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Find duplicate patterns using structural comparison
|
|
127
|
+
*/
|
|
128
|
+
findDuplicates(pattern, existingPatterns) {
|
|
129
|
+
const duplicates = [];
|
|
130
|
+
const patternHash = this.hashStructure(pattern.structure);
|
|
131
|
+
for (const existing of existingPatterns) {
|
|
132
|
+
const existingHash = this.hashStructure(existing.structure);
|
|
133
|
+
if (patternHash === existingHash) {
|
|
134
|
+
duplicates.push(existing.id ?? existing.name);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return duplicates;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Find patterns with the same name
|
|
141
|
+
*/
|
|
142
|
+
findNameCollisions(pattern, existingPatterns) {
|
|
143
|
+
return existingPatterns
|
|
144
|
+
.filter(p => p.name === pattern.name)
|
|
145
|
+
.map(p => p.id ?? p.name);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Find circular dependencies in pattern references
|
|
149
|
+
*/
|
|
150
|
+
findCircularDependencies(pattern, existingPatterns) {
|
|
151
|
+
const patternId = pattern.id ?? pattern.name;
|
|
152
|
+
const circularRefs = [];
|
|
153
|
+
// Simple check: look for patterns that reference this pattern
|
|
154
|
+
// and that this pattern also references
|
|
155
|
+
const referencedByPattern = this.extractReferences(pattern);
|
|
156
|
+
for (const existingPattern of existingPatterns) {
|
|
157
|
+
const existingId = existingPattern.id ?? existingPattern.name;
|
|
158
|
+
const existingRefs = this.extractReferences(existingPattern);
|
|
159
|
+
// Check if mutual reference exists
|
|
160
|
+
if (referencedByPattern.includes(existingId) && existingRefs.includes(patternId)) {
|
|
161
|
+
circularRefs.push(existingId);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return circularRefs;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Find disjoint class violations
|
|
168
|
+
* Patterns from certain sources cannot be combined
|
|
169
|
+
*/
|
|
170
|
+
findDisjointViolations(pattern, existingPatterns) {
|
|
171
|
+
const violations = [];
|
|
172
|
+
// Define disjoint source pairs
|
|
173
|
+
const disjointPairs = [
|
|
174
|
+
// No current disjoint pairs defined
|
|
175
|
+
// Add domain-specific constraints here
|
|
176
|
+
];
|
|
177
|
+
for (const [source1, source2] of disjointPairs) {
|
|
178
|
+
if (pattern.source === source1) {
|
|
179
|
+
const conflicting = existingPatterns.filter(p => p.source === source2 && this.isStructurallyRelated(pattern, p));
|
|
180
|
+
violations.push(...conflicting.map(p => p.id ?? p.name));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return violations;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Extract pattern references from structure
|
|
187
|
+
*/
|
|
188
|
+
extractReferences(pattern) {
|
|
189
|
+
const refs = [];
|
|
190
|
+
const structure = pattern.structure;
|
|
191
|
+
if (typeof structure === 'object' && structure !== null) {
|
|
192
|
+
const traverse = (obj) => {
|
|
193
|
+
if (typeof obj !== 'object' || obj === null)
|
|
194
|
+
return;
|
|
195
|
+
if (Array.isArray(obj)) {
|
|
196
|
+
obj.forEach(traverse);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
const record = obj;
|
|
200
|
+
if (typeof record['$ref'] === 'string') {
|
|
201
|
+
refs.push(record['$ref']);
|
|
202
|
+
}
|
|
203
|
+
Object.values(record).forEach(traverse);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
traverse(structure);
|
|
207
|
+
}
|
|
208
|
+
return refs;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Check if two patterns are structurally related
|
|
212
|
+
*/
|
|
213
|
+
isStructurallyRelated(p1, p2) {
|
|
214
|
+
// Simple check: compare pattern names for similarity
|
|
215
|
+
const name1 = p1.name.toLowerCase();
|
|
216
|
+
const name2 = p2.name.toLowerCase();
|
|
217
|
+
// Check for common prefixes or suffixes
|
|
218
|
+
const commonPrefix = this.longestCommonPrefix(name1, name2);
|
|
219
|
+
return commonPrefix.length > 3;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Find longest common prefix between two strings
|
|
223
|
+
*/
|
|
224
|
+
longestCommonPrefix(s1, s2) {
|
|
225
|
+
let i = 0;
|
|
226
|
+
while (i < s1.length && i < s2.length && s1[i] === s2[i]) {
|
|
227
|
+
i++;
|
|
228
|
+
}
|
|
229
|
+
return s1.substring(0, i);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Hash a structure for duplicate detection
|
|
233
|
+
*/
|
|
234
|
+
hashStructure(structure) {
|
|
235
|
+
// Deterministic JSON stringification
|
|
236
|
+
const normalize = (obj) => {
|
|
237
|
+
if (typeof obj !== 'object' || obj === null)
|
|
238
|
+
return obj;
|
|
239
|
+
if (Array.isArray(obj))
|
|
240
|
+
return obj.map(normalize);
|
|
241
|
+
const sorted = {};
|
|
242
|
+
for (const key of Object.keys(obj).sort()) {
|
|
243
|
+
sorted[key] = normalize(obj[key]);
|
|
244
|
+
}
|
|
245
|
+
return sorted;
|
|
246
|
+
};
|
|
247
|
+
const normalized = JSON.stringify(normalize(structure));
|
|
248
|
+
// Simple hash function
|
|
249
|
+
let hash = 0;
|
|
250
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
251
|
+
const char = normalized.charCodeAt(i);
|
|
252
|
+
hash = ((hash << 5) - hash) + char;
|
|
253
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
254
|
+
}
|
|
255
|
+
return hash.toString(16);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Calculate adjusted confidence based on violations
|
|
259
|
+
*/
|
|
260
|
+
calculateAdjustedConfidence(originalConfidence, violations) {
|
|
261
|
+
let adjustment = 0;
|
|
262
|
+
for (const violation of violations) {
|
|
263
|
+
switch (violation.severity) {
|
|
264
|
+
case 'error':
|
|
265
|
+
adjustment -= 0.3;
|
|
266
|
+
break;
|
|
267
|
+
case 'warning':
|
|
268
|
+
adjustment -= 0.1;
|
|
269
|
+
break;
|
|
270
|
+
case 'info':
|
|
271
|
+
adjustment -= 0.05;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return Math.max(0, Math.min(1, originalConfidence + adjustment));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Update configuration
|
|
279
|
+
*/
|
|
280
|
+
updateConfig(config) {
|
|
281
|
+
this.config = { ...this.config, ...config };
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get current configuration
|
|
285
|
+
*/
|
|
286
|
+
getConfig() {
|
|
287
|
+
return { ...this.config };
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Clear internal caches
|
|
291
|
+
*/
|
|
292
|
+
clearCache() {
|
|
293
|
+
this.patternIndex.clear();
|
|
294
|
+
this.nameIndex.clear();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=pattern-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern-validator.js","sourceRoot":"","sources":["../../src/validation/pattern-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyCH;;GAEG;AACH,MAAM,cAAc,GAA4B;IAC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