Author index¶
gutenberg_kg.authors
¶
Author provenance — build corpus/authors/ from reference.md files.
Entry point for callers: :func:build. The CLI wrapper lives at
gutenberg_kg.cli.cmd_authors and exposes this as gutenkg authors.
author_lines(meta)
¶
The list lines of a reference.md ## Author section.
The first author gets the Name line and the provenance lines, which describe that one person. Each further author gets a Co-author line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
dict
|
Book metadata. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The lines, without the heading; empty when there is no author. |
Source code in src/gutenberg_kg/authors.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
build(refresh=False, dry_run=False)
¶
Rebuild corpus/authors/ from all reference.md files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
refresh
|
bool
|
If True, re-fetch the Gutenberg RDF for every book with a
Gutenberg ID and rewrite its |
False
|
dry_run
|
bool
|
If True, print what would happen without writing any files. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
|
Source code in src/gutenberg_kg/authors.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
credit(names)
¶
Join author names into one byline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
Display names, primary author first. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/gutenberg_kg/authors.py
86 87 88 89 90 91 92 93 94 | |
display_name(heading)
¶
Turn a Gutenberg catalog heading into a name in reading order.
Gutenberg files names library-style, "Surname, Forenames, Title".
Splitting on the first comma alone turned "Tolstoy, Leo, graf" into
"Leo, graf Tolstoy" and "Marcus Aurelius, Emperor of Rome" into
"Emperor of Rome Marcus Aurelius". The rules, from the corpus's own names:
- A parenthesized fuller form is dropped: "Wells, H. G. (Herbert George)" is "H. G. Wells".
- A part with a date in it is dropped: "Sunzi, active 6th century B.C." is "Sunzi".
- A peerage keeps its title: "Byron, George Gordon Byron, Baron" is "George Gordon Byron, Baron Byron".
- Any other trailing title is dropped: "Tolstoy, Leo, graf" is "Leo Tolstoy".
- A second part starting lowercase is an epithet and follows the name: "Pliny, the Younger" is "Pliny the Younger".
- A second part containing " of " is a title: "Marcus Aurelius, Emperor of Rome" is "Marcus Aurelius".
- Otherwise the forenames come first: "Dumas, Alexandre" is "Alexandre Dumas".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heading
|
str
|
A name as Gutenberg's RDF or OPDS feed gives it. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The name in reading order; the heading unchanged when nothing in it survives the rules. |
Source code in src/gutenberg_kg/authors.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
parse_reference(path)
¶
Extract author + book metadata from a reference.md file.
Source code in src/gutenberg_kg/authors.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
rewrite_author_section(path, meta, dry_run=False)
¶
Replace the ## Author list in a reference.md with meta's.
Only the run of author lines starting at - **Name**: is replaced; the
rest of the file, including the Gutenberg Published line that follows the
section, is left byte for byte. A file with no Name line, or a meta with
no author (a failed fetch returns none), is never touched, so a network
error cannot erase an author.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The |
required |
meta
|
dict
|
Fresh metadata, as |
required |
dry_run
|
bool
|
Report the change without writing it. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True iff the file was (or would be) changed. |
Source code in src/gutenberg_kg/authors.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
write_author_page(author, books, dry_run=False)
¶
Write corpus/authors/<slug>/author.md and return its path.
Source code in src/gutenberg_kg/authors.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
write_index(authors_books, dry_run=False)
¶
Write corpus/authors/index.md and return its path.
Source code in src/gutenberg_kg/authors.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |