#!/usr/bin/env python3
"""Revelation mapped from the throne outward. Every placing is the text's own preposition, counted from the seated Greek (Nestle 1904)."""
import re, pathlib, collections
D = pathlib.Path(__file__).resolve().parent; R = D.parents[2]
G = dict(l.rstrip("\n").split("\t", 1) for l in (R/"data/corpora/gnt-nestle1904/text/Rev.txt").read_text().split("\n") if "\t" in l)
def g(ref, s): assert s in G["Rev " + ref], (ref, s); return f"{s} ({ref})"
occ = [(r[4:], m.start(), t) for r, t in G.items() for m in re.finditer("θρόν", t)]
N = len(occ); bych = collections.Counter(int(r.split(":")[0]) for r, _, _ in occ)
none = [c for c in range(1, 23) if c not in bych]
RINGS = [
 ("0", "On it", "ἐπί", "One, seated. Never described beyond stone and colour. Said 12 times as “the one seated on the throne”. In the right hand, a book written inside and on the back, sealed with seven seals.",
  [g("4:2", "ἐπὶ τὸν θρόνον καθήμενος"), g("5:1", "ἐπὶ τὴν δεξιὰν τοῦ καθημένου ἐπὶ τοῦ θρόνου βιβλίον"), g("21:5", "ὁ καθήμενος ἐπὶ τῷ θρόνῳ")]),
 ("1", "In the midst of it", "ἐν μέσῳ, ἀνὰ μέσον", "The Lamb, standing, as slain. Also the four living creatures, who are both in the midst and around. The Lamb is the only figure placed in the midst and nowhere else.",
  [g("5:6", "ἐν μέσῳ τοῦ θρόνου καὶ τῶν τεσσάρων ζῴων καὶ ἐν μέσῳ τῶν πρεσβυτέρων Ἀρνίον ἑστηκὸς ὡς ἐσφαγμένον"), g("7:17", "τὸ Ἀρνίον τὸ ἀνὰ μέσον τοῦ θρόνου"), g("4:6", "ἐν μέσῳ τοῦ θρόνου καὶ κύκλῳ τοῦ θρόνου τέσσερα ζῷα")]),
 ("2", "Around it", "κυκλόθεν, κύκλῳ", "A rainbow like emerald. Twenty-four thrones, and elders seated on them in white with gold crowns. The four living creatures, full of eyes. Outside these, angels: ten thousands of ten thousands.",
  [g("4:3", "ἶρις κυκλόθεν τοῦ θρόνου"), g("4:4", "κυκλόθεν τοῦ θρόνου θρόνους εἴκοσι τέσσαρας"), g("5:11", "ἀγγέλων πολλῶν κύκλῳ τοῦ θρόνου καὶ τῶν ζῴων καὶ τῶν πρεσβυτέρων"), g("7:11", "εἱστήκεισαν κύκλῳ τοῦ θρόνου")]),
 ("3", "Before it", "ἐνώπιον", "Seven lamps of fire, which are the seven spirits. A sea of glass like crystal. The golden altar. Here the elders fall and throw down their crowns; here the great multitude stands, the new song is sung, and at the end the dead stand, great and small.",
  [g("4:5", "ἑπτὰ λαμπάδες πυρὸς καιόμεναι ἐνώπιον τοῦ θρόνου"), g("4:6", "ἐνώπιον τοῦ θρόνου ὡς θάλασσα ὑαλίνη"), g("8:3", "τὸ θυσιαστήριον τὸ χρυσοῦν τὸ ἐνώπιον τοῦ θρόνου"), g("7:9", "ἑστῶτες ἐνώπιον τοῦ θρόνου"), g("14:3", "ᾠδὴν καινὴν ἐνώπιον τοῦ θρόνου"), g("20:12", "ἑστῶτας ἐνώπιον τοῦ θρόνου")]),
 ("4", "Out of it", "ἐκ, ἀπό", "Lightnings, voices, thunders. A voice, three times, each at an ending: “It is done”, “Praise our God”, “Behold, the tabernacle”. At the last, a river of water of life.",
  [g("4:5", "ἐκ τοῦ θρόνου ἐκπορεύονται ἀστραπαὶ καὶ φωναὶ καὶ βρονταί"), g("16:17", "φωνὴ μεγάλη ἐκ τοῦ ναοῦ ἀπὸ τοῦ θρόνου λέγουσα Γέγονεν"), g("19:5", "φωνὴ ἀπὸ τοῦ θρόνου ἐξῆλθεν"), g("21:3", "φωνῆς μεγάλης ἐκ τοῦ θρόνου"), g("22:1", "ἐκπορευόμενον ἐκ τοῦ θρόνου τοῦ Θεοῦ καὶ τοῦ Ἀρνίου")]),
 ("5", "Away from its face", "ἀπὸ προσώπου", "Those on earth hide from the face of the one seated. At the judgment earth and heaven themselves flee, and no place is found for them.",
  [g("6:16", "ἀπὸ προσώπου τοῦ καθημένου ἐπὶ τοῦ θρόνου"), g("20:11", "οὗ ἀπὸ τοῦ προσώπου ἔφυγεν ἡ γῆ καὶ ὁ οὐρανός")]),
 ("6", "Toward it", "πρός", "One thing only travels inward from outside: the woman's child, caught up.",
  [g("12:5", "ἡρπάσθη τὸ τέκνον αὐτῆς πρὸς τὸν Θεὸν καὶ πρὸς τὸν θρόνον αὐτοῦ")]),
]
OUT = [
 ("The book", "from the right hand of the seated one, to the Lamb in the midst; the Lamb opens; a living creature says Come; a rider goes out on the earth", [g("5:7", "εἴληφεν ἐκ τῆς δεξιᾶς τοῦ καθημένου ἐπὶ τοῦ θρόνου"), g("6:1", "ἤνοιξεν τὸ Ἀρνίον μίαν ἐκ τῶν ἑπτὰ σφραγίδων"), g("6:1", "ἑνὸς ἐκ τῶν τεσσάρων ζῴων λέγοντος")]),
 ("The altar", "the slain are under it; prayers go up from it; fire from it is thrown on the earth", [g("6:9", "ὑποκάτω τοῦ θυσιαστηρίου τὰς ψυχὰς τῶν ἐσφαγμένων"), g("8:5", "ἐκ τοῦ πυρὸς τοῦ θυσιαστηρίου καὶ ἔβαλεν εἰς τὴν γῆν")]),
 ("The trumpets", "given to the seven angels who stand before God", [g("8:2", "τοὺς ἑπτὰ ἀγγέλους οἳ ἐνώπιον τοῦ Θεοῦ ἑστήκασιν")]),
 ("The bowls", "handed to seven angels by one of the four living creatures; poured out at a voice from the temple", [g("15:7", "ἓν ἐκ τῶν τεσσάρων ζῴων ἔδωκεν τοῖς ἑπτὰ ἀγγέλοις ἑπτὰ φιάλας χρυσᾶς"), g("16:1", "μεγάλης φωνῆς ἐκ τοῦ ναοῦ")]),
]
OTHER = [("Satan's throne, at Pergamum", g("2:13", "ὅπου ὁ θρόνος τοῦ Σατανᾶ")), ("the dragon's throne, given to the beast", g("13:2", "τὸν θρόνον αὐτοῦ καὶ ἐξουσίαν μεγάλην")), ("the beast's throne, on which the fifth bowl is poured", g("16:10", "ἐπὶ τὸν θρόνον τοῦ θηρίου")),
 ("the elders' twenty-four", g("11:16", "καθήμενοι ἐπὶ τοὺς θρόνους αὐτῶν")), ("thrones of those who judge, a thousand years", g("20:4", "εἶδον θρόνους, καὶ ἐκάθισαν ἐπ’ αὐτούς")), ("the great white throne", g("20:11", "θρόνον μέγαν λευκὸν")),
 ("the seat promised to the one who overcomes: in the speaker's own throne", g("3:21", "δώσω αὐτῷ καθίσαι μετ’ ἐμοῦ ἐν τῷ θρόνῳ μου"))]
