Author voices¶
gutenberg_kg.author_voices
¶
Each author's voice for a moot: gender and a coarse accent, from Wikidata.
A moot's tree speaks as its book's author, so the forest picks a voice of
the author's gender and, where the browser has one, the author's accent.
Neither is in the corpus, so this module looks them up on Wikidata and keeps
them in corpus/authors/voices.json, beside the author pages and apart
from ingestion:
gender:"male","female"orNone, from sex or gender (P21).accent:"en-US","en-GB"orNone, from country of citizenship (P27). An American citizenship givesen-US; a British, Irish or Commonwealth oneen-GB; anything else, including every translated author,None, which leaves the accent to the system.
Each entry also records the Wikidata item and the citizenship labels, so
the table can be reviewed, and its source. An entry whose source is
"manual" is never overwritten; the others are filled in once and kept
unless refreshed.
accent_of(ids)
¶
"en-US", "en-GB" or None for an author's P27 values; American wins.
Source code in src/gutenberg_kg/author_voices.py
74 75 76 77 78 79 80 | |
author_pages(authors_dir=AUTHORS_DIR)
¶
Every author page: slug -> {"name", "title"}.
title is the Wikipedia article title from the page's Wikipedia link,
or None when the page has none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
authors_dir
|
Path
|
|
AUTHORS_DIR
|
Source code in src/gutenberg_kg/author_voices.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
fetch_json(url)
¶
GET url from a Wikimedia API with a descriptive User-Agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The API URL. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The decoded JSON. |
Source code in src/gutenberg_kg/author_voices.py
58 59 60 61 62 63 64 65 66 | |
gender_of(ids)
¶
"male", "female" or None for an author's P21 values.
Source code in src/gutenberg_kg/author_voices.py
69 70 71 | |
look_up(pages, fetch=fetch_json)
¶
Look each author up on Wikidata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pages
|
dict[str, dict]
|
slug -> |
required |
fetch
|
Fetch
|
The JSON fetcher. |
fetch_json
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
slug -> voice entry. An author with no Wikipedia link is found by
name and marked |
Source code in src/gutenberg_kg/author_voices.py
175 176 177 178 179 180 181 182 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 213 214 215 216 217 | |
merge_voices(old, new, refresh=False)
¶
Combine a fresh lookup with the existing table.
A "manual" entry always stays. Other existing entries stay unless
refresh; authors new to the corpus are added.
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
The merged table, sorted by slug. |
Source code in src/gutenberg_kg/author_voices.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
read_voices(path=VOICES_PATH)
¶
The voice table, or {} when it has not been written.
Source code in src/gutenberg_kg/author_voices.py
237 238 239 | |
voice_for(author, voices)
¶
{"gender", "accent"} for a catalog author name, both None when unknown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
author
|
str
|
The author as the catalog names it. |
required |
voices
|
dict[str, dict]
|
The voice table. |
required |
Source code in src/gutenberg_kg/author_voices.py
242 243 244 245 246 247 248 249 | |