Diary parser¶
gutenberg_kg.diary.parser
¶
parser.py — Parse Project Gutenberg diary markdown into dated PSV entries.
Supports multiple diary date formats via pluggable parser subclasses:
pepys— ALL-CAPS MONTH YEAR section headers +Month Nth.entries (Pepys, any standard Gutenberg diary)evelyn— Day-first inline year:29th December, 1659.boswell— Weekday prefix, no inline year:Sunday, 15th August(year anchored at construction time, default 1773)
Use :func:get_parser to select a parser by format name, or instantiate
directly. The module-level :func:parse and :func:write_psv use the
Pepys format for backward compatibility.
Output: pipe-delimited lines compatible with DiaryTransformer::
TIMESTAMP | diary | prose | CONTENT
BaseDiaryParser
¶
Bases: ABC
State-machine base for Gutenberg diary parsing.
Subclasses implement :meth:_match_section and :meth:_match_date.
Set requires_section_header = True (Pepys) to skip date matching
before the first section header fires; leave False (Evelyn, Boswell)
to start accumulating from the first matched date line.
parse(md_path)
¶
Yield dated entries from a Gutenberg diary markdown file.
:yields: :class:ParsedEntry in chronological order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_path
|
Path
|
Path to the downloaded markdown. |
required |
Source code in src/gutenberg_kg/diary/parser.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
BoswellParser(anchor_year=1773)
¶
Bases: BaseDiaryParser
Boswell format: Sunday, 15th August — weekday prefix, no inline year.
The tour (1773) spans a single year, supplied via anchor_year.
Source code in src/gutenberg_kg/diary/parser.py
373 374 | |
EvelynParser
¶
Bases: BaseDiaryParser
Evelyn format: day-first with inline year — 29th December, 1659.
Each entry carries its own year; no section headers. Handles the older
ordinal d suffix used by Evelyn (3d, 22d).
ParsedEntry(timestamp, content, source_line)
dataclass
¶
One dated diary entry extracted from a Gutenberg diary markdown.
PepysParser
¶
get_parser(fmt)
¶
Return the parser for fmt (default: pepys if unknown).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmt
|
str
|
Format name — one of |
required |
Returns:
| Type | Description |
|---|---|
BaseDiaryParser
|
Shared :class: |
Source code in src/gutenberg_kg/diary/parser.py
403 404 405 406 407 408 409 | |
parse(md_path)
¶
Parse using the Pepys format (default). See :func:get_parser for others.
Source code in src/gutenberg_kg/diary/parser.py
417 418 419 | |
write_psv(entries, out_path)
¶
Write parsed entries as a pipe-delimited file for DiaryTransformer.
Format per line::
TIMESTAMP | diary | prose | CONTENT
Pipe characters within content are replaced with em-dashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Iterator[ParsedEntry]
|
Iterator of :class: |
required |
out_path
|
Path
|
Destination |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of lines written. |
Source code in src/gutenberg_kg/diary/parser.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |