API reference
Every public function and the Theory class. The three functions whose name
matches their module (diagram, dossier, simulate) are documented by their
canonical path so the function, rather than the module, is shown.
theoryforge
theoryforge: systematic theory development.
A rigorous, reproducible workflow for building, developing and testing scientific
theories. This is the feature-parity twin of the R package of the same name
(https://pablobernabeu.github.io/theoryforge/r/). Every public function has an
identically behaving counterpart there, pinned by the shared public specification
(https://github.com/pablobernabeu/theoryforge/blob/main/API_SPEC.md), so the two
implementations produce identical verdicts and byte-identical diagram intermediate
representations. The only exceptions are the assistive helpers that depend on a
network service or a user-supplied embedder (fetch_corpus, osf_push and
embedding_redundancy) and the language-native diagram renderer
(render_diagram), which are documented as such.
Theory
A theory as a versioned, machine-checkable object.
Wraps the parsed mapping (self.data); all accessors tolerate missing
optional collections by treating them as empty.
Source code in src/theoryforge/core.py
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 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 113 114 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 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
appraise_amendment(prior)
Progressive vs degenerating verdict for this theory relative to a prior version.
Source code in src/theoryforge/core.py
255 256 257 | |
compile_sem()
Compile constructs and propositions to lavaan model syntax.
Source code in src/theoryforge/core.py
271 272 273 | |
diagram(type='nomological_net', engine='graphviz')
Return the diagram IR for type (one of nomological_net, provenance,
causal_dag, development_roadmap, pipeline, context, workflow, venn, rigour,
severity).
Source code in src/theoryforge/core.py
239 240 241 242 243 | |
dossier()
A reviewer-facing audit bundle of rigour report, severity, provenance, and preregistration.
Source code in src/theoryforge/core.py
275 276 277 | |
embedding_redundancy(embedder, threshold=None)
An opt-in embedding-based redundancy screen; results depend on the supplied embedder.
Source code in src/theoryforge/core.py
284 285 286 | |
landscape(corpus, min_link=2)
Map this theory and its alternatives onto a literature corpus's themes.
Source code in src/theoryforge/core.py
263 264 265 | |
new_evidence_dois(candidate_dois)
DOIs in candidate_dois not already cited by this theory's evidence or alternatives.
Source code in src/theoryforge/core.py
267 268 269 | |
osf_push(token=None, node=None, filename=None, dry_run=True, base_url=None)
Deposit the dossier on OSF (dry-run by default). A live push needs a token and node.
Source code in src/theoryforge/core.py
292 293 294 295 296 | |
preregister(path=None)
Render a preregistration document (and write it if a path is given).
Source code in src/theoryforge/core.py
259 260 261 | |
render_diagram(type='nomological_net')
Render a digraph view via the optional graphviz library; see
:func:theoryforge.render.render_diagram.
Source code in src/theoryforge/core.py
245 246 247 248 249 | |
render_report(path, title=None, render=False, to='html')
Write (and optionally render) a Quarto report of the audit dossier.
Source code in src/theoryforge/core.py
288 289 290 | |
severity()
Per-prediction risk and computed severity from the operationalised rubric.
Source code in src/theoryforge/core.py
251 252 253 | |
simulate(steps=10, dt=0.1, k=1.0, damping=0.5, init=1.0)
Integrate the construct network as a linear dynamical system.
Source code in src/theoryforge/core.py
279 280 281 282 | |
validate(*, full=False)
Structural validation against the schema's required fields and enums.
Returns True on success, raises ValueError listing every problem found.
With full=True additionally checks referential integrity: that every
id is unique within its collection and that every cross-reference
(proposition endpoints, prediction derivations and diagnostics,
assumption/evidence/test-outcome targets) points to a declared id. The
full checks are deterministic.
Source code in src/theoryforge/core.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
read(path)
Read a theory object from a YAML or JSON file.
Source code in src/theoryforge/core.py
302 303 304 305 306 307 308 309 | |
write(theory, path)
Write a theory object to YAML or JSON (chosen by file extension).
Source code in src/theoryforge/core.py
312 313 314 | |
new_theory(id, title, maturity='building', theory_form='network')
Start a new, empty theory object (BUILDING mode entry point).
Source code in src/theoryforge/core.py
317 318 319 320 321 322 323 324 325 326 327 | |
check(T)
Compute the full rigour report (dict) for a Theory or theory mapping.
Source code in src/theoryforge/rigor.py
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 | |
report(T, format='json')
Render the rigour report. format in {'json', 'html'}.
Source code in src/theoryforge/rigor.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
redundancy_check(T)
Pairwise lexical similarity of construct definitions.
Returns one record per unordered construct pair, sorted by descending
similarity then (a, b) ascending.
References
Le, H., Schmidt, F. L., Harter, J. K., & Lauver, K. J. (2010). The problem of empirical redundancy of constructs. Organizational Behavior and Human Decision Processes, 112(2), 112-125. https://doi.org/10.1016/j.obhdp.2010.02.003 Lawson, K. M., & Robins, R. W. (2021). Sibling constructs. Personality and Social Psychology Review, 25(4), 344-366. https://doi.org/10.1177/10888683211047101
Source code in src/theoryforge/redundancy.py
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 | |
tokens(s)
Tokenise a string into a set of content tokens.
Source code in src/theoryforge/redundancy.py
21 22 23 24 25 | |
jaccard(a, b)
Source code in src/theoryforge/redundancy.py
28 29 30 31 32 33 | |
severity(T)
Per-prediction risk and computed severity, in file order.
References
Mayo, D. G. (2018). Statistical inference as severe testing. Cambridge University Press. https://doi.org/10.1017/9781107286184 Meehl, P. E. (1990). Why summaries of research on psychological theories are often uninterpretable. Psychological Reports, 66, 195-244. https://doi.org/10.2466/pr0.1990.66.1.195
Source code in src/theoryforge/scoring.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
appraise_amendment(new, prior)
Appraise an amendment as progressive, degenerating, or neutral relative to a prior version.
References
Lakatos, I. (1970). Falsification and the methodology of scientific research programmes. In Criticism and the growth of knowledge (pp. 91-196). Cambridge University Press. https://doi.org/10.1017/cbo9781139171434.009 Meehl, P. E. (1990). Appraising and amending theories. Psychological Inquiry, 1(2), 108-141. https://doi.org/10.1207/s15327965pli0102_1
Source code in src/theoryforge/develop.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
preregister(T, path=None)
Render a preregistration document, writing it to path when one is given.
Source code in src/theoryforge/prereg.py
23 24 25 26 27 28 29 30 31 32 33 34 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 | |
read_corpus(path)
Read a literature corpus from YAML or JSON.
Source code in src/theoryforge/lit.py
25 26 27 28 29 30 31 32 | |
litmap(corpus, min_link=DEFAULT_MIN_LINK)
Keyword co-occurrence, thematic components, and co-citation, all deterministic.
Source code in src/theoryforge/lit.py
87 88 89 90 91 92 93 94 95 96 97 98 99 | |
landscape(theory, corpus, min_link=DEFAULT_MIN_LINK)
Map a theory and its registered alternatives onto the literature's themes.
Source code in src/theoryforge/lit.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
lit_diagram(obj, type='keyword_cooccurrence')
DOT for the literature layer. type in {keyword_cooccurrence, co_citation, theme_landscape}.
Source code in src/theoryforge/lit.py
187 188 189 190 191 192 193 194 195 196 | |
fetch_corpus(query, per_page=25, mailto=None)
Build a corpus from the OpenAlex API (network call).
This adapter is assistive. It depends on a live external service whose results change over time, so it sits outside the package's deterministic core.
Source code in src/theoryforge/lit.py
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 | |
new_evidence_dois(theory, candidate_dois)
DOIs in candidate_dois not already cited by the theory's evidence or alternatives.
Compares by normalised form (lowercased, with any doi.org/dx.doi.org URL prefix stripped), so a fresh literature search, for example via OpenAlex, Scopus, or any other source, can be checked against what the theory already engages with. Returns the qualifying DOIs in their original form, deduplicated and sorted by normalised form. Deterministic and takes no network dependency: the search itself is left to whichever literature tool the caller prefers.
Source code in src/theoryforge/lit.py
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 | |
compile_sem(T)
Source code in src/theoryforge/sem.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
embedding_redundancy(T, embedder, threshold=None)
Pairwise cosine similarity of embedded construct definitions.
embedder maps a definition string to a numeric vector. Returns one record per unordered
construct pair, sorted by descending similarity then (a, b), with a review/ok flag.
Source code in src/theoryforge/embedding.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
render_report(T, path, title=None, render=False, to='html')
Write a Quarto report for the theory; render it with Quarto when render=True.
Returns the path of the written .qmd.
Source code in src/theoryforge/report_render.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
render_diagram(x, type='nomological_net')
Render a digraph view without leaving Python.
Where :func:theoryforge.diagram.diagram returns the deterministic Graphviz
DOT string, render_diagram wraps it in a graphviz.Source, which
displays inline in Jupyter and renders to a file with its render method.
Requires the optional graphviz <https://pypi.org/project/graphviz/>_
library (pip install theoryforge[render]) and, to write image files, the
Graphviz system binaries.
The three chart views (venn, rigour and severity) are already
SVG, so they come back as an :class:SVGString, which also displays inline
in Jupyter. The causal_dag view emits dagitty syntax rather than DOT, so
it is not rendered here; paste it into a dagitty tool instead.
Parameters
x:
A :class:~theoryforge.core.Theory, a parsed theory mapping, or a
diagram IR string from diagram() or lit_diagram(), so literature
diagrams render the same way.
type:
The diagram type, as in diagram(). Ignored when x is already an
IR string.
Returns
graphviz.Source or SVGString
A graphviz.Source for the digraph views; an :class:SVGString for
the chart views.
Source code in src/theoryforge/render.py
31 32 33 34 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 84 85 86 87 88 89 90 91 92 93 | |
osf_push(T, token=None, node=None, filename=None, dry_run=True, base_url=_DEFAULT_BASE)
Deposit the theory's dossier on OSF.
With dry_run=True (default) the planned request is returned and nothing is sent. A live
upload (dry_run=False) requires both token and node (the OSF project id).
Source code in src/theoryforge/osf.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
theoryforge.diagram.diagram(T, type='nomological_net', engine='graphviz')
Return the diagram IR string for the requested type.
engine is accepted but has no effect, because the IR is engine-independent
(DOT for the digraphs, dagitty syntax for the causal DAG, and SVG for the Venn,
the rigour grid and the severity chart).
Source code in src/theoryforge/diagram.py
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 | |
theoryforge.dossier.dossier(T)
Source code in src/theoryforge/dossier.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 | |
theoryforge.simulate.simulate(T, steps=10, dt=0.1, k=1.0, damping=0.5, init=1.0)
Integrate the theory's construct network as a linear dynamical system.
Returns {states, dt, steps, trajectory}, where trajectory[t] is the state vector at step t (t = 0..steps), each value rounded to 6 decimals.
Source code in src/theoryforge/simulate.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |