Book graph¶
gutenberg_kg.bookgraph
¶
bookgraph.py — reading one book's knowledge graph off disk.
Corpus discovery and per-book graph loading, with no rendering stack attached:
plain sqlite3 and the layout node/edge records the geometry layer consumes.
Kept apart from :mod:gutenberg_kg.scene so the whole POV-Ray pipeline — find
a book, grow it, write the .pov — runs without an installed PyVista.
:mod:gutenberg_kg.scene re-exports every name here, so existing imports keep
working.
Author: Eric G. Suchanek, PhD
BookMeta(title, genre, book_dir)
dataclass
¶
Lightweight metadata for one corpus book.
load_book_graph(meta)
¶
Load nodes and edges from a book's DocKG SQLite, prefixing all IDs with the book slug to prevent collisions when merging multiple books.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
BookMeta
|
Book metadata including slug and db_path. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[LayoutNode], list[LayoutEdge]]
|
|
Source code in src/gutenberg_kg/bookgraph.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
load_entry_times(meta)
¶
Earliest chunk timestamp per document, for books that carry dates.
DiaryKG stamps every chunk with the entry's date but leaves the document
row's timestamp null, so the entry's date has to come up through its
chunks. The result lets :class:ForestLayout grow a diary's limbs from
its chronology — one limb per year — rather than from position in the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
BookMeta
|
Book metadata. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
|
Source code in src/gutenberg_kg/bookgraph.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
scan_corpus(corpus_root)
¶
Walk corpus_root and return {genre: [BookMeta, ...]} for every
book directory that carries a graph in one of :data:KG_DIRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corpus_root
|
Path
|
Root of the corpus directory tree. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[BookMeta]]
|
Dict mapping genre name to list of book metadata objects. |
Source code in src/gutenberg_kg/bookgraph.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |