import { BaseNode } from './BaseNode.js'; /** * AST node for evidence body containing statements * Represents: { statement1; statement2; ... } */ export class EvidenceBodyNode extends BaseNode { constructor(location = null) { super('EvidenceBody', location); this.statements = []; } /** * Add a statement to the evidence body * @param {BaseNode} statement - Statement to add */ addStatement(statement) { this.statements.push(statement); this.addChild(statement); } /** * Get all statements of a specific type * @param {string} type - Statement type to filter by * @returns {BaseNode[]} Filtered statements */ getStatementsOfType(type) { return this.statements.filter(stmt => stmt.type === type); } /** * Get all direct evidence statements * @returns {DirectEvidenceNode[]} Direct evidence statements */ getDirectEvidence() { return this.getStatementsOfType('DirectEvidence'); } /** * Get all pattern matching statements * @returns {PatternMatchNode[]} Pattern matching statements */ getPatternMatches() { return this.getStatementsOfType('PatternMatch'); } /** * Get all defeasible logic statements * @returns {DefeasibleLogicNode[]} Defeasible logic statements */ getDefeasibleLogic() { return this.getStatementsOfType('DefeasibleLogic'); } /** * Get all fusion statements * @returns {FusionNode[]} Fusion statements */ getFusions() { return this.getStatementsOfType('Fusion'); } /** * Validate the evidence body * @returns {string[]} Array of error messages */ validate() { const errors = []; // Validate each statement this.statements.forEach((stmt, index) => { const stmtErrors = stmt.validate ? stmt.validate() : []; errors.push(...stmtErrors.map(err => `Statement ${index + 1}: ${err}`)); }); return errors; } toString() { return `EvidenceBody(${this.statements.length} statements)`; } }