t = (D/"VISION-FIXED.md").read_text()
def v(s): assert s in t, s; return f"“{s}”"
o = ["# Revelation from the throne outward", "", "Working file, not a deposit. 2026-11-29. Lee Sharks, 02:56: “i need a map of revelation from the throne room outward, as its center”.", "",
 f"Method. Every placing below is the text's own preposition before θρόνος, taken from the seated Greek (Nestle 1904, `data/corpora/gnt-nestle1904/text/Rev.txt`); each phrase is asserted at its verse. The word stands {N} times in Revelation, in {len(bych)} of 22 chapters: " + ", ".join(f"ch. {c}: {bych[c]}" for c in sorted(bych)) + f". Chapters 4 and 5 hold {bych[4] + bych[5]}. It is absent from chapters " + ", ".join(map(str, none)) + ".", "",
 "## 1. The rings", "", "| | Place | Greek | What is there | At |", "|---|---|---|---|---|"]
for n, name, prep, what, refs in RINGS: o.append(f"| {n} | **{name}** | {prep} | {what} | " + "; ".join(refs) + " |")
o += ["", "Read inward to outward: a seated one with a book; in the midst a slain thing standing; around, a rainbow, twenty-four seated, four creatures, then angels without number; before, seven lamps, a glass sea, an altar, and whoever is brought to stand; out of it, weather, a voice, and at last water.", "",
 "## 2. How the action leaves the centre", "", "Nothing in chapters 6 to 16 begins on the earth. Each of the three sevens is handed out from a ring of the throne.", "", "| | Path | At |", "|---|---|---|"]
