zettelkasten.enrich¶
zettelkasten.enrich ¶
OpenAlex citation-metrics enrichment (metadata-only refresh).
Fills/refreshes the two citation metrics that power the Papers view's
Influence (cohort-normalized cited_by_count) and citation Recency
(counts_by_year) axes on already-known works — each owned source's
_meta.yaml and each _citations/<id>.yaml — by resolving them through
OpenAlex. Resolution tries the most reliable identifier first: exact DOI, then
exact arXiv id, then a STRICT title+year+author match. The fallbacks exist
because DOI-less arXiv preprints (common in ML/finance corpora) would otherwise
stay pinned at cited_by_count == 0 and drag down the Influence axis; the
title match is deliberately strict (rejecting same-title impostors) so a
DOI-less work is matched to the right paper or left untouched.
Unlike :func:zettelkasten.server.expand_citations, this performs no
citation-graph expansion: it mints no new references/citing works and never
touches the note graph. It only updates cited_by_count + counts_by_year
on works that already exist in the corpus, which is exactly the gap that leaves
Influence pinned at its neutral default and citation Recency dark when a corpus
was ingested without those fields.
Conservative on failure: a DOI that does not resolve (offline, 404, no DOI) is a
no-op for that work — its stored YAML is left untouched — so a partial/offline
run never corrupts the store. Resolved works are refreshed (overwritten) since
cited_by_count/counts_by_year are objective, monotonically-growing
OpenAlex metrics rather than curated fields.
enrich_citation_metrics ¶
enrich_citation_metrics(*, project: str = '', graph: str = '', graphs_dir: Path | None = None, dry_run: bool = False) -> dict[str, Any]
Refresh cited_by_count + counts_by_year for a scope's works.
Scope resolution:
graph— that single owned source plus the citations it references / is cited by.project— the project's owned sources plus their referenced citations.- neither — every owned source plus all citation entities.
With dry_run no network call or write happens; the report lists how many
sources/citations carry a DOI and how many DOI-less ones will be attempted via
the arXiv/title fallback. A live run resolves each work (DOI → arXiv id →
strict title match) through OpenAlex and writes the two metrics back atomically
(resolved works only — an unresolved work is left untouched), reporting a
by_method breakdown of how each was matched.
Source code in zettelkasten/enrich.py
127 128 129 130 131 132 133 134 135 136 137 138 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 174 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 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 | |