neurolang.utils.engine_registry#
Declarative engine registry for the neurolang-query CLI.
Engines are declared in engines/engines.yaml, into whose entries
the files engines/<engine>/*.yaml (their example queries and the
query assistant’s guidance) are merged with OmegaConf. Each engine may
define:
Python initialisation scripts (
python_init): a module name, or a list of them, whoseinit_engine(nl, mask, data_dir, **options)run in order, each given all the keyword arguments ofpython_init_options(aninit_enginetakes**optionsfor those of the others);optional Datalog initialisation code (
datalog_init) evaluated after the Python script;optional CSV/TSV relations (
relations) loaded as extensional predicates after the Datalog init. Each relation entry may carry optionalnameanddescriptionfields for predicate metadata used by the--list-predicatescommand. Thefilevalue may be a URL (http:///https://) for automatic download;downloads— files to fetch (with optional archive extraction);templates— neuroimaging templates (brain masks, anatomical templates) downloaded via nilearn or TemplateFlow (if thetemplateflowpackage is installed). Each template may optionally register avoxel(i, j, k)predicate from its non-zero mask:templates: mni_brain: source: nilearn variant: brain_mask predicate: voxel t1_ref: source: templateflow template: MNI152NLin2009cAsym resolution: 1
ontologies— OWL/RDF ontologies to load from URLs or local paths;builtins— list of known function names (exp,log,startswith, etc.) to register as callable symbols;probabilistic_choice— uniform probabilistic choices declared asname: {source: other_predicate}.resamplings— replicates of a probabilistic choice for confidence intervals,name: {choice: selected_study, n: 1000, scheme: bayesian, seed: 0}, used asRESAMPLE[name](pred(x)) = b(seeadd_resampling()).atlases— brain atlases downloaded via nilearn (e.g.destrieux,schaefer,difumo) and registered as predicates withExplicitVBRregions. Deterministic atlases areAtlasobjects, fetched as.load_atlas(name, kind=...)fetches them, added byadd_atlas_setand recorded in the engine’satlases; probabilistic atlases are thresholded (default 0.5) to create binary region masks.extends— one engine name, or a list of them, whose configuration is inherited (seeresolve_engine_config()); engines markedabstract: trueonly serve as bases and cannot be built or listed;solver_mixins— classes, as"module:Class"strings, put before the solver of the engine’sNeurolangPDL(the classes ofdimension_type_predicatesafter them), e.g. pattern-matching mixins adding Datalog commands.name(...); inherited parent first;text_embeddings— semantic search over document texts (e.g. PubMed abstracts) with SPECTER2, registered as a functionf(query, doc) -> similarity, withf_cutoff(query)the 95th percentile of the similarities to the query, orinfif the mean of its 20 largest is belowsimilarity_gate(0.75 by default); seeneurolang_apps.utils.text_embeddings:text_embeddings: study_abstracts: ids_from: study source: pubmed # or {file: ...} or {predicate: ...} function: query_similarity similarity_gate: 0.75
Usage#
from pathlib import Path
from neurolang.utils.engine_registry import (
build_engine,
show_engines,
list_engine_names,
get_engine_config,
)
# Load engine from the built-in YAML
nl = build_engine("neurosynth", data_dir=Path("data"))
# Load engine from a custom YAML file
nl = build_engine("my_engine", yaml_path=Path("my_engines.yaml"),
data_dir=Path("data"))
# Print available engines with descriptions
show_engines()
# List engine names from a custom YAML
for name in list_engine_names(yaml_path=Path("my_engines.yaml")):
print(name)
Functions
|
Return the |
|
Return the colour, |
|
Return how much the studies cover the regions of the atlas image img, the rows |
|
Return the values labelling each region of the atlas name of nl in the image of its grid ( |
|
Create and populate a |
|
Return the pairs of |
|
Return the rows of |
|
Return the engine whose |
|
Return the names of the grids of the engine cfg. |
|
Return the acknowledgements of the data of an engine (its own and those of the engines it extends): a text per source, with its citation. |
|
Return the YAML configuration dict for a single engine. |
|
Return the settings of the Euclidean join an engine changes. |
|
Return the predicates of an engine its SQUALL completion withholds. |
|
Return the predicate metadata dict for an engine from its YAML config. |
|
Return the predicates of an engine declared with a probability. |
|
Return the arguments of the predicates of an engine, by predicate. |
|
Return the sorts an engine declares, by name. |
|
Return the |
|
Return the names of all registered, non-abstract engines. |
|
Return the rows of the CSV or TSV file path as a DataFrame. |
|
Return the column separator of the relation file path. |
|
Return the configuration of name with all |
|
Print a formatted description of all available engines. |
Classes
|
An argument of a predicate: an entity of a sort over columns. |
|
A sort of entities an engine declares once, in its |
Exceptions
|
Raised for a relation file whose extension is not supported. |