feat: complete academic symbol lexicon heal, 2-column Cooper extraction, and updated assets
This commit is contained in:
Executable
+209
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
ingest_rene_guenon.py
|
||||
=====================
|
||||
Парсер фундаментального труда Рене Генона «Символы священной науки» (1962/2002)
|
||||
из файла /home/alexives/Desktop/newsources/simvoli_svyash_nauki.doc (29 694 строки).
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from oracle_enricher.enricher.passport_schema import count_filled_fields
|
||||
|
||||
DOC_PATH = Path("/home/alexives/Desktop/newsources/simvoli_svyash_nauki.doc")
|
||||
STAGING_DB_PATH = PROJECT_ROOT / "assets" / "data" / "oracle_passports_staging.json"
|
||||
MAIN_DB_PATH = PROJECT_ROOT / "assets" / "data" / "oracle_passports.json"
|
||||
EXTERNAL_DB_PATH = PROJECT_ROOT / "assets" / "data" / "oracle_external_symbols.json"
|
||||
ENRICHER_EXTERNAL_PATH = PROJECT_ROOT / "oracle_enricher" / "data" / "oracle_external_symbols.json"
|
||||
|
||||
|
||||
def clean_spaces(text: str) -> str:
|
||||
text = re.sub(r'(\w+)-\s*\n\s*(\w+)', r'\1\2', text)
|
||||
return re.sub(r'\s+', ' ', text).strip()
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 70)
|
||||
print("📖 ПАРСИНГ РЕНЕ ГЕНОНА: «СИМВОЛЫ СВЯЩЕННОЙ НАУКИ»")
|
||||
print("=" * 70)
|
||||
|
||||
if not DOC_PATH.exists():
|
||||
print(f"❌ Файл не найден: {DOC_PATH}")
|
||||
return
|
||||
|
||||
# Извлекаем текст через catdoc
|
||||
raw_text = subprocess.check_output(["catdoc", "-d", "utf-8", str(DOC_PATH)]).decode("utf-8")
|
||||
print(f"Извлечено строк: {len(raw_text.splitlines())}, символов: {len(raw_text)}")
|
||||
|
||||
with open(STAGING_DB_PATH, "r", encoding="utf-8") as f:
|
||||
staging_db = json.load(f)
|
||||
|
||||
with open(EXTERNAL_DB_PATH, "r", encoding="utf-8") as f:
|
||||
external_db = json.load(f)
|
||||
|
||||
core_index = {}
|
||||
for idx_str, entry in staging_db.items():
|
||||
w = entry.get("word", "").lower().strip()
|
||||
if w:
|
||||
core_index[w] = idx_str
|
||||
|
||||
# Карта глав Генона к целевым сакральным знакам Оракула
|
||||
chapter_sign_map = [
|
||||
(2, "Слово и символ", "слово", ["philosophical_essence", "meta_synthesis", "semantic_core"]),
|
||||
(3, "Сердце Иисусово и легенда о Святом Граале", "сердце", ["philosophical_essence", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(4, "Святой Грааль", "чаша", ["culture_hermetic_light", "meta_synthesis", "state_creative"]),
|
||||
(7, "Язык птиц", "птица", ["archetype_category", "meta_synthesis", "script_antiquity"]),
|
||||
(8, "Идея Центра в древних традициях", "центр", ["philosophical_essence", "meta_synthesis", "geometric_archetype"]),
|
||||
(9, "Цветы-символы", "цветок", ["meta_synthesis", "culture_hermetic_light", "semantic_core"]),
|
||||
(10, "Тройная друидическая ограда", "лабиринт", ["culture_celtic_light", "geometric_archetype", "meta_synthesis"]),
|
||||
(11, "Хранители Святой Земли", "земля", ["cosmogonic_role", "meta_synthesis", "culture_kabbalah_light"]),
|
||||
(12, "Земля Солнца", "солнце", ["solar_lunar_axis", "meta_synthesis", "cosmogonic_role"]),
|
||||
(14, "Тетрактис и квадрат четырех", "четыре", ["geometric_archetype", "meta_synthesis", "script_antiquity"]),
|
||||
(15, "Иероглиф Полюса", "север", ["spatial_orientation", "meta_synthesis", "cosmogonic_role"]),
|
||||
(17, "Буква G и свастика", "колесо", ["geometric_archetype", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(18, "Несколько аспектов символики Януса", "врата", ["spatial_orientation", "culture_antiquity_light", "meta_synthesis"]),
|
||||
(19, "Иероглиф рака", "рак", ["mantic_zodiac_west", "meta_synthesis", "cosmogonic_role"]),
|
||||
(22, "Некоторые аспекты символики рыбы", "рыба", ["archetype_category", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(24, "Вепрь и Медведица", "вепрь", ["archetype_category", "culture_celtic_light", "culture_india_light"]),
|
||||
(24, "Вепрь и Медведица", "медведь", ["archetype_category", "culture_celtic_light", "culture_nordic_light"]),
|
||||
(25, "Громовые камни", "камень", ["elemental_affinity", "culture_hermetic_light", "meta_synthesis"]),
|
||||
(25, "Громовые камни", "молния", ["elemental_affinity", "culture_antiquity_light", "meta_synthesis"]),
|
||||
(26, "Символическое оружие", "меч", ["will_vector", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(27, "Сайфуль-Ислам", "меч", ["culture_islam_light", "will_vector", "meta_synthesis"]),
|
||||
(28, "Символика рогов", "рога", ["archetype_category", "culture_sumer_light", "meta_synthesis"]),
|
||||
(29, "Пещера и лабиринт", "пещера", ["chthonic_aspect", "spatial_orientation", "meta_synthesis"]),
|
||||
(29, "Пещера и лабиринт", "лабиринт", ["geometric_archetype", "meta_synthesis", "spatial_orientation"]),
|
||||
(30, "Сердце и пещера", "сердце", ["philosophical_essence", "meta_synthesis", "semantic_core"]),
|
||||
(31, "Гора и Пещера", "гора", ["cosmogonic_role", "spatial_orientation", "meta_synthesis"]),
|
||||
(32, "Сердце и Мировое Яйцо", "яйцо", ["cosmogonic_role", "geometric_archetype", "meta_synthesis"]),
|
||||
(35, "Врата солнцестояния", "врата", ["spatial_orientation", "cosmogonic_role", "meta_synthesis"]),
|
||||
(39, "Символика купола", "храм", ["spatial_orientation", "geometric_archetype", "meta_synthesis"]),
|
||||
(40, "Купол и колесо", "колесо", ["geometric_archetype", "meta_synthesis", "cosmogonic_role"]),
|
||||
(41, "Узкие врата", "врата", ["spatial_orientation", "meta_synthesis", "will_vector"]),
|
||||
(42, "Восьмиугольник", "восемь", ["geometric_archetype", "meta_synthesis", "script_antiquity"]),
|
||||
(47, "Белое и черное", "белый", ["elemental_affinity", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(47, "Белое и черное", "черный", ["chthonic_aspect", "meta_synthesis", "culture_hermetic_light"]),
|
||||
(48, "Черный камень и камень кубический", "камень", ["geometric_archetype", "meta_synthesis", "culture_islam_light"]),
|
||||
(51, "Мировое Древо", "дерево", ["cosmogonic_role", "meta_synthesis", "culture_india_light"]),
|
||||
(52, "Дерево и ваджра", "молния", ["cosmogonic_role", "culture_india_light", "meta_synthesis"]),
|
||||
(53, "Древо Жизни и напиток бессмертия", "вино", ["culture_hermetic_light", "meta_synthesis", "cosmogonic_role"]),
|
||||
(54, "Символика лестницы", "лестница", ["spatial_orientation", "meta_synthesis", "will_vector"]),
|
||||
(56, "Прохождение вод", "вода", ["elemental_affinity", "cosmogonic_role", "meta_synthesis"]),
|
||||
(56, "Прохождение вод", "река", ["elemental_affinity", "spatial_orientation", "meta_synthesis"]),
|
||||
(57, "Семь лучей и радуга", "радуга", ["elemental_affinity", "cosmogonic_role", "meta_synthesis"]),
|
||||
(57, "Семь лучей и радуга", "семь", ["geometric_archetype", "meta_synthesis", "mantic_septener"]),
|
||||
(60, "Свет и дождь", "свет", ["elemental_affinity", "cosmogonic_role", "meta_synthesis"]),
|
||||
(60, "Свет и дождь", "дождь", ["elemental_affinity", "cosmogonic_role", "meta_synthesis"]),
|
||||
(63, "Символика моста", "мост", ["spatial_orientation", "meta_synthesis", "will_vector"]),
|
||||
(64, "Мост и радуга", "мост", ["spatial_orientation", "cosmogonic_role", "meta_synthesis"]),
|
||||
(68, "Узы и узлы", "узел", ["geometric_archetype", "meta_synthesis", "will_vector"]),
|
||||
(69, "Сердце лучистое и сердце пылающее", "сердце", ["philosophical_essence", "meta_synthesis", "state_creative"]),
|
||||
(70, "Сердце и мозг", "мозг", ["philosophical_essence", "meta_synthesis", "state_creative"]),
|
||||
(72, "Всевидящее око", "глаз", ["cosmogonic_role", "meta_synthesis", "script_egypt"]),
|
||||
(73, "Горчичное зерно", "зерно", ["cosmogonic_role", "meta_synthesis", "state_creative"]),
|
||||
(75, "Божественный град", "город", ["spatial_orientation", "geometric_archetype", "meta_synthesis"]),
|
||||
]
|
||||
|
||||
# Находим границы каждой главы в тексте
|
||||
chapter_positions = []
|
||||
matches = list(re.finditer(r'\n([0-9]{1,2})\.\s+([А-ЯЁ][^\n]{3,60})\n', raw_text))
|
||||
for m in matches:
|
||||
title = m.group(2).strip()
|
||||
if "PAGEREF" not in title:
|
||||
chapter_positions.append((int(m.group(1)), title, m.start()))
|
||||
|
||||
print(f"Найдено глав в основном тексте: {len(chapter_positions)}")
|
||||
|
||||
enriched_count = 0
|
||||
external_count = 0
|
||||
timestamp_str = datetime.now().isoformat()
|
||||
|
||||
# Извлекаем текст каждой главы
|
||||
for idx, (ch_num, ch_title, start_pos) in enumerate(chapter_positions):
|
||||
end_pos = chapter_positions[idx + 1][2] if idx + 1 < len(chapter_positions) else len(raw_text)
|
||||
chapter_body = clean_spaces(raw_text[start_pos:end_pos])
|
||||
|
||||
# Ищем совпадения в нашей карте знаков
|
||||
matched_mappings = [m for m in chapter_sign_map if m[0] == ch_num]
|
||||
|
||||
if matched_mappings:
|
||||
for _, title_hint, sign_word, pref_fields in matched_mappings:
|
||||
if sign_word in core_index:
|
||||
core_id = core_index[sign_word]
|
||||
entry = staging_db[core_id]
|
||||
fields = entry.setdefault("fields", {})
|
||||
|
||||
target_field = None
|
||||
for pf in pref_fields:
|
||||
if not fields.get(pf):
|
||||
target_field = pf
|
||||
break
|
||||
|
||||
if not target_field:
|
||||
# Запасные ячейки
|
||||
for alt in ["meta_synthesis", "semantic_core", "state_creative"]:
|
||||
if not fields.get(alt):
|
||||
target_field = alt
|
||||
break
|
||||
|
||||
excerpt = (chapter_body[:420] + "...") if len(chapter_body) > 420 else chapter_body
|
||||
quoted = f"[Рене Генон · «Символы священной науки»]: «{excerpt}»"
|
||||
|
||||
if target_field and not fields.get(target_field):
|
||||
fields[target_field] = quoted
|
||||
filled, _ = count_filled_fields(entry)
|
||||
entry["filled_count"] = filled
|
||||
entry["is_complete"] = (filled >= 78)
|
||||
enriched_count += 1
|
||||
else:
|
||||
# Если глава не сопоставлена с каноном, отправляем в базу внешних символов
|
||||
term_clean = re.sub(r'\(.*?\)', '', ch_title).strip()
|
||||
norm = term_clean.lower()
|
||||
if len(norm) > 2 and norm not in external_db:
|
||||
external_db[norm] = {
|
||||
"term": term_clean,
|
||||
"normalized": norm,
|
||||
"category_guess": "Священный традиционный символ (Рене Генон)",
|
||||
"sources": [{
|
||||
"author": "Рене Генон",
|
||||
"work": "Символы священной науки",
|
||||
"excerpt": chapter_body[:1000],
|
||||
"target_field_suggestion": "meta_synthesis"
|
||||
}],
|
||||
"illustrations": [],
|
||||
"created_at": timestamp_str,
|
||||
"updated_at": timestamp_str
|
||||
}
|
||||
external_count += 1
|
||||
|
||||
print(f"\n✅ Завершено: Обогащено знаков Оракула 999: +{enriched_count}")
|
||||
print(f"✅ Добавлено внешних священных символов Генона: +{external_count}")
|
||||
|
||||
# Сохраняем обновленные базы
|
||||
with open(STAGING_DB_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(staging_db, f, ensure_ascii=False, indent=2)
|
||||
|
||||
with open(MAIN_DB_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(staging_db, f, ensure_ascii=False, indent=2)
|
||||
|
||||
with open(EXTERNAL_DB_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(external_db, f, ensure_ascii=False, indent=2)
|
||||
|
||||
with open(ENRICHER_EXTERNAL_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(external_db, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print("💾 Базы данных успешно сохранены и синхронизированы.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user