Skip to content

Commit

Permalink
added tabb
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Sep 28, 2024
1 parent 2f37281 commit bddf59d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
All of the poems in here are good, or interesting. There are currently 8,964 poems in 43 (3.593) languages by 591 (254.902) authors from 54 (9.282) countries.
All of the poems in here are good, or interesting. There are currently 8,967 poems in 44 (3.602) languages by 592 (255.198) authors from 54 (9.280) countries.

(The quantites in the parentheses are the effective counts, based on the entropy of the distribution over the poems.)
21 changes: 21 additions & 0 deletions poems/curator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from .errors import AuthorNotFoundError, PoemNotFoundError
from .catalog import Catalog
from .poem import Author, Poem
from .data import authors

import pandas as pd

here, this_file = os.path.split(__file__)

Expand Down Expand Up @@ -61,8 +64,26 @@ def get_poem(

if very_verbose:
catalog_summary = self.catalog.df.sort_values(["probability", "author"], ascending=[False, False])[["author", "title", "context", "probability"]]

author_summary_entries = {}
for author_index, entry in authors.iterrows():
author_mask = self.catalog.df.author == author_index
author_summary_entries[author_index] = {
**entry.to_dict(),
"n": author_mask.sum(),
"probability": self.catalog.df.loc[author_mask, "probability"].sum().round(6)
}

author_summary = pd.DataFrame(author_summary_entries).T.sort_values(["probability"], ascending=[False])

print(f"choosing from {len(self.catalog.df)} poems; the most likely are:")
print(catalog_summary.iloc[:20].to_string())
print()

print(f"choosing from {len(author_summary)} authors; the most likely are:")
print(author_summary.iloc[:20].to_string())
print()

chosen_loc = np.random.choice(self.catalog.df.index, p=self.catalog.df.probability)
chosen_author, chosen_title = self.catalog.df.loc[chosen_loc, ["author", "title"]]

Expand Down
16 changes: 13 additions & 3 deletions poems/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
with open(f"{here}/poems.json", "r+") as f:
poems = json.load(f)

authors = []
for author_key, d in poems.items():
authors.append(Author(key=author_key, **d["metadata"]))
author_list = []
author_entries = {}
for author_key, author_data in poems.items():
author = Author(key=author_key, **author_data["metadata"])
author_list.append(author)

author_entries[author_key] = {
"name": author.name,
"demonym": author.demonym.lower(),
# "dates": author.dates()[1:-1],
}

authors = pd.DataFrame(author_entries).T
102 changes: 100 additions & 2 deletions poems/data/poems.json
Original file line number Diff line number Diff line change
Expand Up @@ -34125,6 +34125,14 @@
"body": "To be rational about politics\nIs to take a rash step\nFor surely as they change\nYou will find yourself out of step.\n\nAn irrational attitude is better,\nSome bold improbable commitment\nWhich may overlap boundaries\nAnd land you right for 1999.\n\nTo eschew them is the classic mark,\nYet politics assail us inwardly\nAs governments mull our disorder,\nAnd should we wish to be aloof?\n\nA shrewd eye may see a spectacle,\nSavor a style, inject a note,\nBut shrewdness is unpolitical,\nPolitics is the people’s choice.\n\nRush in, unreasonable roysterer,\nDisrupt the game in the grand manner,\nIt is serious to be mistaken,\nIt is pleasant to be two-faced.",
"metadata": {
"language": "English",
"source": {
"title": "Poetry",
"type": "magazine",
"published": {
"year": 1950,
"month": "april"
}
},
"tags": []
}
},
Expand Down Expand Up @@ -52266,6 +52274,9 @@
"title": "“The Dark Angel”",
"body": "Dark Angel, with thine aching lust\nTo rid the world of penitence:\nMalicious Angel, who still dost\nMy soul such subtile violence!\n\nBecause of thee, no thought, no thing,\nAbides for me undesecrate:\nDark Angel, ever on the wing,\nWho never reachest me too late!\n\nWhen music sounds, then changest thou\nIts silvery to a sultry fire:\nNor will thine envious heart allow\nDelight untortured by desire.\n\nThrough thee, the gracious Muses turn,\nTo Furies, O mine Enemy!\nAnd all the things of beauty burn\nWith flames of evil ecstasy.\n\nBecause of thee, the land of dreams\nBecomes a gathering place of fears:\nUntil tormented slumber seems\nOne vehemence of useless tears.\n\nWhen sunlight glows upon the flowers,\nOr ripples down the dancing sea:\nThou, with thy troop of passionate powers,\nBeleaguerest, bewilderest, me.\n\nWithin the breath of autumn woods,\nWithin the winter silences:\nThy venomous spirit stirs and broods,\nO Master of impieties!\n\nThe ardour of red flame is thine,\nAnd thine the steely soul of ice:\nThou poisonest the fair design\nOf nature, with unfair device.\n\nApples of ashes, golden bright;\nWaters of bitterness, how sweet!\nO banquet of a foul delight,\nPrepared by thee, dark Paraclete!\n\nThou art the whisper in the gloom,\nThe hinting tone, the haunting laugh:\nThou art the adorner of my tomb,\nThe minstrel of mine epitaph.\n\nI fight thee, in the Holy Name!\nYet, what thou dost, is what God saith:\nTempter! should I escape thy flame,\nThou wilt have helped my soul from Death:\n\nThe second Death, that never dies,\nThat cannot die, when time is dead:\nLive Death, wherein the lost soul cries,\nEternally uncomforted.\n\nDark Angel, with thine aching lust!\nOf two defeats, of two despairs:\nLess dread, a change to drifting dust,\nThan thine eternity of cares.\n\nDo what thou wilt, thou shalt not so,\nDark Angel! triumph over me:\n_Lonely, unto the Lone I go;\nDivine, to the Divinity._",
"metadata": {
"tags": [
"Favorite"
],
"language": "English",
"source": {
"title": "Poems",
Expand All @@ -52278,7 +52289,6 @@
"time": {
"year": 1893
},
"tags": [],
"context": {
"liturgy": "advent"
}
Expand Down Expand Up @@ -90839,6 +90849,9 @@
"body": "In the years when we were\nall children, this inclining\nto be alone so much was gentle;\nothers’ time passed fighting,\nand one had one’s faction,\none’s near, one’s far-off place,\na path, an animal, a picture.\n\nAnd I still imagined, that life\nwould always keep providing\nfor one to dwell on things within,\nAm I within myself not in what’s greatest?\nShall what’s mine no longer soothe\nand understand me as a child?\n\nSuddenly I’m as if cast out,\nand this solitude surrounds me\nas something vast and unbounded,\nwhen my feeling, standing on the hills\nof my breasts, cries out for wings\nor for an end.",
"metadata": {
"language": "German",
"translators": [
"Edward Snow"
],
"tags": []
}
},
Expand Down Expand Up @@ -114471,6 +114484,91 @@
}
}
},
"john-b-tabb": {
"metadata": {
"name": "John B. Tabb",
"birth": {
"date": {
"year": 1845,
"month": "march",
"day": 22
},
"place": {
"city": "Amelia County",
"state": "Virginia",
"country": "USA"
}
},
"death": {
"date": {
"year": 1909,
"month": "november",
"day": 19
},
"place": {
"city": "Ellicott City",
"state": "Maryland",
"country": "USA"
}
},
"gender": "male",
"occupation": [
"poet",
"priest"
],
"education": null,
"movement": [],
"religion": "Catholic",
"nationality": [
"england"
],
"language": [
"American"
],
"link": "https://en.wikipedia.org/wiki/John_B._Tabb",
"favorite": false,
"tags": [
"English",
"American",
"priest"
]
},
"poems": {
"finis": {
"title": "“Finis”",
"body": "O to be with thee sinking to thy rest,\n Thy journey done;\nThe world thou leavest blessing thee and blest,\n O setting sun;\nThe clouds, that ne’er the morning joys forget,\n Again aglow,\nAnd leaf and flower with tears of twilight wet\n To see thee go.",
"metadata": {
"language": "American",
"tags": [],
"context": {
"season": "autumn"
}
}
},
"a-legacy": {
"title": "“A Legacy”",
"body": "Do you remember, little cloud,\nThis morning when you lay--\nA mist along the river--what\nThe waters had to say?\nAnd how the many-coloured flowers\nThat on the margin grew,\nAll promised when the day was done\nTo leave their tints to you?",
"metadata": {
"language": "American",
"tags": [],
"context": {
"season": "spring"
}
}
},
"song": {
"title": "“Song”",
"body": "Fade not yet, O summer day,\nFor my love hath answered yea.\nKeep us from the coming night,\nLest our blossom suffer blight.\nFear thou not: if love be true,\nCloser will it cleave to you;\n’Tis the darkened hours that prove\nFaith or faithlessness in Love.",
"metadata": {
"language": "American",
"tags": [],
"context": {
"season": "autumn"
}
}
}
}
},
"galaktion-tabidze": {
"metadata": {
"name": "Galaktion Tabidze",
Expand Down Expand Up @@ -125462,7 +125560,7 @@
}
},
"million-roses": {
"title": "“Million roses”",
"title": "“Million Roses”",
"body": "There was painter once,\nOwned a small home and his art.\nBut there’s an actress he loved,\nFlowers were dear to her heart.\n\nSo he sold his house on a whim--\nHis art and his roof, undeterred--\nAnd spent all the money to buy\nA whole sea of flowers for her.\n\nA million, million, million red roses here,\nFrom you room, from your room, from your room, you can view.\nOne in love, one in love, one in love--that’s sincere!--\nWill transform life into flowers for you.\n\nOutside the window, you gaze--\nMaybe your mind’s in a daze?\nYour dream is continuing there,\nFlowers have covered the square.\n\nYour soul turns cold, overwhelmed--\nWhat affluent man went offbeat?\nBut there, not a penny in hand,\nThe painter stands in the street.\n\nTheir meeting was fleeting, of course.\nShe left on the train in the night.\nBut in her life there once was\nThe mad song of roses outside.\n\nThe painter lived all alone.\nThrough much misfortune and gloom.\nBut in his life there once was\nA square full of roses in bloom.",
"metadata": {
"language": "Russian",
Expand Down

0 comments on commit bddf59d

Please sign in to comment.