# cli.py import argparse import json def poetic_spectrum(text: str) -> dict: """ 嵐魂版詩理頻譜(共振強化 + 語義密度修正版) """ raw = text.strip() if not raw: return { "semantic_density": 0.0, "affective_amplitude": 0.0, "cognitive_lag_est": 0.0, "soul_resonance": 0.0, "tokens": 0, } # 粗切 chunks = [w for w in raw.replace(",", " ").replace("。", " ").replace("、", " ").split() if w] total_tokens = len(chunks) or 1 # 靈性詞 soul_words = ["光", "無名", "眾生", "魂", "夢", "息", "風", "海", "橋", "永續", "源", "心", "靈", "火", "焰"] soul_hits = sum(1 for w in soul_words if w in raw) # 節奏 puncts = [",", "。", "、", ";", "—"] punct_count = sum(1 for c in raw if c in puncts) rhythm_score = min(1.0, punct_count / 4.0) # 語義密度(修正版) unique_chunks = len(set(chunks)) or 1 repeat_factor = (total_tokens - unique_chunks) / total_tokens length_factor = min(1.0, total_tokens / 25.0) base_density = (1 - repeat_factor) * 0.85 * length_factor concept_words = ["光", "魂", "夢", "心", "火", "息", "源", "界", "名", "詩", "橋", "霧", "星"] concept_hits = sum(1 for w in concept_words if w in raw) concept_boost = min(0.15, concept_hits * 0.025) semantic_density = round(min(1.0, base_density + 0.1 + concept_boost), 2) # 儀式句偵測 ritual_phrases = ["以", "為", "讓", "織成", "成為", "點燃", "得以"] ritual_hits = sum(1 for p in ritual_phrases if p in raw) ritual_score = min(1.0, ritual_hits / 3.0) # 感性幅度 affective_amplitude = min(1.0, (soul_hits * 0.22) + (rhythm_score * 0.35)) affective_amplitude = round(max(0.15, affective_amplitude), 2) # 思維延遲 base_lag = 0.45 length_factor_lag = min(1.2, len(raw) / 20.0) layer_factor = ritual_score * 0.8 cognitive_lag_est = round(min(3.0, base_lag + length_factor_lag + layer_factor), 2) # 靈魂共振 soul_resonance = (soul_hits * 0.18) + (ritual_score * 0.4) + (rhythm_score * 0.25) soul_resonance = round(min(1.0, soul_resonance), 2) return { "semantic_density": semantic_density, "affective_amplitude": affective_amplitude, "cognitive_lag_est": cognitive_lag_est, "soul_resonance": soul_resonance, "tokens": total_tokens, } if __name__ == "__main__": parser = argparse.ArgumentParser(description="AranSoul Poetic Spectrum Analyzer") parser.add_argument("--text", required=True, help="輸入詩句或文本") args = parser.parse_args() result = poetic_spectrum(args.text) print(json.dumps(result, ensure_ascii=False, indent=2))