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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""
|
| 4 |
+
STRUCTURAL INQUIRY SYSTEM v2.5
|
| 5 |
+
Engineering-Focused Knowledge Discovery with Concrete Improvements
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from enum import Enum
|
| 9 |
+
from dataclasses import dataclass, field
|
| 10 |
+
from typing import List, Dict, Any, Optional, Tuple, Mapping, Callable
|
| 11 |
+
import hashlib
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
from types import MappingProxyType
|
| 14 |
+
import numpy as np
|
| 15 |
+
|
| 16 |
+
# === CORE SYMBOLS ===
|
| 17 |
+
KNOWLEDGE_NODE = "●"
|
| 18 |
+
PATTERN_RECOGNITION = "⟁"
|
| 19 |
+
INQUIRY_MARKER = "?"
|
| 20 |
+
VALIDATION_SYMBOL = "✓"
|
| 21 |
+
|
| 22 |
+
# === KNOWLEDGE STATE TYPES ===
|
| 23 |
+
|
| 24 |
+
class KnowledgeStateType(Enum):
|
| 25 |
+
"""Knowledge state types with clear semantics"""
|
| 26 |
+
PATTERN_DETECTION = "pattern_detection"
|
| 27 |
+
DATA_CORRELATION = "data_correlation"
|
| 28 |
+
CONTEXTUAL_ALIGNMENT = "contextual_alignment"
|
| 29 |
+
METHODOLOGICAL_STRUCTURE = "methodological_structure"
|
| 30 |
+
SOURCE_VERIFICATION = "source_verification"
|
| 31 |
+
TEMPORAL_CONSISTENCY = "temporal_consistency"
|
| 32 |
+
CROSS_DOMAIN_SYNTHESIS = "cross_domain_synthesis"
|
| 33 |
+
KNOWLEDGE_GAP_IDENTIFICATION = "knowledge_gap_identification"
|
| 34 |
+
|
| 35 |
+
@dataclass(frozen=True)
|
| 36 |
+
class KnowledgeState:
|
| 37 |
+
"""Immutable knowledge state with provenance tracking"""
|
| 38 |
+
state_id: str
|
| 39 |
+
state_type: KnowledgeStateType
|
| 40 |
+
confidence_score: float
|
| 41 |
+
confidence_provenance: str # Track where confidence came from
|
| 42 |
+
methodological_rigor: float
|
| 43 |
+
data_patterns: Tuple[float, ...]
|
| 44 |
+
knowledge_domains: Tuple[str, ...]
|
| 45 |
+
temporal_markers: Tuple[str, ...]
|
| 46 |
+
research_constraints: Tuple[str, ...]
|
| 47 |
+
structural_description: str
|
| 48 |
+
validation_signature: str
|
| 49 |
+
state_hash: str = field(init=False)
|
| 50 |
+
|
| 51 |
+
def __post_init__(self):
|
| 52 |
+
hash_input = f"{self.state_id}:{self.state_type.value}:{self.confidence_score}:"
|
| 53 |
+
hash_input += f"{self.confidence_provenance}:{self.methodological_rigor}:"
|
| 54 |
+
hash_input += ":".join(str(v) for v in self.data_patterns[:10])
|
| 55 |
+
hash_input += ":".join(self.knowledge_domains)
|
| 56 |
+
|
| 57 |
+
state_hash = hashlib.sha3_512(hash_input.encode()).hexdigest()[:32]
|
| 58 |
+
object.__setattr__(self, 'state_hash', state_hash)
|
| 59 |
+
|
| 60 |
+
# === INQUIRY CATEGORIES ===
|
| 61 |
+
|
| 62 |
+
class InquiryCategory(Enum):
|
| 63 |
+
"""Inquiry categories with clear prioritization semantics"""
|
| 64 |
+
CONFIDENCE_DISCREPANCY_ANALYSIS = "confidence_discrepancy_analysis"
|
| 65 |
+
METHODOLOGICAL_CONSISTENCY_CHECK = "methodological_consistency_check"
|
| 66 |
+
PATTERN_ANOMALY_DETECTION = "pattern_anomaly_detection"
|
| 67 |
+
TEMPORAL_ALIGNMENT_VALIDATION = "temporal_alignment_validation"
|
| 68 |
+
SOURCE_RELIABILITY_ASSESSMENT = "source_reliability_assessment"
|
| 69 |
+
CROSS_REFERENCE_VALIDATION = "cross_reference_validation"
|
| 70 |
+
KNOWLEDGE_COMPLETENESS_EVALUATION = "knowledge_completeness_evaluation"
|
| 71 |
+
|
| 72 |
+
# === PLUGGABLE ANALYSIS INTERFACE ===
|
| 73 |
+
|
| 74 |
+
class AnalysisResult:
|
| 75 |
+
"""Structured analysis result for inquiry generation"""
|
| 76 |
+
def __init__(
|
| 77 |
+
self,
|
| 78 |
+
category: InquiryCategory,
|
| 79 |
+
basis_code: str,
|
| 80 |
+
basis_kwargs: Dict[str, Any],
|
| 81 |
+
verification_requirements: List[str],
|
| 82 |
+
investigation_confidence: float,
|
| 83 |
+
research_completion_estimate: float,
|
| 84 |
+
priority_score: float
|
| 85 |
+
):
|
| 86 |
+
self.category = category
|
| 87 |
+
self.basis_code = basis_code
|
| 88 |
+
self.basis_kwargs = basis_kwargs
|
| 89 |
+
self.verification_requirements = verification_requirements
|
| 90 |
+
self.investigation_confidence = investigation_confidence
|
| 91 |
+
self.research_completion_estimate = research_completion_estimate
|
| 92 |
+
self.priority_score = priority_score
|
| 93 |
+
|
| 94 |
+
class InquiryAnalyzer:
|
| 95 |
+
"""Protocol for pluggable analysis"""
|
| 96 |
+
def analyze(self, state: KnowledgeState) -> List[AnalysisResult]:
|
| 97 |
+
"""Analyze state and return multiple potential inquiries"""
|
| 98 |
+
raise NotImplementedError
|
| 99 |
+
|
| 100 |
+
# === DEFAULT ANALYZER IMPLEMENTATION ===
|
| 101 |
+
|
| 102 |
+
class DefaultInquiryAnalyzer(InquiryAnalyzer):
|
| 103 |
+
"""Default analyzer that generates multiple inquiry candidates"""
|
| 104 |
+
|
| 105 |
+
def __init__(self, basis_templates: Dict[str, Dict[str, Any]]):
|
| 106 |
+
self.basis_templates = basis_templates
|
| 107 |
+
|
| 108 |
+
def analyze(self, state: KnowledgeState) -> List[AnalysisResult]:
|
| 109 |
+
"""Generate multiple inquiry candidates from state"""
|
| 110 |
+
results = []
|
| 111 |
+
|
| 112 |
+
# Check multiple independent criteria
|
| 113 |
+
if state.confidence_score < 0.7:
|
| 114 |
+
results.append(self._confidence_analysis(state))
|
| 115 |
+
|
| 116 |
+
if state.methodological_rigor < 0.65:
|
| 117 |
+
results.append(self._methodological_analysis(state))
|
| 118 |
+
|
| 119 |
+
if len(state.data_patterns) < 8:
|
| 120 |
+
results.append(self._pattern_analysis(state))
|
| 121 |
+
|
| 122 |
+
if len(state.temporal_markers) < 3:
|
| 123 |
+
results.append(self._temporal_analysis(state))
|
| 124 |
+
|
| 125 |
+
if len(state.knowledge_domains) > 2:
|
| 126 |
+
results.append(self._cross_domain_analysis(state))
|
| 127 |
+
|
| 128 |
+
# Always provide at least one analysis
|
| 129 |
+
if not results:
|
| 130 |
+
results.append(self._default_analysis(state))
|
| 131 |
+
|
| 132 |
+
return results
|
| 133 |
+
|
| 134 |
+
def _confidence_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 135 |
+
"""Analyze confidence discrepancies"""
|
| 136 |
+
confidence_factor = max(0.1, 0.8 - state.confidence_score)
|
| 137 |
+
return AnalysisResult(
|
| 138 |
+
category=InquiryCategory.CONFIDENCE_DISCREPANCY_ANALYSIS,
|
| 139 |
+
basis_code="CONFIDENCE_ANOMALY_INVESTIGATION",
|
| 140 |
+
basis_kwargs={
|
| 141 |
+
"score": state.confidence_score * 100,
|
| 142 |
+
"expected": 75.0,
|
| 143 |
+
"provenance": state.confidence_provenance
|
| 144 |
+
},
|
| 145 |
+
verification_requirements=[
|
| 146 |
+
"statistical_reanalysis",
|
| 147 |
+
"source_review",
|
| 148 |
+
"methodology_audit"
|
| 149 |
+
],
|
| 150 |
+
investigation_confidence=confidence_factor,
|
| 151 |
+
research_completion_estimate=self._calculate_completion_estimate(3, confidence_factor),
|
| 152 |
+
priority_score=self._calculate_priority_score(confidence_factor, 0.9)
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
def _methodological_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 156 |
+
"""Analyze methodological issues"""
|
| 157 |
+
rigor_factor = max(0.1, 0.7 - state.methodological_rigor)
|
| 158 |
+
return AnalysisResult(
|
| 159 |
+
category=InquiryCategory.METHODOLOGICAL_CONSISTENCY_CHECK,
|
| 160 |
+
basis_code="METHODOLOGICAL_CONSISTENCY_QUESTION",
|
| 161 |
+
basis_kwargs={
|
| 162 |
+
"rigor": state.methodological_rigor * 100,
|
| 163 |
+
"method_type": "research_protocol"
|
| 164 |
+
},
|
| 165 |
+
verification_requirements=[
|
| 166 |
+
"protocol_review",
|
| 167 |
+
"reproducibility_check",
|
| 168 |
+
"peer_validation"
|
| 169 |
+
],
|
| 170 |
+
investigation_confidence=rigor_factor,
|
| 171 |
+
research_completion_estimate=self._calculate_completion_estimate(3, rigor_factor),
|
| 172 |
+
priority_score=self._calculate_priority_score(rigor_factor, 0.8)
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
def _pattern_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 176 |
+
"""Analyze pattern anomalies"""
|
| 177 |
+
pattern_factor = len(state.data_patterns) / 10.0
|
| 178 |
+
return AnalysisResult(
|
| 179 |
+
category=InquiryCategory.PATTERN_ANOMALY_DETECTION,
|
| 180 |
+
basis_code="PATTERN_DEVIATION_ANALYSIS",
|
| 181 |
+
basis_kwargs={
|
| 182 |
+
"pattern_completeness": pattern_factor * 100,
|
| 183 |
+
"expected_patterns": 8
|
| 184 |
+
},
|
| 185 |
+
verification_requirements=[
|
| 186 |
+
"pattern_completeness_check",
|
| 187 |
+
"data_collection_review",
|
| 188 |
+
"statistical_validation"
|
| 189 |
+
],
|
| 190 |
+
investigation_confidence=1.0 - pattern_factor,
|
| 191 |
+
research_completion_estimate=self._calculate_completion_estimate(3, pattern_factor),
|
| 192 |
+
priority_score=self._calculate_priority_score(1.0 - pattern_factor, 0.7)
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
def _temporal_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 196 |
+
"""Analyze temporal issues"""
|
| 197 |
+
temporal_factor = len(state.temporal_markers) / 3.0
|
| 198 |
+
return AnalysisResult(
|
| 199 |
+
category=InquiryCategory.TEMPORAL_ALIGNMENT_VALIDATION,
|
| 200 |
+
basis_code="TEMPORAL_CONSISTENCY_CHECK",
|
| 201 |
+
basis_kwargs={
|
| 202 |
+
"marker_count": len(state.temporal_markers),
|
| 203 |
+
"expected_markers": 3
|
| 204 |
+
},
|
| 205 |
+
verification_requirements=[
|
| 206 |
+
"temporal_sequence_verification",
|
| 207 |
+
"chronological_consistency_check"
|
| 208 |
+
],
|
| 209 |
+
investigation_confidence=1.0 - temporal_factor,
|
| 210 |
+
research_completion_estimate=self._calculate_completion_estimate(2, temporal_factor),
|
| 211 |
+
priority_score=self._calculate_priority_score(1.0 - temporal_factor, 0.6)
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
def _cross_domain_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 215 |
+
"""Analyze cross-domain issues"""
|
| 216 |
+
domain_factor = min(1.0, len(state.knowledge_domains) / 5.0)
|
| 217 |
+
return AnalysisResult(
|
| 218 |
+
category=InquiryCategory.CROSS_REFERENCE_VALIDATION,
|
| 219 |
+
basis_code="CROSS_DOMAIN_ALIGNMENT_CHECK",
|
| 220 |
+
basis_kwargs={
|
| 221 |
+
"domain_count": len(state.knowledge_domains),
|
| 222 |
+
"domains": list(state.knowledge_domains)[:3]
|
| 223 |
+
},
|
| 224 |
+
verification_requirements=[
|
| 225 |
+
"cross_domain_correlation",
|
| 226 |
+
"independent_verification"
|
| 227 |
+
],
|
| 228 |
+
investigation_confidence=domain_factor,
|
| 229 |
+
research_completion_estimate=self._calculate_completion_estimate(2, domain_factor),
|
| 230 |
+
priority_score=self._calculate_priority_score(domain_factor, 0.5)
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
def _default_analysis(self, state: KnowledgeState) -> AnalysisResult:
|
| 234 |
+
"""Default analysis for well-formed states"""
|
| 235 |
+
return AnalysisResult(
|
| 236 |
+
category=InquiryCategory.KNOWLEDGE_COMPLETENESS_EVALUATION,
|
| 237 |
+
basis_code="BASELINE_VERIFICATION",
|
| 238 |
+
basis_kwargs={
|
| 239 |
+
"confidence_score": state.confidence_score * 100,
|
| 240 |
+
"rigor_score": state.methodological_rigor * 100
|
| 241 |
+
},
|
| 242 |
+
verification_requirements=["comprehensive_review"],
|
| 243 |
+
investigation_confidence=0.3,
|
| 244 |
+
research_completion_estimate=0.9,
|
| 245 |
+
priority_score=2.0 # Low priority baseline check
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
def _calculate_completion_estimate(self, requirement_count: int, confidence: float) -> float:
|
| 249 |
+
"""Calculate research completion estimate"""
|
| 250 |
+
base = 0.5
|
| 251 |
+
requirement_impact = 0.9 ** requirement_count
|
| 252 |
+
confidence_impact = confidence * 0.4
|
| 253 |
+
return min(0.95, base * requirement_impact + confidence_impact)
|
| 254 |
+
|
| 255 |
+
def _calculate_priority_score(self, investigation_confidence: float, weight: float) -> float:
|
| 256 |
+
"""Calculate priority score with clear semantics"""
|
| 257 |
+
base_score = investigation_confidence * weight
|
| 258 |
+
return round(base_score * 10, 2)
|
| 259 |
+
|
| 260 |
+
# === INQUIRY BASIS TEMPLATES ===
|
| 261 |
+
|
| 262 |
+
INQUIRY_BASIS_TEMPLATES = {
|
| 263 |
+
"CONFIDENCE_ANOMALY_INVESTIGATION": {
|
| 264 |
+
"template": "Confidence score of {score}% ({provenance}) differs from expected baseline of {expected}%",
|
| 265 |
+
"investigation_focus": "confidence_validation"
|
| 266 |
+
},
|
| 267 |
+
"METHODOLOGICAL_CONSISTENCY_QUESTION": {
|
| 268 |
+
"template": "Methodological rigor rating of {rigor}% suggests review of {method_type} may be beneficial",
|
| 269 |
+
"investigation_focus": "methodological_review"
|
| 270 |
+
},
|
| 271 |
+
"PATTERN_DEVIATION_ANALYSIS": {
|
| 272 |
+
"template": "Pattern completeness at {pattern_completeness}% with {expected_patterns} expected patterns",
|
| 273 |
+
"investigation_focus": "pattern_analysis"
|
| 274 |
+
},
|
| 275 |
+
"TEMPORAL_CONSISTENCY_CHECK": {
|
| 276 |
+
"template": "Temporal markers: {marker_count} present, {expected_markers} expected",
|
| 277 |
+
"investigation_focus": "temporal_validation"
|
| 278 |
+
},
|
| 279 |
+
"CROSS_DOMAIN_ALIGNMENT_CHECK": {
|
| 280 |
+
"template": "Cross-domain analysis across {domain_count} domains: {domains}",
|
| 281 |
+
"investigation_focus": "cross_domain_validation"
|
| 282 |
+
},
|
| 283 |
+
"BASELINE_VERIFICATION": {
|
| 284 |
+
"template": "Baseline verification: confidence={confidence_score}%, rigor={rigor_score}%",
|
| 285 |
+
"investigation_focus": "comprehensive_review"
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
# === INQUIRY ARTIFACT ===
|
| 290 |
+
|
| 291 |
+
@dataclass(frozen=True)
|
| 292 |
+
class InquiryArtifact:
|
| 293 |
+
"""Deterministic inquiry artifact with robust priority calculation"""
|
| 294 |
+
artifact_id: str
|
| 295 |
+
source_state_hash: str
|
| 296 |
+
inquiry_category: InquiryCategory
|
| 297 |
+
investigation_priority: int # 1-10 scale with clear semantics
|
| 298 |
+
knowledge_domains_involved: Tuple[str, ...]
|
| 299 |
+
basis_code: str
|
| 300 |
+
inquiry_description: str
|
| 301 |
+
verification_requirements: Tuple[str, ...]
|
| 302 |
+
investigation_confidence: float
|
| 303 |
+
research_completion_estimate: float
|
| 304 |
+
confidence_provenance: str
|
| 305 |
+
artifact_hash: str
|
| 306 |
+
creation_context: 'CreationContext'
|
| 307 |
+
|
| 308 |
+
@classmethod
|
| 309 |
+
def create(
|
| 310 |
+
cls,
|
| 311 |
+
knowledge_state: KnowledgeState,
|
| 312 |
+
analysis_result: AnalysisResult,
|
| 313 |
+
basis_templates: Dict[str, Dict[str, Any]],
|
| 314 |
+
creation_context: 'CreationContext'
|
| 315 |
+
) -> 'InquiryArtifact':
|
| 316 |
+
"""Create inquiry artifact with deterministic hash"""
|
| 317 |
+
|
| 318 |
+
# Format inquiry description
|
| 319 |
+
template_data = basis_templates.get(analysis_result.basis_code, {})
|
| 320 |
+
description_template = template_data.get("template", "Analysis required")
|
| 321 |
+
inquiry_description = description_template.format(**analysis_result.basis_kwargs)
|
| 322 |
+
|
| 323 |
+
# Calculate deterministic priority (1-10)
|
| 324 |
+
priority_value = max(1, min(10, int(round(analysis_result.priority_score))))
|
| 325 |
+
|
| 326 |
+
# Generate deterministic hash
|
| 327 |
+
hash_input = f"{knowledge_state.state_hash}:{analysis_result.category.value}:"
|
| 328 |
+
hash_input += f"{analysis_result.basis_code}:{priority_value}:"
|
| 329 |
+
hash_input += ":".join(analysis_result.verification_requirements)
|
| 330 |
+
hash_input += creation_context.context_hash
|
| 331 |
+
|
| 332 |
+
artifact_hash = hashlib.sha3_512(hash_input.encode()).hexdigest()[:32]
|
| 333 |
+
artifact_id = f"inq_{artifact_hash[:16]}"
|
| 334 |
+
|
| 335 |
+
return cls(
|
| 336 |
+
artifact_id=artifact_id,
|
| 337 |
+
source_state_hash=knowledge_state.state_hash,
|
| 338 |
+
inquiry_category=analysis_result.category,
|
| 339 |
+
investigation_priority=priority_value,
|
| 340 |
+
knowledge_domains_involved=knowledge_state.knowledge_domains,
|
| 341 |
+
basis_code=analysis_result.basis_code,
|
| 342 |
+
inquiry_description=inquiry_description,
|
| 343 |
+
verification_requirements=tuple(analysis_result.verification_requirements),
|
| 344 |
+
investigation_confidence=analysis_result.investigation_confidence,
|
| 345 |
+
research_completion_estimate=analysis_result.research_completion_estimate,
|
| 346 |
+
confidence_provenance=knowledge_state.confidence_provenance,
|
| 347 |
+
artifact_hash=artifact_hash,
|
| 348 |
+
creation_context=creation_context
|
| 349 |
+
)
|
| 350 |
+
|
| 351 |
+
def reference_information(self) -> Mapping[str, Any]:
|
| 352 |
+
"""Immutable reference information"""
|
| 353 |
+
return MappingProxyType({
|
| 354 |
+
"artifact_id": self.artifact_id,
|
| 355 |
+
"source_state": self.source_state_hash[:12],
|
| 356 |
+
"inquiry_category": self.inquiry_category.value,
|
| 357 |
+
"investigation_priority": self.investigation_priority,
|
| 358 |
+
"priority_semantics": self._priority_semantics(),
|
| 359 |
+
"knowledge_domains": list(self.knowledge_domains_involved),
|
| 360 |
+
"basis": {
|
| 361 |
+
"code": self.basis_code,
|
| 362 |
+
"description": self.inquiry_description,
|
| 363 |
+
"confidence_provenance": self.confidence_provenance
|
| 364 |
+
},
|
| 365 |
+
"verification_requirements": list(self.verification_requirements),
|
| 366 |
+
"investigation_confidence": round(self.investigation_confidence, 3),
|
| 367 |
+
"research_completion_estimate": round(self.research_completion_estimate, 3),
|
| 368 |
+
"artifact_hash": self.artifact_hash,
|
| 369 |
+
"creation_context": self.creation_context.reference_data()
|
| 370 |
+
})
|
| 371 |
+
|
| 372 |
+
def _priority_semantics(self) -> str:
|
| 373 |
+
"""Document priority semantics"""
|
| 374 |
+
if self.investigation_priority >= 9:
|
| 375 |
+
return "critical_immediate_attention"
|
| 376 |
+
elif self.investigation_priority >= 7:
|
| 377 |
+
return "high_priority_review"
|
| 378 |
+
elif self.investigation_priority >= 5:
|
| 379 |
+
return "moderate_priority"
|
| 380 |
+
elif self.investigation_priority >= 3:
|
| 381 |
+
return "low_priority_backlog"
|
| 382 |
+
else:
|
| 383 |
+
return "informational_only"
|
| 384 |
+
|
| 385 |
+
# === CREATION CONTEXT ===
|
| 386 |
+
|
| 387 |
+
@dataclass(frozen=True)
|
| 388 |
+
class CreationContext:
|
| 389 |
+
"""Immutable creation context"""
|
| 390 |
+
system_version: str
|
| 391 |
+
generation_timestamp: str
|
| 392 |
+
research_environment: str
|
| 393 |
+
deterministic_seed: Optional[int]
|
| 394 |
+
context_hash: str = field(init=False)
|
| 395 |
+
|
| 396 |
+
def __post_init__(self):
|
| 397 |
+
hash_input = f"{self.system_version}:{self.generation_timestamp}:"
|
| 398 |
+
hash_input += f"{self.research_environment}:{self.deterministic_seed or 'none'}"
|
| 399 |
+
|
| 400 |
+
context_hash = hashlib.sha3_512(hash_input.encode()).hexdigest()[:32]
|
| 401 |
+
object.__setattr__(self, 'context_hash', context_hash)
|
| 402 |
+
|
| 403 |
+
@classmethod
|
| 404 |
+
def create(
|
| 405 |
+
cls,
|
| 406 |
+
research_environment: str = "knowledge_discovery_system",
|
| 407 |
+
deterministic_seed: Optional[int] = None,
|
| 408 |
+
clock_source: Callable[[], datetime] = datetime.now
|
| 409 |
+
) -> 'CreationContext':
|
| 410 |
+
"""Factory method with optional determinism"""
|
| 411 |
+
return cls(
|
| 412 |
+
system_version="structural_inquiry_v2.5",
|
| 413 |
+
generation_timestamp=clock_source().isoformat(),
|
| 414 |
+
research_environment=research_environment,
|
| 415 |
+
deterministic_seed=deterministic_seed
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
def reference_data(self) -> Mapping[str, Any]:
|
| 419 |
+
return MappingProxyType({
|
| 420 |
+
"system_version": self.system_version,
|
| 421 |
+
"generation_timestamp": self.generation_timestamp,
|
| 422 |
+
"research_environment": self.research_environment,
|
| 423 |
+
"deterministic_mode": self.deterministic_seed is not None,
|
| 424 |
+
"context_hash": self.context_hash[:12]
|
| 425 |
+
})
|
| 426 |
+
|
| 427 |
+
# === INQUIRY GENERATOR ===
|
| 428 |
+
|
| 429 |
+
class InquiryGenerator:
|
| 430 |
+
"""
|
| 431 |
+
Deterministic inquiry generator with pluggable analysis
|
| 432 |
+
"""
|
| 433 |
+
|
| 434 |
+
def __init__(
|
| 435 |
+
self,
|
| 436 |
+
analyzer: Optional[InquiryAnalyzer] = None,
|
| 437 |
+
creation_context: Optional[CreationContext] = None,
|
| 438 |
+
deterministic_seed: Optional[int] = None
|
| 439 |
+
):
|
| 440 |
+
self.analyzer = analyzer or DefaultInquiryAnalyzer(INQUIRY_BASIS_TEMPLATES)
|
| 441 |
+
self.creation_context = creation_context or CreationContext.create(
|
| 442 |
+
deterministic_seed=deterministic_seed
|
| 443 |
+
)
|
| 444 |
+
self.generated_inquiries: List[InquiryArtifact] = []
|
| 445 |
+
|
| 446 |
+
# Set deterministic seed if provided
|
| 447 |
+
if deterministic_seed is not None:
|
| 448 |
+
np.random.seed(deterministic_seed)
|
| 449 |
+
|
| 450 |
+
def generate_inquiries(
|
| 451 |
+
self,
|
| 452 |
+
knowledge_states: Tuple[KnowledgeState, ...],
|
| 453 |
+
confidence_threshold: float = 0.7
|
| 454 |
+
) -> Tuple[InquiryArtifact, ...]:
|
| 455 |
+
"""Generate inquiries from knowledge states"""
|
| 456 |
+
|
| 457 |
+
inquiries = []
|
| 458 |
+
|
| 459 |
+
for state in knowledge_states:
|
| 460 |
+
# Use analyzer to get multiple potential inquiries
|
| 461 |
+
analysis_results = self.analyzer.analyze(state)
|
| 462 |
+
|
| 463 |
+
for result in analysis_results:
|
| 464 |
+
# Only generate inquiries that meet threshold
|
| 465 |
+
if result.investigation_confidence >= confidence_threshold:
|
| 466 |
+
inquiry = InquiryArtifact.create(
|
| 467 |
+
knowledge_state=state,
|
| 468 |
+
analysis_result=result,
|
| 469 |
+
basis_templates=INQUIRY_BASIS_TEMPLATES,
|
| 470 |
+
creation_context=self.creation_context
|
| 471 |
+
)
|
| 472 |
+
inquiries.append(inquiry)
|
| 473 |
+
self.generated_inquiries.append(inquiry)
|
| 474 |
+
|
| 475 |
+
return tuple(inquiries)
|
| 476 |
+
|
| 477 |
+
# === RESEARCH SYSTEM INTERFACE ===
|
| 478 |
+
|
| 479 |
+
class ResearchSystem:
|
| 480 |
+
"""Abstract research system interface"""
|
| 481 |
+
|
| 482 |
+
async def research(self, topic: str, **kwargs) -> Dict[str, Any]:
|
| 483 |
+
"""Conduct research on topic (must be implemented)"""
|
| 484 |
+
raise NotImplementedError
|
| 485 |
+
|
| 486 |
+
# === INTEGRATED KNOWLEDGE DISCOVERY ===
|
| 487 |
+
|
| 488 |
+
class IntegratedKnowledgeDiscovery:
|
| 489 |
+
"""
|
| 490 |
+
Integrated system with clear async boundaries and determinism
|
| 491 |
+
"""
|
| 492 |
+
|
| 493 |
+
def __init__(
|
| 494 |
+
self,
|
| 495 |
+
research_system: ResearchSystem,
|
| 496 |
+
deterministic_seed: Optional[int] = None
|
| 497 |
+
):
|
| 498 |
+
"""
|
| 499 |
+
Initialize with concrete research system
|
| 500 |
+
|
| 501 |
+
Args:
|
| 502 |
+
research_system: Must implement ResearchSystem interface
|
| 503 |
+
deterministic_seed: Optional seed for reproducible results
|
| 504 |
+
"""
|
| 505 |
+
if not isinstance(research_system, ResearchSystem):
|
| 506 |
+
raise TypeError("research_system must implement ResearchSystem interface")
|
| 507 |
+
|
| 508 |
+
self.research_system = research_system
|
| 509 |
+
self.deterministic_seed = deterministic_seed
|
| 510 |
+
self.inquiry_generator = InquiryGenerator(deterministic_seed=deterministic_seed)
|
| 511 |
+
self.discovery_history: List[Dict[str, Any]] = []
|
| 512 |
+
|
| 513 |
+
async def conduct_research_with_inquiries(
|
| 514 |
+
self,
|
| 515 |
+
research_topic: str,
|
| 516 |
+
confidence_threshold: float = 0.7,
|
| 517 |
+
**research_kwargs
|
| 518 |
+
) -> Dict[str, Any]:
|
| 519 |
+
"""Conduct research and generate knowledge inquiries"""
|
| 520 |
+
|
| 521 |
+
# 1. Conduct research using the provided system
|
| 522 |
+
research_result = await self.research_system.research(research_topic, **research_kwargs)
|
| 523 |
+
|
| 524 |
+
# 2. Convert to knowledge state
|
| 525 |
+
knowledge_state = self._convert_to_knowledge_state(research_result)
|
| 526 |
+
|
| 527 |
+
# 3. Generate inquiries
|
| 528 |
+
knowledge_states = (knowledge_state,)
|
| 529 |
+
inquiry_artifacts = self.inquiry_generator.generate_inquiries(
|
| 530 |
+
knowledge_states,
|
| 531 |
+
confidence_threshold
|
| 532 |
+
)
|
| 533 |
+
|
| 534 |
+
# 4. Create inquiry collection
|
| 535 |
+
inquiry_collection = {
|
| 536 |
+
"collection_id": f"inq_coll_{hashlib.sha256(knowledge_state.state_hash.encode()).hexdigest()[:16]}",
|
| 537 |
+
"research_topic": research_topic,
|
| 538 |
+
"knowledge_state_hash": knowledge_state.state_hash[:12],
|
| 539 |
+
"inquiry_count": len(inquiry_artifacts),
|
| 540 |
+
"generation_timestamp": datetime.utcnow().isoformat(),
|
| 541 |
+
"confidence_threshold": confidence_threshold,
|
| 542 |
+
"deterministic_mode": self.deterministic_seed is not None,
|
| 543 |
+
"inquiries": [i.reference_information() for i in inquiry_artifacts]
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
# 5. Store and return
|
| 547 |
+
self.discovery_history.append({
|
| 548 |
+
"research_topic": research_topic,
|
| 549 |
+
"research_result": research_result,
|
| 550 |
+
"knowledge_state": knowledge_state,
|
| 551 |
+
"inquiry_collection": inquiry_collection,
|
| 552 |
+
"inquiry_artifacts": inquiry_artifacts
|
| 553 |
+
})
|
| 554 |
+
|
| 555 |
+
return {
|
| 556 |
+
"research_topic": research_topic,
|
| 557 |
+
"research_summary": {
|
| 558 |
+
"confidence_score": research_result.get("confidence_score", 0.5),
|
| 559 |
+
"methodological_rigor": research_result.get("methodological_rigor", 0.5),
|
| 560 |
+
"domains": research_result.get("knowledge_domains", [])
|
| 561 |
+
},
|
| 562 |
+
"inquiry_generation": {
|
| 563 |
+
"inquiries_generated": len(inquiry_artifacts),
|
| 564 |
+
"inquiry_collection_id": inquiry_collection["collection_id"],
|
| 565 |
+
"priority_distribution": self._summarize_priorities(inquiry_artifacts),
|
| 566 |
+
"confidence_threshold_met": len(inquiry_artifacts) > 0
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
def _convert_to_knowledge_state(
|
| 571 |
+
self,
|
| 572 |
+
research_result: Dict[str, Any]
|
| 573 |
+
) -> KnowledgeState:
|
| 574 |
+
"""Convert research result to knowledge state"""
|
| 575 |
+
|
| 576 |
+
# Extract with provenance tracking
|
| 577 |
+
confidence_score = research_result.get("confidence_score", 0.5)
|
| 578 |
+
confidence_provenance = research_result.get(
|
| 579 |
+
"confidence_provenance",
|
| 580 |
+
"derived_from_research"
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
# Determine state type
|
| 584 |
+
if confidence_score < 0.6:
|
| 585 |
+
state_type = KnowledgeStateType.SOURCE_VERIFICATION
|
| 586 |
+
elif "pattern" in str(research_result.get("structural_description", "")).lower():
|
| 587 |
+
state_type = KnowledgeStateType.PATTERN_DETECTION
|
| 588 |
+
elif len(research_result.get("knowledge_domains", [])) > 2:
|
| 589 |
+
state_type = KnowledgeStateType.CROSS_DOMAIN_SYNTHESIS
|
| 590 |
+
else:
|
| 591 |
+
state_type = KnowledgeStateType.DATA_CORRELATION
|
| 592 |
+
|
| 593 |
+
# Generate patterns deterministically
|
| 594 |
+
if self.deterministic_seed is not None:
|
| 595 |
+
# Deterministic pattern generation
|
| 596 |
+
pattern_seed = hash(f"{self.deterministic_seed}:{research_result.get('content_hash', '')}")
|
| 597 |
+
np.random.seed(pattern_seed % (2**32))
|
| 598 |
+
data_patterns = tuple(np.random.randn(8).tolist())
|
| 599 |
+
else:
|
| 600 |
+
# Use provided pattern or generate default
|
| 601 |
+
provided_patterns = research_result.get("data_patterns", [])
|
| 602 |
+
data_patterns = tuple(provided_patterns[:8]) if provided_patterns else tuple(np.sin(np.arange(8) * 0.785).tolist())
|
| 603 |
+
|
| 604 |
+
# Generate structural description
|
| 605 |
+
structural_description = self._generate_structural_description(research_result)
|
| 606 |
+
|
| 607 |
+
# Generate validation signature
|
| 608 |
+
validation_signature = hashlib.sha3_512(
|
| 609 |
+
f"{research_result.get('content_hash', '')}:{self.deterministic_seed or 'stochastic'}".encode()
|
| 610 |
+
).hexdigest()[:32]
|
| 611 |
+
|
| 612 |
+
return KnowledgeState(
|
| 613 |
+
state_id=f"knowledge_state_{research_result.get('content_hash', 'unknown')[:12]}",
|
| 614 |
+
state_type=state_type,
|
| 615 |
+
confidence_score=confidence_score,
|
| 616 |
+
confidence_provenance=confidence_provenance,
|
| 617 |
+
methodological_rigor=research_result.get("methodological_rigor", 0.5),
|
| 618 |
+
data_patterns=data_patterns,
|
| 619 |
+
knowledge_domains=tuple(research_result.get("knowledge_domains", ["general"])),
|
| 620 |
+
temporal_markers=(
|
| 621 |
+
research_result.get("timestamp", ""),
|
| 622 |
+
datetime.utcnow().isoformat()
|
| 623 |
+
),
|
| 624 |
+
research_constraints=self._extract_constraints(research_result),
|
| 625 |
+
structural_description=structural_description,
|
| 626 |
+
validation_signature=validation_signature
|
| 627 |
+
)
|
| 628 |
+
|
| 629 |
+
def _generate_structural_description(
|
| 630 |
+
self,
|
| 631 |
+
research_result: Dict[str, Any]
|
| 632 |
+
) -> str:
|
| 633 |
+
"""Generate structural description"""
|
| 634 |
+
components = []
|
| 635 |
+
|
| 636 |
+
confidence = research_result.get("confidence_score", 0.5)
|
| 637 |
+
provenance = research_result.get("confidence_provenance", "unstated")
|
| 638 |
+
|
| 639 |
+
if confidence < 0.6:
|
| 640 |
+
components.append(f"Low confidence ({confidence:.2f}) from {provenance}")
|
| 641 |
+
elif confidence > 0.8:
|
| 642 |
+
components.append(f"High confidence ({confidence:.2f}) from {provenance}")
|
| 643 |
+
|
| 644 |
+
rigor = research_result.get("methodological_rigor", 0.5)
|
| 645 |
+
if rigor < 0.6:
|
| 646 |
+
components.append(f"Methodological rigor: {rigor:.2f}")
|
| 647 |
+
|
| 648 |
+
domains = research_result.get("knowledge_domains", [])
|
| 649 |
+
if len(domains) > 2:
|
| 650 |
+
components.append(f"Cross-domain: {len(domains)} domains")
|
| 651 |
+
|
| 652 |
+
if not components:
|
| 653 |
+
components.append("Standard research structure")
|
| 654 |
+
|
| 655 |
+
return f"{KNOWLEDGE_NODE} " + "; ".join(components)
|
| 656 |
+
|
| 657 |
+
def _extract_constraints(
|
| 658 |
+
self,
|
| 659 |
+
research_result: Dict[str, Any]
|
| 660 |
+
) -> Tuple[str, ...]:
|
| 661 |
+
"""Extract research constraints"""
|
| 662 |
+
constraints = []
|
| 663 |
+
|
| 664 |
+
if research_result.get("confidence_score", 0) < 0.7:
|
| 665 |
+
constraints.append("confidence_verification_needed")
|
| 666 |
+
|
| 667 |
+
if research_result.get("methodological_rigor", 0) < 0.6:
|
| 668 |
+
constraints.append("methodology_review_recommended")
|
| 669 |
+
|
| 670 |
+
if not research_result.get("source_references", []):
|
| 671 |
+
constraints.append("source_corroboration_required")
|
| 672 |
+
|
| 673 |
+
if not constraints:
|
| 674 |
+
constraints.append("standard_verification_protocol")
|
| 675 |
+
|
| 676 |
+
return tuple(constraints)
|
| 677 |
+
|
| 678 |
+
def _summarize_priorities(
|
| 679 |
+
self,
|
| 680 |
+
inquiry_artifacts: Tuple[InquiryArtifact, ...]
|
| 681 |
+
) -> Dict[str, Any]:
|
| 682 |
+
"""Summarize inquiry priorities with clear semantics"""
|
| 683 |
+
if not inquiry_artifacts:
|
| 684 |
+
return {"message": "No inquiries generated", "priority_levels": {}}
|
| 685 |
+
|
| 686 |
+
priority_summary = {}
|
| 687 |
+
for artifact in inquiry_artifacts:
|
| 688 |
+
priority = artifact.investigation_priority
|
| 689 |
+
if priority not in priority_summary:
|
| 690 |
+
priority_summary[priority] = {
|
| 691 |
+
"count": 0,
|
| 692 |
+
"domains": set(),
|
| 693 |
+
"semantics": artifact._priority_semantics()
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
priority_summary[priority]["count"] += 1
|
| 697 |
+
priority_summary[priority]["domains"].update(artifact.knowledge_domains_involved)
|
| 698 |
+
|
| 699 |
+
# Convert sets to lists
|
| 700 |
+
for priority in priority_summary:
|
| 701 |
+
priority_summary[priority]["domains"] = list(priority_summary[priority]["domains"])
|
| 702 |
+
|
| 703 |
+
return {
|
| 704 |
+
"total_priorities": len(priority_summary),
|
| 705 |
+
"highest_priority": max(priority_summary.keys()),
|
| 706 |
+
"priority_distribution": priority_summary
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
def get_statistics(self) -> Dict[str, Any]:
|
| 710 |
+
"""Get system statistics"""
|
| 711 |
+
total_inquiries = len(self.inquiry_generator.generated_inquiries)
|
| 712 |
+
|
| 713 |
+
# Calculate category distribution
|
| 714 |
+
category_counts = {}
|
| 715 |
+
for inquiry in self.inquiry_generator.generated_inquiries:
|
| 716 |
+
category = inquiry.inquiry_category.value
|
| 717 |
+
category_counts[category] = category_counts.get(category, 0) + 1
|
| 718 |
+
|
| 719 |
+
# Calculate average metrics
|
| 720 |
+
if total_inquiries > 0:
|
| 721 |
+
avg_confidence = np.mean([i.investigation_confidence for i in self.inquiry_generator.generated_inquiries])
|
| 722 |
+
avg_priority = np.mean([i.investigation_priority for i in self.inquiry_generator.generated_inquiries])
|
| 723 |
+
else:
|
| 724 |
+
avg_confidence = 0.0
|
| 725 |
+
avg_priority = 0.0
|
| 726 |
+
|
| 727 |
+
return {
|
| 728 |
+
"system": "Integrated Knowledge Discovery v2.5",
|
| 729 |
+
"research_sessions": len(self.discovery_history),
|
| 730 |
+
"total_inquiries_generated": total_inquiries,
|
| 731 |
+
"category_distribution": category_counts,
|
| 732 |
+
"average_investigation_confidence": round(float(avg_confidence), 3),
|
| 733 |
+
"average_investigation_priority": round(float(avg_priority), 1),
|
| 734 |
+
"deterministic_mode": self.deterministic_seed is not None,
|
| 735 |
+
"engineering_properties": {
|
| 736 |
+
"immutable_data_structures": True,
|
| 737 |
+
"deterministic_hashes": True,
|
| 738 |
+
"pluggable_analyzers": True,
|
| 739 |
+
"clear_async_boundaries": True,
|
| 740 |
+
"priority_semantics_documented": True
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
# === CONCRETE RESEARCH SYSTEM EXAMPLE ===
|
| 745 |
+
|
| 746 |
+
class ConcreteResearchSystem(ResearchSystem):
|
| 747 |
+
"""Example research system with proper async implementation"""
|
| 748 |
+
|
| 749 |
+
def __init__(self, deterministic_seed: Optional[int] = None):
|
| 750 |
+
self.deterministic_seed = deterministic_seed
|
| 751 |
+
if deterministic_seed is not None:
|
| 752 |
+
np.random.seed(deterministic_seed)
|
| 753 |
+
|
| 754 |
+
async def research(self, topic: str, **kwargs) -> Dict[str, Any]:
|
| 755 |
+
"""Conduct research (simulated for example)"""
|
| 756 |
+
# Simulate async research delay
|
| 757 |
+
import asyncio
|
| 758 |
+
await asyncio.sleep(0.1) # Simulate network/processing
|
| 759 |
+
|
| 760 |
+
# Generate deterministic or random results
|
| 761 |
+
if self.deterministic_seed is not None:
|
| 762 |
+
# Deterministic based on topic
|
| 763 |
+
topic_hash = hash(topic) % 1000
|
| 764 |
+
confidence = 0.5 + (topic_hash % 500) / 1000 # 0.5-1.0
|
| 765 |
+
rigor = 0.4 + (topic_hash % 600) / 1000 # 0.4-1.0
|
| 766 |
+
else:
|
| 767 |
+
# Random results
|
| 768 |
+
confidence = np.random.random() * 0.3 + 0.5 # 0.5-0.8
|
| 769 |
+
rigor = np.random.random() * 0.4 + 0.4 # 0.4-0.8
|
| 770 |
+
|
| 771 |
+
return {
|
| 772 |
+
"topic": topic,
|
| 773 |
+
"content_hash": hashlib.sha256(topic.encode()).hexdigest()[:32],
|
| 774 |
+
"confidence_score": confidence,
|
| 775 |
+
"confidence_provenance": "simulated_analysis",
|
| 776 |
+
"methodological_rigor": rigor,
|
| 777 |
+
"knowledge_domains": self._identify_domains(topic),
|
| 778 |
+
"structural_description": f"Research on {topic}",
|
| 779 |
+
"timestamp": datetime.utcnow().isoformat(),
|
| 780 |
+
"data_patterns": np.sin(np.arange(10) * 0.628).tolist(),
|
| 781 |
+
"source_references": [f"ref_{i}" for i in range(np.random.randint(1, 4))]
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
def _identify_domains(self, topic: str) -> List[str]:
|
| 785 |
+
"""Identify domains from topic"""
|
| 786 |
+
domains = []
|
| 787 |
+
topic_lower = topic.lower()
|
| 788 |
+
|
| 789 |
+
if any(word in topic_lower for word in ["quantum", "physics"]):
|
| 790 |
+
domains.append("physics")
|
| 791 |
+
if any(word in topic_lower for word in ["history", "ancient"]):
|
| 792 |
+
domains.append("history")
|
| 793 |
+
if any(word in topic_lower for word in ["consciousness", "mind"]):
|
| 794 |
+
domains.append("psychology")
|
| 795 |
+
if any(word in topic_lower for word in ["pattern", "analysis"]):
|
| 796 |
+
domains.append("mathematics")
|
| 797 |
+
|
| 798 |
+
return domains if domains else ["interdisciplinary"]
|
| 799 |
+
|
| 800 |
+
# === TEST UTILITIES ===
|
| 801 |
+
|
| 802 |
+
def run_deterministic_test() -> bool:
|
| 803 |
+
"""Test deterministic reproducibility"""
|
| 804 |
+
print("Testing deterministic reproducibility...")
|
| 805 |
+
|
| 806 |
+
# Run with same seed
|
| 807 |
+
research_system1 = ConcreteResearchSystem(deterministic_seed=42)
|
| 808 |
+
system1 = IntegratedKnowledgeDiscovery(research_system1, deterministic_seed=42)
|
| 809 |
+
|
| 810 |
+
research_system2 = ConcreteResearchSystem(deterministic_seed=42)
|
| 811 |
+
system2 = IntegratedKnowledgeDiscovery(research_system2, deterministic_seed=42)
|
| 812 |
+
|
| 813 |
+
import asyncio
|
| 814 |
+
|
| 815 |
+
# Run same research
|
| 816 |
+
loop = asyncio.new_event_loop()
|
| 817 |
+
asyncio.set_event_loop(loop)
|
| 818 |
+
|
| 819 |
+
result1 = loop.run_until_complete(
|
| 820 |
+
system1.conduct_research_with_inquiries("Test topic")
|
| 821 |
+
)
|
| 822 |
+
result2 = loop.run_until_complete(
|
| 823 |
+
system2.conduct_research_with_inquiries("Test topic")
|
| 824 |
+
)
|
| 825 |
+
|
| 826 |
+
loop.close()
|
| 827 |
+
|
| 828 |
+
# Compare results
|
| 829 |
+
inquiries1 = result1["inquiry_generation"]["inquiries_generated"]
|
| 830 |
+
inquiries2 = result2["inquiry_generation"]["inquiries_generated"]
|
| 831 |
+
|
| 832 |
+
print(f" System 1 inquiries: {inquiries1}")
|
| 833 |
+
print(f" System 2 inquiries: {inquiries2}")
|
| 834 |
+
print(f" Results identical: {inquiries1 == inquiries2}")
|
| 835 |
+
|
| 836 |
+
return inquiries1 == inquiries2
|
| 837 |
+
|
| 838 |
+
# === MAIN ===
|
| 839 |
+
|
| 840 |
+
async def main():
|
| 841 |
+
"""Demonstrate the system"""
|
| 842 |
+
print(f"""
|
| 843 |
+
{'='*70}
|
| 844 |
+
STRUCTURAL INQUIRY SYSTEM v2.5
|
| 845 |
+
Engineering-Focused Knowledge Discovery
|
| 846 |
+
{'='*70}
|
| 847 |
+
""")
|
| 848 |
+
|
| 849 |
+
# Run deterministic test
|
| 850 |
+
if run_deterministic_test():
|
| 851 |
+
print(f"\n{VALIDATION_SYMBOL} Deterministic reproducibility verified")
|
| 852 |
+
else:
|
| 853 |
+
print(f"\n{INQUIRY_MARKER} Non-deterministic behavior detected")
|
| 854 |
+
|
| 855 |
+
# Create and run system
|
| 856 |
+
research_system = ConcreteResearchSystem()
|
| 857 |
+
discovery_system = IntegratedKnowledgeDiscovery(research_system)
|
| 858 |
+
|
| 859 |
+
topics = [
|
| 860 |
+
"Quantum pattern analysis techniques",
|
| 861 |
+
"Historical methodology consistency",
|
| 862 |
+
"Cross-domain verification protocols"
|
| 863 |
+
]
|
| 864 |
+
|
| 865 |
+
for i, topic in enumerate(topics, 1):
|
| 866 |
+
print(f"\n{PATTERN_RECOGNITION} RESEARCH SESSION {i}: {topic}")
|
| 867 |
+
print(f"{'-'*60}")
|
| 868 |
+
|
| 869 |
+
result = await discovery_system.conduct_research_with_inquiries(
|
| 870 |
+
topic,
|
| 871 |
+
confidence_threshold=0.6
|
| 872 |
+
)
|
| 873 |
+
|
| 874 |
+
inquiries = result["inquiry_generation"]["inquiries_generated"]
|
| 875 |
+
priorities = result["inquiry_generation"]["priority_distribution"]
|
| 876 |
+
|
| 877 |
+
print(f" {VALIDATION_SYMBOL} Research completed")
|
| 878 |
+
print(f" {KNOWLEDGE_NODE} Inquiries generated: {inquiries}")
|
| 879 |
+
|
| 880 |
+
if inquiries > 0:
|
| 881 |
+
for priority, data in priorities.get("priority_distribution", {}).items():
|
| 882 |
+
semantics = data.get("semantics", "unknown")
|
| 883 |
+
print(f" Priority {priority} ({semantics}): {data['count']} inquiries")
|
| 884 |
+
|
| 885 |
+
# Display statistics
|
| 886 |
+
stats = discovery_system.get_statistics()
|
| 887 |
+
print(f"\n{'='*70}")
|
| 888 |
+
print("SYSTEM STATISTICS")
|
| 889 |
+
print(f"{'='*70}")
|
| 890 |
+
|
| 891 |
+
print(f"\nResearch sessions: {stats['research_sessions']}")
|
| 892 |
+
print(f"Total inquiries: {stats['total_inquiries_generated']}")
|
| 893 |
+
print(f"\nEngineering properties:")
|
| 894 |
+
for prop, value in stats["engineering_properties"].items():
|
| 895 |
+
status = "✓" if value else "✗"
|
| 896 |
+
print(f" {status} {prop}: {value}")
|
| 897 |
+
|
| 898 |
+
if __name__ == "__main__":
|
| 899 |
+
import asyncio
|
| 900 |
+
|
| 901 |
+
try:
|
| 902 |
+
asyncio.run(main())
|
| 903 |
+
except KeyboardInterrupt:
|
| 904 |
+
print(f"\n\n{KNOWLEDGE_NODE} System shutdown complete.")
|