Metadata-Version: 2.4
Name: svar-query
Version: 0.1.0
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Jupyter
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Rust
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Dist: pandas>=2 ; extra == 'charts'
Requires-Dist: spectacular-charts[notebook]>=0.2 ; extra == 'charts'
Requires-Dist: pandas>=2 ; extra == 'notebook'
Requires-Dist: ipython>=8 ; extra == 'notebook'
Requires-Dist: spectacular-charts[notebook]>=0.2 ; extra == 'notebook'
Requires-Dist: pandas>=2 ; extra == 'pandas'
Provides-Extra: charts
Provides-Extra: notebook
Provides-Extra: pandas
License-File: LICENSE
Summary: Runs the queries people already write and returns with each result what it means: answered, empty or never reached, where it came from, and what was left unread.
Keywords: sparql,knowledge graphs,federated query,provenance,bioinformatics,jupyter
Author-email: Kundai Farai Sachikonye <kundai.f.sachikonye@gmail.com>
Maintainer: Kundai Farai Sachikonye
License: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Bug Tracker, https://git.uni-greifswald.de/sachikonyk/svar/issues
Project-URL: Changelog, https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/CHANGELOG.md
Project-URL: documentation, https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/docs/usage.md
Project-URL: repository, https://git.uni-greifswald.de/sachikonyk/svar

# svar

svar runs the queries people already write as they are. With each result it returns what the result
means: whether it was answered, empty or never reached, where it came from, and how much was left
unread. The name is "answer" in Swedish, Norwegian and Danish; expanded, it reads Staged Verdicts, Answers
and Residue.

svar hosts existing query languages instead of replacing them. It composes queries into plans across
many sources and checks, before any request, whether each source can do what it is asked. Every step
returns a verdict beside its rows.

## Status

Milestones M1 to M4 are built. Plans in the HFQ (Hegel Federated Query) core grammar are parsed, checked
against a source registry, and run. A plan is refused before contact when a source cannot do what a step
asks. A plan that passes runs step by step through adapters, and each step returns a verdict beside its
rows. The adapters reach local Resource Description Framework (RDF) files, endpoints of the SPARQL
Protocol and RDF Query Language (SPARQL), REST (Representational State Transfer) interfaces, triple
pattern fragments and identifier maps.

- **M2:** hosted SPARQL leaves are sent as written, and their needs are read from their algebra. A
  differential harness verifies declared capabilities against a local reference engine.
- **M3:** stages make absence claimable. Aggregates report a bound and the residue, filters get controls
  that can fail, and two routes measure their divergence. The budget is allocated by water-filling, and
  two runs are compared only under equal stage keys.

- **M4:** values are decided by margin against a threshold set from an error budget, over candidates
  frozen before anything is read. Witnesses read passages for observations, copies of one text count
  once, and a language model may propose candidates, cues and claims. What it writes is recorded and
  never counts as evidence; its claims are checked against sources, and prose written from the answer
  records is checked sentence by sentence.

Types and projection let a graph source witness an expectation beside text sources
([decision 0010](https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/docs/blueprint/decisions/0010-types-projection-and-use.md)). A catalogue of tested
registry entries for ten public services (Rhea, UniProt, UniProtKB, KEGG, ChEBI, the Ontology Lookup Service (OLS4), PubChem, MetaNetX,
Reactome, Europe PMC) lets another project start without writing its own.

Resolution and computation (M5) are next. The full design and the milestones are in the
[blueprint](https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/docs/blueprint/index.md).

## Install

```bash
pip install "svar-query[notebook]"     # imports as `svar`; Python 3.11 or later; with pandas and spectacular-charts
```

The distribution is called `svar-query` because the name `svar` on the Python Package Index belongs to an
unrelated project.

## In a notebook

```python
import svar

svar.sources()                                   # ready-made entries for public services
registry = svar.catalogue("kegg", "metanetx")    # a registry, with no file
report = svar.run("""
plan first {
  budget 20 requests
  let chebi = from METANETX ask chebi_of_kegg("cpd:C00031") within 2
  emit chebi with provenance
}
""", registry)
report                                           # one row per step, with its verdict
report.frame()                                   # as a pandas DataFrame
```

`%load_ext svar` adds the `%%svar` cell magic: the cell holds a plan, and `--sources kegg,metanetx`
names the catalogue entries it asks. Charts are drawn with
[spectacular-charts](https://pypi.org/project/spectacular-charts/): `report.edges()` is the plan's
dataflow for a `layers` chart, and `report.frame("a", "b")` stacks the rows of several steps.
`jupyter/00-quickstart.ipynb` runs a full example against the live services.

## In a project

```bash
cargo install --git https://git.uni-greifswald.de/sachikonyk/svar svar-cli
svar sources                                  # the catalogue
svar init . --sources kegg,metanetx,rhea      # writes svar/registry.toml, svar/plans/first.svar
svar run svar/plans/first.svar --registry svar/registry.toml --out svar/runs/first
```

`svar.init(".", ["kegg", "metanetx"])` does the same from Python. The [usage guide](https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/docs/usage.md)
covers plans, verdicts, a project's own records as a source, adding sources, and decisions from
evidence. The [extensions page](https://git.uni-greifswald.de/sachikonyk/svar/src/branch/main/docs/blueprint/extensions.md) pairs each extension of the Data
Catalog Vocabulary application profiles (DCAT-AP-PLUS) with the catalogue entries that serve its open
values.

## Layout

- `crates/`: the Rust workspace, where all computing happens (`svar-core`, `svar-lang`, `svar-engine`,
  `svar-exec`, `svar-adapters`, `svar-cli`, and `svar-py` for the Python bindings).
- `src/svar/`: the Python package, a thin layer over the extension module for prototyping and notebooks.
- `src/svar/examples/`: example plans, a registry of declarations, and in `fixtures/` small sources that run
  offline.
- `jupyter/`: demonstration notebooks.

## Build

Requires a Rust toolchain and [uv](https://docs.astral.sh/uv/).

```bash
cargo test                      # the Rust core
uv sync                         # builds the Python extension with maturin
uv run pytest                   # the Python layer
cargo run -p svar-cli -- check src/svar/examples/hfq-enzymes.svar --registry src/svar/examples/registry.toml
cargo run -p svar-cli -- run src/svar/examples/hfq-enzymes.svar --registry src/svar/examples/fixtures/registry.toml --out runs/hfq
cargo run -p svar-cli -- run src/svar/examples/staged.svar --registry src/svar/examples/fixtures/registry.toml --out runs/staged
cargo run -p svar-cli -- replay runs/staged
cargo run -p svar-cli -- verify src/svar/examples/verify.toml --registry src/svar/examples/fixtures/registry.toml
cargo run -p svar-cli -- run src/svar/examples/midazolam.svar --registry src/svar/examples/fixtures/midazolam-registry.toml --out runs/midazolam
```

## Example

```text
$ svar check src/svar/examples/refused.svar --registry src/svar/examples/registry.toml
plan pathway_counts  sha256:f5907c41…
outcome: refused-statically (0 requests issued)
  refused S1 counts: `counts` needs {agg, link} from `KEGG`, which declares {lookup, link}

$ svar run src/svar/examples/baseline.svar --registry src/svar/examples/fixtures/registry.toml --out runs/baseline
plan baseline  sha256:1ba483da…
outcome: completed (8 requests issued)
verdict: answered
  acids        answered         4 rows
  rxns         answered         5 rows
  ecs          answered         5 rows
  kids         answered         5 rows
  paths        answered         5 rows
record: runs/baseline/record.jsonl (28 acts)
```

From Python:

```python
import svar

report = svar.check(open("src/svar/examples/hfq-enzymes.svar").read(), "src/svar/examples/registry.toml")
report["outcome"], report["requests_issued"]        # ('well-capable', 0)

run = svar.run(open("src/svar/examples/baseline.svar").read(), "src/svar/examples/fixtures/registry.toml", "runs/py")
run["verdict"]["verdict"], run["requests_issued"]   # ('answered', 8)
```

## License

MIT; the full text is in the license file at the repository root.

