Skip to content

Multi-part, multi-source datasets

Benchmark datasets that mix several splits and several source formats share one on-disk layout. The reader and writer for that layout is kgpipe.datasets.multipart_multisource.

ODIBEL writes a dataset with this module. KGpipe pipelines and KGI-Bench read the same files with load_dataset. The module stays in KGpipe. Copying it into ODIBEL or KGI-Bench would split the layout across three repositories.

The module uses pydantic and the standard library. It does not import pipeline execution, tasks, or evaluation. Import it directly:

from pathlib import Path

from kgpipe.datasets.multipart_multisource import (
    Dataset,
    EntitiesRow,
    LinksRow,
    MatchesRow,
    SourceType,
    load_dataset,
)

KGpipe itself requires Python >= 3.12. import kgpipe.datasets.multipart_multisource does not load the pipeline runner. Installing the kgpipe package still installs the package dependencies declared in pyproject.toml.

Movie-specific evaluation names, such as a filtered reference graph or a seed-subtracted entity list, stay in the KGI-Bench movie preset. This module only describes the dataset tree.

Layout

load_dataset accepts either layout. Splits may sit directly under the dataset root, which is what the MovieKG release uses, or under a splits/ directory.

film_10k/
├── ontology.ttl                     # or ontology/ontology.ttl
├── entities/
│   └── master_entities.csv          # one column: entity_id
└── split_0/
    ├── index/
    │   └── entities.csv             # one column: entity_id
    ├── kg/
    │   ├── reference/
    │   │   ├── data/                # part files: .nt, .ttl, .nq
    │   │   ├── data.nt              # optional aggregate, not a listed part
    │   │   └── meta/
    │   └── seed/
    │       ├── data/
    │       ├── data.nt
    │       └── meta/
    └── sources/
        ├── rdf/
        │   ├── data/
        │   ├── data.nt
        │   └── meta/
        ├── json/
        │   ├── data/                # .json, .jsonl
        │   └── meta/
        └── text/
            ├── data/                # .txt
            └── meta/

load_dataset records a part only when the file is inside data/ and has one of the extensions for that bundle. An aggregate data.nt next to data/ is a MovieKG convenience for pipelines that want one file. The loader does not add it to parts.

Verified tables are tab-separated and live in the bundle meta/ directory. A file named verfied_*.csv is rejected.

File Columns
verified_entities.csv dataset, entity_id, entity_label, entity_type
verified_matches.csv left_dataset, right_dataset, left_id, right_id, entity_type
verified_links.csv doc_id, entity_id, entity_type, dataset

verified_links.csv is for text and JSON sources. verified_matches.csv is for RDF sources and the reference KG. The seed meta directory carries verified_entities.csv when that file is present.

Reading

KGI-Bench and a pipeline runner both start from the dataset root:

dataset = load_dataset(Path("film_10k"))

split = dataset.splits["split_0"]
seed = split.kg_seed          # KGBundle or None
reference = split.kg_reference
rdf = split.sources["rdf"]    # keys are "rdf", "json", "text"
json_source = split.sources["json"]
text_source = split.sources["text"]

Use these paths when a step needs a file or a directory:

Need Path
Aggregate seed or reference N-Triples bundle.root / "data.nt"
Aggregate RDF source source.root / "data.nt"
JSON or text source directory source.data.dir
Individual part files bundle.data.parts
Ontology dataset.ontology
Verified entities, matches, or links bundle.meta.entities, .matches, .links

VerifiedEntities.read_csv(), VerifiedMatches.read_csv(), and read_links_csv(path) return the row models. A missing optional file stays None. A present file with the wrong header raises ValueError.

Pairwise entity overlap across splits comes from each index/entities.csv:

dataset.overlap_matrix()

Each pair (split_a, split_b) maps to cnt, len_left, len_right, pct_left, and pct_right.

Writing

ODIBEL builds the same tree through the models, then a later load_dataset reads it back.

dataset = Dataset(root=Path("film_10k"))
dataset.set_entities_master(["e1", "e2", "e3"])
dataset.set_splits(0, 4)  # split_0 .. split_3

for split in dataset.splits.values():
    split.set_index([
        EntitiesRow(entity_id="e1", entity_label="E1", entity_type="Film", dataset="seed"),
    ])
    split.set_empty_seed()
    split.set_empty_reference()
    split.set_sources([SourceType.rdf, SourceType.json, SourceType.text])

    rdf = split.sources["rdf"]
    rdf.meta.set_entities([
        EntitiesRow(entity_id="e1", entity_label="E1", entity_type="Film", dataset="rdf"),
    ])
    rdf.meta.set_matches([
        MatchesRow(
            left_dataset="rdf",
            right_dataset="seed",
            left_id="src-1",
            right_id="e1",
            entity_type="Film",
        ),
    ])
    split.sources["json"].meta.set_links([
        LinksRow(doc_id="doc-1", entity_id="e1", entity_type="Film", dataset="json"),
    ])

set_splits, set_empty_seed, set_empty_reference, and set_sources create the directories. The set_* meta methods write the CSV headers above. Part files and an aggregate data.nt are written by the generator into data/ and the bundle root. This module does not serialize RDF.

After writing, load_dataset(dataset.root) is the check that a reader sees the tree the writer just produced.