for a, b, refs in OUT: o.append(f"| {a} | {b} | " + "; ".join(refs) + " |")
o += ["", "So the seals come from ring 0 through ring 1; the trumpets from ring 3; the bowls from ring 2. The altar, in ring 3, is the one place where what happened on earth is held at the centre, and where it is sent back.", "",
 "## 3. The other thrones", "", "The word is not kept for the centre. Seven other uses:", ""] + [f"- {a}: {b}" for a, b in OTHER]
o += ["", "Three belong to the adversary and are on the earth. The last is a promise that the centre has room in it.", "",
 "## 4. The centre at the end", "",
 "1. In chapters 4 to 19 the throne is in heaven and the seer goes up to it: " + g("4:2", "θρόνος ἔκειτο ἐν τῷ οὐρανῷ") + ".",
 "2. At 20:11 it is seen alone, white, with nothing around it, and earth and heaven flee.",
 "3. At 22:1–3 it is in the city that came down, it is “of God and of the Lamb”, and a river and a street run from it: " + g("22:3", "ὁ θρόνος τοῦ Θεοῦ καὶ τοῦ Ἀρνίου ἐν αὐτῇ ἔσται") + ". The Lamb has moved from the midst of the throne to its name.",
 "4. The city has no temple and no lamp but these two (21:22–23). The rings are gone. What was a room in heaven with ranks around it is the middle of a street.", "",
 "## 5. Against the vision, briefly", "", "Three observations; nothing is changed by them.", "",
 "1. Revelation's living figure is at the centre from chapter 5 and everything is handed out from where it stands. The vision has two centres and they are far apart. The first is the star: " + v("In one of them stood a ghost.") + " with " + v("twelve seats stood in a ring") + " around it, and a hand that seven once went round. The second is the room: " + v("In the thirty-sixth there was a room.") + " That is the only place where " + v("he was not a ghost") + ", and it comes after the fall of the city, near the end.",
 "2. In Revelation the slain one takes the book and opens it. In the vision the ghost climbs into the book. Nothing is handed out from that room: the leaves, the letters and the year all go out from the star, where he is a tree.",
 "3. Revelation's centre has a seated one and a standing one. The vision's star has the ghost standing and no one seated but the twelve; its room has a couch and a table and no one sits."]
(D/"THRONE.md").write_text("\n".join(o) + "\n"); print(N, dict(bych), none)
