API
Main RDFSolve functionalities for extraction, conversion and solving.
- build_ontology_index(schema_class_uris: set[str] | None = None, *, cache_dir: str | None = None, ontology_ids: list[str] | None = None) Any[source]
Build an OntologyIndex from OLS4 metadata.
Delegates to
rdfsolve.ontology.index.build_ontology_index().- Parameters:
schema_class_uris – Set of class IRIs from rdfsolve schemas. When provided, only ontologies whose
baseUrioverlaps with the given URIs are fully indexed.cache_dir – Directory for diskcache (OLS HTTP-response cache). Pass
Noneto disable caching.ontology_ids – Explicit list of OLS4 ontology IDs to index. When provided, the OLS paginated ontology listing is skipped.
- Returns:
- Populated index ready for grounding tier 3 and
path planning.
- Return type:
OntologyIndex
- compose_query_from_paths(paths: list[dict[str, Any]], prefixes: dict[str, str] | None = None, include_types: bool = False, include_labels: bool = True, limit: int = 100, value_bindings: dict[str, list[str]] | None = None) dict[str, Any][source]
Generate a SPARQL query from diagram paths.
- Parameters:
paths – List of path dicts, each with an
edgeslist. Each edge hassource,target,predicate, andis_forward.prefixes – Namespace prefix map (e.g.
{"wp": "http://..."}).include_types – Add
rdf:typeassertions.include_labels – Add
OPTIONAL rdfs:labelclauses.limit – LIMIT for the generated query.
value_bindings – VALUES clause bindings
{var: [uri, ...]}.
- Returns:
Dict with
query(SPARQL string),variable_map(var -> schema URI), andjsonld(SPARQLExecutable JSON-LD).
Example:
>>> from rdfsolve.api import compose_query_from_paths >>> result = compose_query_from_paths( ... paths=[{"edges": [{ ... "source": "http://ex.org/Gene", ... "target": "http://ex.org/Protein", ... "predicate": "http://ex.org/encodes", ... "is_forward": True, ... }]}], ... prefixes={"ex": "http://ex.org/"}, ... ) >>> print(result["query"]) PREFIX ex: <http://ex.org/> ...
- count_instances(endpoint_url: str, sample_limit: int | None = None, sample_offset: int | None = None, chunk_size: int | None = None, offset_limit_steps: int | None = None, delay_between_chunks: float = 20.0, streaming: bool = False) dict[str, int] | Any[source]
Count instances per class at endpoint_url.
Delegates to
count_instances().
- count_instances_per_class(endpoint_url: str, graph_uris: str | list[str] | None = None, sample_limit: int | None = None, exclude_graphs: bool = True) dict[str, int][source]
Return
{class_uri: count}for endpoint_url.Delegates to
count_instances_per_class().
- discover_void_graphs(endpoint_url: str, graph_uris: str | list[str] | None = None, exclude_graphs: bool = False) dict[str, Any][source]
Find VoID graphs at endpoint_url.
Delegates to
discover_void_graphs(). graph_uris and exclude_graphs are accepted for backwards-compatibility but the discovery query always searches all named graphs.
- discover_void_source(endpoint: str, name: str, output_dir: str | Path = '.', *, tag: str = 'discovered_remote', void_uri_base: str | None = None, entry: SourceEntry | dict[str, Any] | None = None, fmt: str = 'all') dict[str, Any][source]
Discover VoID descriptions for one source and export artefacts.
Calls
discover_void_graphs()thenexport_schema_artifacts()for the result.- Parameters:
endpoint – SPARQL endpoint URL.
name – Dataset name.
output_dir – Directory for output files.
tag – File-name tag (default
"discovered_remote").void_uri_base – Explicit base URI override (
None→ resolved viaresolve_void_uri_base()).entry – Source entry dict — used to resolve void_uri_base when no explicit override is given.
fmt – Export format (
"jsonld","void","all").
- Returns:
dict with
partitions_found,graphs_found,files.Returns
partitions_found == 0when the endpoint has no VoIDdata.
- enrich_source_with_bioregistry(entry: SourceEntry) str | None[source]
Populate
bioregistry_*fields on a source entry in-place.Delegates to
rdfsolve.sources.enrich_source_with_bioregistry().- Parameters:
entry – A
SourceEntrydict, modified in-place.- Returns:
The resolved Bioregistry prefix, or
Noneif no match was found.- Return type:
str or None
- execute_sparql(query: str, endpoint: str, method: str = 'GET', timeout: int = 30, variable_map: dict[str, str] | None = None) dict[str, Any][source]
Execute a SPARQL query against a remote endpoint.
- Parameters:
query – Full SPARQL query string.
endpoint – SPARQL endpoint URL.
method – HTTP method (
"GET"or"POST").timeout – Timeout in seconds.
variable_map – Optional mapping of SPARQL ?variable -> schema URI.
- Returns:
Dict with keys
query,endpoint,variables,rows,variable_map,row_count,duration_ms, and optionallyerror.
Example:
>>> from rdfsolve.api import execute_sparql >>> result = execute_sparql( ... query="SELECT ?s WHERE { ?s a ?o } LIMIT 5", ... endpoint="https://sparql.wikipathways.org/sparql/", ... ) >>> result["row_count"] 5
- export_schema_artifacts(void_graph: Graph, name: str, endpoint: str, output_dir: str | Path, tag: str = 'discovered_remote', fmt: str = 'all') dict[str, str][source]
Write VoID / JSON-LD / LinkML / SHACL / RDF-config artefacts.
This is the shared export routine used by
discover_void_source()andmine_local_source().- Parameters:
void_graph – An
rdflib.Graphcontaining VoID triples.name – Dataset name (used in file stems).
endpoint – Endpoint URL written into JSON-LD
@aboutand RDF-config.output_dir – Directory to write files into (created if needed).
tag – File-name tag inserted between name and suffix, e.g.
"discovered_remote"→<name>_discovered_remote_void.ttl.fmt –
"jsonld","void", or"all"(default).
- Returns:
Mapping of artefact kind → file path written.
- Return type:
- extract_partitions_from_void(endpoint_url: str, void_graph_uris: list[str]) list[dict[str, str]][source]
Extract partition records from VoID graphs.
Delegates to
extract_partitions_from_void().
- generate_qleverfiles(sources_path: str | Path | None = None, data_dir: str | Path = '.', *, base_port: int = 7019, runtime: str = 'docker', name_filter: str | None = None, test: bool = False, server_memory: str = '500G') dict[str, Any][source]
Generate Qleverfiles for all downloadable sources.
For each eligible source a per-source
Qleverfileis written to<data_dir>/qlever_workdirs/<name>/Qleverfile.Additionally, for every
local_providergroup a combinedQleverfileis written that indexes all member sources together into one QLever instance.- Parameters:
sources_path – Path to sources file (
None→ default).data_dir – Root directory where RDF dumps live.
base_port – First port number for allocation.
runtime –
"docker"or"native".name_filter – Regex to select sources by name.
test – If
True, generate only for the 3 smallest sources.server_memory –
MEMORY_FOR_QUERIESwritten into every Qleverfile (-mflag passed toqlever-server). Defaults to"500G". Lower this when many servers run concurrently on a single node.
- Return type:
dict with
generated,skipped,failedlists.
- generate_void_from_endpoint(endpoint_url: str, graph_uris: str | list[str] | None = None, output_file: str | None = None, counts: bool = True, offset_limit_steps: int | None = None, exclude_graphs: bool = True, dataset_uri: str | None = None, void_base_uri: str | None = None) Graph[source]
Mine a VoID description from a SPARQL endpoint.
Deprecated since version Use:
mine_schema()instead.Delegates to
generate_void_from_endpoint().
- get_bioregistry_metadata(br_prefix: str) dict[str, Any][source]
Return a structured metadata dict for a Bioregistry prefix.
Delegates to
rdfsolve.sources.get_bioregistry_metadata().- Parameters:
br_prefix – A valid Bioregistry prefix (e.g.
"drugbank","chebi").- Returns:
Fields:
prefix,name,description,homepage,license,domain,keywords,publications,uri_prefix,uri_prefixes,synonyms,mappings,logo,extra_providers.- Return type:
- Raises:
ValueError – If br_prefix is unknown to Bioregistry.
- graph_to_jsonld(graph: Graph, graph_uris: str | list[str] | None = None, filter_void_admin_nodes: bool = True, endpoint_url: str | None = None, dataset_name: str | None = None) dict[str, Any][source]
Convert a VoID graph to JSON-LD format.
- Parameters:
graph – RDFLib Graph with VoID data
graph_uris – Graph URIs to filter extraction
filter_void_admin_nodes – Remove VoID and administrative nodes
endpoint_url – SPARQL endpoint URL for the @about section
dataset_name – Dataset name for the @about section
- Returns:
JSON-LD with @context, @graph, and @about
- graph_to_linkml(graph: Graph, graph_uris: str | list[str] | None = None, filter_void_nodes: bool = True, schema_name: str | None = None, schema_description: str | None = None, schema_base_uri: str | None = None) str[source]
Convert a VoID graph to LinkML YAML schema.
- Parameters:
graph – RDFLib Graph with VoID data
graph_uris – Graph URIs to filter extraction
filter_void_nodes – Remove VoID-specific nodes
schema_name – Name for the schema
schema_description – Description for the schema
schema_base_uri – Base URI for the schema
- Returns:
LinkML YAML schema string
- graph_to_schema(void_graph: Graph, graph_uris: str | list[str] | None = None, filter_void_admin_nodes: bool = True) DataFrame[source]
Convert VoID graph to schema DataFrame.
- Parameters:
void_graph – RDFLib graph with VoID data
graph_uris – Graph URIs to extract
filter_void_admin_nodes – Filter VoID or administrative nodes
- Returns:
DataFrame with schema patterns (subject/property/object URIs)
- graph_to_shacl(graph: Graph, graph_uris: str | list[str] | None = None, filter_void_nodes: bool = True, schema_name: str | None = None, schema_description: str | None = None, schema_base_uri: str | None = None, closed: bool = True, suffix: str | None = None, include_annotations: bool = False) str[source]
Convert a VoID graph to SHACL shapes.
Generates SHACL (Shapes Constraint Language) shapes from a VoID graph. SHACL shapes define constraints on RDF data and can be used for validation.
- Parameters:
graph – RDFLib Graph with VoID data
graph_uris – Graph URIs to filter extraction
filter_void_nodes – Remove VoID-specific nodes
schema_name – Name for the schema
schema_description – Description for the schema
schema_base_uri – Base URI for the schema
closed – Generate closed shapes (only allow defined properties)
suffix – Optional suffix for shape names (e.g., “Shape”)
include_annotations – Include class/slot annotations in shapes
- Returns:
SHACL shapes as Turtle/RDF string
Example
>>> from rdflib import Graph >>> from rdfsolve.api import graph_to_shacl >>> void_graph = Graph() >>> void_graph.parse("dataset_void.ttl", format="turtle") >>> shacl_ttl = graph_to_shacl(void_graph, schema_name="my_dataset")
- import_semra_source(source: str, keep_prefixes: list[str] | None = None, output_dir: str = 'docker/mappings/semra', mapping_type: str = 'instance') dict[str, Any][source]
Import mappings from a SeMRA source and write one JSON-LD per prefix.
Delegates to
rdfsolve.semra_converter.import_source().- Parameters:
source – SeMRA source key (e.g.
"biomappings").keep_prefixes – Optional prefix filter.
output_dir – Directory for output files.
mapping_type –
"instance"(default) or"class". When"instance", the output JSON-LD contains instance-level edges that can be passed toderive_class_mappings_from_instances().
- Returns:
Summary dict
{"succeeded", "failed", "skipped"}.
- import_sssom_source(entry: dict[str, Any], output_dir: str = 'docker/mappings/sssom', mapping_type: str = 'instance') dict[str, Any][source]
Download and convert one SSSOM source entry to JSON-LD files.
Thin wrapper around
rdfsolve.sssom_importer.import_sssom_source().For each
.sssom.tsvfile found inside the archive atentry["url"], one JSON-LD file is written to output_dir:{source_name}__{sssom_file_stem}.jsonld
- Parameters:
entry – Dict with at least
"name"and"url"keys, as found indata/sssom_sources.yaml.output_dir – Directory to write output JSON-LD files.
mapping_type –
"instance"(default) or"class". Stored in the@about.mapping_typefield of each output JSON-LD file.
- Returns:
Summary dict with keys
"succeeded","failed","skipped".
- infer_mappings(input_paths: list[str], output_path: str, *, inversion: bool = True, transitivity: bool = True, generalisation: bool = False, chain_cutoff: int = 3, dataset_name: str | None = None) dict[str, Any][source]
Run the SeMRA inference pipeline over mapping JSON-LD files.
Thin wrapper around
rdfsolve.inference.infer_mappings(). See that function for full documentation.- Parameters:
input_paths – Paths to input mapping JSON-LD files.
output_path – Path to write the inferenced mapping JSON-LD.
inversion – Apply symmetric inversion.
transitivity – Apply transitive chain inference.
generalisation – Apply generalisation.
chain_cutoff – Max chain length for transitivity.
dataset_name – Override for
@about.dataset_name.
- Returns:
Summary dict with
"input_edges","output_edges","inference_types","output_path".
- load_mapping_jsonld(path: str) dict[str, Any][source]
Load a mapping JSON-LD file from disk.
- Parameters:
path – Path to a
.jsonldfile.- Returns:
Parsed JSON dict.
- load_ontology_index(data_dir: str | Path = 'data') Any[source]
Load a persisted OntologyIndex from data_dir.
Delegates to
rdfsolve.ontology.index.load_ontology_index().- Parameters:
data_dir – Directory that contains
ontology_index.pkl.gzand (optionally)ontology_graph.graphml, as written bysave_ontology_index().- Returns:
Restored index.
- Return type:
OntologyIndex
- Raises:
FileNotFoundError – If
ontology_index.pkl.gzdoes not exist under data_dir.
- load_parser_from_file(void_file_path: str, graph_uris: str | list[str] | None = None, exclude_graphs: bool = True) VoidParser[source]
Load a VoID file and return a parser for schema extraction.
- Parameters:
void_file_path – Path to VoID Turtle file
graph_uris – Graph URIs to filter queries
exclude_graphs – Exclude system graphs
- Returns:
VoidParser instance
- load_parser_from_graph(graph: Graph, graph_uris: str | list[str] | None = None, exclude_graphs: bool = True) VoidParser[source]
Load a VoID graph and return a parser for schema extraction.
- Parameters:
graph – RDFLib Graph with VoID data
graph_uris – Graph URIs to filter queries
exclude_graphs – Exclude system graphs
- Returns:
VoidParser instance
- load_parser_from_jsonld(jsonld_path: str, graph_uris: str | list[str] | None = None, exclude_graphs: bool = True) VoidParser[source]
Load a mined-schema JSON-LD file and return a VoidParser.
Reads the JSON-LD produced by
rdfsolve mine, reconstructs aMinedSchemaviaMinedSchema.from_jsonld(), converts it to an in-memory VoID RDF graph, and wraps it in aVoidParserready for export to CSV / LinkML / SHACL / RDF-config.- Parameters:
jsonld_path – Path to a
*_schema.jsonldfile produced byrdfsolve mine.graph_uris – Graph URIs to filter (passed through to VoidParser).
exclude_graphs – Exclude system graphs.
- Returns:
VoidParser instance backed by the converted VoID graph.
- load_sources(path: str | Path | None = None, name_filter: str | None = None) list['SourceEntry'][source]
Load source entries, optionally filtered by name regex.
Re-exports
rdfsolve.sources.load_sources()with an optional name_filter convenience argument.- Parameters:
path – Path to the sources file (YAML / JSON-LD / CSV).
Nonefalls back to the defaultdata/sources.yaml.name_filter – Regex pattern (case-insensitive) to select sources by name.
Nonereturns all sources.
- mine_all_sources(sources_csv: str | None = None, *, sources: str | None = None, output_dir: str = '.', fmt: str = 'all', chunk_size: int = 10000, class_chunk_size: int | None = None, class_batch_size: int = 15, delay: float = 0.5, timeout: float = 120.0, counts: bool = True, reports: bool = True, filter_service_namespaces: bool = True, untyped_as_classes: bool = False, authors: list[dict[str, str]] | None = None, on_progress: Callable[[str, int, int, str | None], None] | None = None) dict[str, Any][source]
Mine schemas for all sources in a JSON-LD or CSV file.
Delegates to
rdfsolve.miner.mine_all_sources().
- mine_local_source(endpoint: str, name: str, output_dir: str | Path = '.', *, graph_uris: list[str] | None = None, void_uri_base: str | None = None, entry: SourceEntry | dict[str, Any] | None = None, chunk_size: int = 10000, class_batch_size: int = 15, class_chunk_size: int | None = None, timeout: float = 120.0, counts: bool = True, one_shot: bool = False, untyped_as_classes: bool = False, fmt: str = 'all', authors: list[dict[str, str]] | None = None, discover_first: bool = False, qlever_version: dict[str, str] | None = None) dict[str, Any][source]
Mine a single dataset from a (local) SPARQL endpoint.
Calls
rdfsolve.miner.mine_schema()(returnsMinedSchema) then exports artefacts viaexport_schema_artifacts().When discover_first is
Truea VoID discovery pass is run before mining and its results are saved with thediscovered_localtag.- Parameters:
endpoint – SPARQL endpoint URL (typically
http://localhost:<port>).name – Dataset name.
output_dir – Directory for output files.
graph_uris – Named-graph URIs to scope mining queries.
Nonemeans “use entry’s graph_uris if available, else mine all graphs”.void_uri_base – Explicit VoID base URI override.
entry – Source entry dict — used for graph_uris fallback and void_uri_base resolution.
chunk_size
class_batch_size
class_chunk_size
timeout
counts
:param : :param one_shot: Forwarded to
rdfsolve.miner.mine_schema(). :param untyped_as_classes: Forwarded tordfsolve.miner.mine_schema(). :param fmt: Forwarded tordfsolve.miner.mine_schema(). :param authors: Forwarded tordfsolve.miner.mine_schema(). :param discover_first: Run VoID discovery before mining. :param qlever_version:{"git_hash_server": ..., "git_hash_index": ...}from?cmd=stats. Written into the mining report.- Return type:
dict with
classes,properties,files,report_path.
- mine_schema(endpoint_url: str, graph_uris: str | list[str] | None = None, dataset_name: str | None = None, chunk_size: int = 10000, class_chunk_size: int | None = None, class_batch_size: int = 15, delay: float = 0.5, timeout: float = 120.0, counts: bool = True, two_phase: bool = True, report_path: str | None = None, filter_service_namespaces: bool = True, authors: list[dict[str, str]] | None = None) dict[str, Any][source]
Mine RDF schema from a SPARQL endpoint using SELECT queries.
This is a simpler, faster alternative to generate_void_from_endpoint that avoids heavy CONSTRUCT queries. Returns a MinedSchema which can export to JSON-LD or be converted to a VoID graph.
- Parameters:
endpoint_url – SPARQL endpoint URL
graph_uris – Graph URI(s) to restrict queries
dataset_name – Human-readable dataset name
chunk_size – Pagination page size
class_chunk_size – Page size for Phase-1 class discovery (
None= single query, no pagination)class_batch_size – Number of classes to group into one VALUES query in Phase-2 (default 15)
delay – Delay between pages (seconds)
timeout – HTTP timeout per request
counts – Whether to fetch triple counts
two_phase – Use two-phase mining (default
True). PassFalsefor the legacy single-pass strategy.report_path – If given, write analytics JSON to this path
filter_service_namespaces – Strip service/system namespace patterns from the result (default
True)
- Returns:
JSON-LD dict with @context, @graph, and @about
- probe_instance_mapping(prefix: str, sources_csv: str | None = None, *, sources: str | None = None, predicate: str = 'http://www.w3.org/2004/02/skos/core#narrowMatch', dataset_names: list[str] | None = None, timeout: float = 60.0, inter_request_delay: float = 0.0) dict[str, Any][source]
Probe SPARQL endpoints for a bioregistry resource and return JSON-LD.
For every dataset in sources (or the subset in dataset_names), queries the endpoint for RDF classes whose instances match the resource’s known URI prefixes. Generates pairwise
skos:narrowMatchedges (or predicate override) between classes across different datasets and returns the result as a JSON-LD mapping document.- Parameters:
prefix – Bioregistry prefix, e.g.
"ensembl".sources_csv – Deprecated - use sources instead.
sources – Path to the sources file (JSON-LD or CSV). When
None, auto-detects the default file.predicate – Mapping predicate URI. Defaults to
skos:narrowMatch.dataset_names – Restrict probing to these dataset names.
timeout – SPARQL request timeout in seconds.
inter_request_delay – Seconds to sleep before each SPARQL request. Use a positive value for remote public endpoints;
0.0(default) for local QLever.
- Returns:
JSON-LD
dictwith@context,@graph,@about.- Raises:
ValueError – If prefix is unknown to bioregistry.
- resolve_iris(iris: list[str], endpoints: list[dict[str, Any]], timeout: int = 15) dict[str, Any][source]
Resolve IRIs against SPARQL endpoints to discover their rdf:type.
- Parameters:
iris – List of IRI strings to resolve.
endpoints – List of endpoint dicts, each with keys
name,endpoint, and optionallygraph.timeout – Per-endpoint timeout in seconds.
- Returns:
Dict with keys
resolved,not_found,errors.
Example:
>>> from rdfsolve.api import resolve_iris >>> result = resolve_iris( ... iris=["http://identifiers.org/ncbigene/1234"], ... endpoints=[{ ... "name": "wikipathways", ... "endpoint": "https://sparql.wikipathways.org/sparql/", ... }], ... ) >>> result["resolved"] {...}
- resolve_void_uri_base(name: str, override: str | None = None, entry: SourceEntry | dict[str, Any] | None = None) str[source]
Return the VoID base URI for a dataset.
Resolution order:
Explicit override value (e.g. from
--void-uri-base).void_uri_basefield in the source entry.Default template
https://jmillanacosta.com/rdfsolve/{name}/mined/.
- retrieve_void_from_graphs(endpoint_url: str, void_graph_uris: list[str], graph_uris: str | list[str] | None = None, partitions: list[dict[str, str]] | None = None) Graph[source]
Build a VoID RDF graph from partition data.
Delegates to
retrieve_void_from_graphs().
- seed_inferenced_mappings(input_dir: str = 'docker/mappings', output_dir: str = 'docker/mappings/inferenced', output_name: str = 'inferenced_mappings', inversion: bool = True, transitivity: bool = True, generalisation: bool = False, chain_cutoff: int = 3) dict[str, Any][source]
Infer over all mappings in input_dir and write to output_dir.
Thin wrapper around
rdfsolve.inference.seed_inferenced_mappings().- Parameters:
input_dir – Directory containing mapping subdirs.
output_dir – Directory for output.
output_name – Stem for the output file.
inversion – Apply inversion inference.
transitivity – Apply transitivity inference.
generalisation – Apply generalisation.
chain_cutoff – Max chain length.
- Returns:
Summary dict from
infer_mappings().
- seed_instance_mappings(prefixes: list[str], sources_csv: str | None = None, *, sources: str | None = None, output_dir: str = 'docker/mappings/instance_matching', predicate: str = 'http://www.w3.org/2004/02/skos/core#narrowMatch', dataset_names: list[str] | None = None, timeout: float = 60.0, skip_existing: bool = False, ports_json: str | None = None, inter_request_delay: float = 0.0) dict[str, Any][source]
Probe multiple bioregistry resources and write mapping JSON-LD files.
Delegates to
rdfsolve.instance_matcher.seed_instance_mappings().
- seed_semra_mappings(sources: list[str], keep_prefixes: list[str] | None = None, output_dir: str = 'docker/mappings/semra', mapping_type: str = 'instance') dict[str, Any][source]
Seed semra mapping files for multiple sources.
Delegates to
rdfsolve.semra_converter.seed_semra_mappings().
- seed_sssom_mappings(sssom_sources_yaml: str = 'data/sssom_sources.yaml', output_dir: str = 'docker/mappings/sssom', names: list[str] | None = None, mapping_type: str = 'instance') dict[str, Any][source]
Seed SSSOM mapping files for all (or selected) sources.
Thin wrapper around
rdfsolve.sssom_importer.seed_sssom_mappings().Reads sssom_sources_yaml, optionally filters to names, and calls
import_sssom_source()for each entry.- Parameters:
sssom_sources_yaml – Path to the SSSOM sources YAML file (default:
data/sssom_sources.yaml).output_dir – Directory for output JSON-LD files (default:
docker/mappings/sssom).names – Optional list of source names to restrict processing; if
None(default), all entries are processed.mapping_type –
"instance"(default) or"class". Stored in the@about.mapping_typefield of each output JSON-LD file.
- Returns:
Aggregated summary with keys
"succeeded","failed","skipped".
- sources_to_jsonld(entries: list[SourceEntry], *, enrich: bool = False) dict[str, Any][source]
Serialise source entries to a JSON-LD document.
Delegates to
rdfsolve.sources.sources_to_jsonld().- Parameters:
entries – Source entries, typically returned by
load_sources().enrich – When
True, resolve and embed Bioregistry metadata for each source before serialisation (entries are not modified in place).
- Returns:
JSON-LD document with
@contextand@graphkeys.- Return type:
- to_jsonld_from_file(void_file_path: str, filter_void_admin_nodes: bool = True, endpoint_url: str | None = None, dataset_name: str | None = None, graph_uris: str | list[str] | None = None) dict[str, Any][source]
Convert a VoID file to JSON-LD format.
- Parameters:
void_file_path – Path to VoID file
filter_void_admin_nodes – Remove VoID and administrative nodes
endpoint_url – SPARQL endpoint URL for the @about section
dataset_name – Dataset name for the @about section
graph_uris – Graph URIs for the @about section
- Returns:
JSON-LD with @context, @graph, and @about
- to_linkml_from_file(void_file_path: str, filter_void_nodes: bool = True, schema_name: str | None = None, schema_description: str | None = None, schema_base_uri: str | None = None) str[source]
Convert a VoID file to LinkML YAML schema.
- Parameters:
void_file_path – Path to VoID file
filter_void_nodes – Remove VoID-specific nodes
schema_name – Name for the schema
schema_description – Description for the schema
schema_base_uri – Base URI for the schema
- Returns:
LinkML YAML schema string
- to_rdfconfig_from_file(void_file_path: str, filter_void_nodes: bool = True, endpoint_url: str | None = None, endpoint_name: str | None = None, graph_uri: str | None = None) dict[str, str][source]
Convert a VoID file to RDF-config YAML files.
RDF-config is a schema standard that describes RDF data models using YAML configuration files. This function generates three files: - model.yml: Class and property structure - prefix.yml: Namespace prefix definitions - endpoint.yml: SPARQL endpoint configuration
Note: The rdf-config tool requires these files to be named exactly model.yml, prefix.yml, and endpoint.yml, and placed in a directory named {dataset}_config. The CLI automatically creates this structure.
- Parameters:
void_file_path – Path to VoID file
filter_void_nodes – Remove VoID-specific nodes
endpoint_url – SPARQL endpoint URL (optional)
endpoint_name – Name for endpoint (default: “endpoint”)
graph_uri – Named graph URI (optional)
- Returns:
Dictionary with ‘model’, ‘prefix’, ‘endpoint’ keys containing YAML strings
Example
>>> from rdfsolve.api import to_rdfconfig_from_file >>> rdfconfig = to_rdfconfig_from_file( ... "dataset_void.ttl", ... endpoint_url="https://example.org/sparql", ... graph_uri="http://example.org/graph", ... ) >>> # Save files >>> with open("model.yml", "w") as f: ... f.write(rdfconfig["model"]) >>> with open("prefix.yml", "w") as f: ... f.write(rdfconfig["prefix"]) >>> with open("endpoint.yml", "w") as f: ... f.write(rdfconfig["endpoint"])
- to_shacl_from_file(void_file_path: str, filter_void_nodes: bool = True, schema_name: str | None = None, schema_description: str | None = None, schema_base_uri: str | None = None, closed: bool = True, suffix: str | None = None, include_annotations: bool = False) str[source]
Convert a VoID file to SHACL shapes.
Generates SHACL (Shapes Constraint Language) shapes from a VoID description file. SHACL shapes define constraints on RDF data and can be used for validation.
- Parameters:
void_file_path – Path to VoID file
filter_void_nodes – Remove VoID-specific nodes
schema_name – Name for the schema
schema_description – Description for the schema
schema_base_uri – Base URI for the schema
closed – Generate closed shapes (only allow defined properties)
suffix – Optional suffix for shape names (e.g., “Shape”)
include_annotations – Include class/slot annotations in shapes
- Returns:
SHACL shapes as Turtle/RDF string
Example
>>> from rdfsolve.api import to_shacl_from_file >>> shacl_ttl = to_shacl_from_file( ... "dataset_void.ttl", schema_name="my_dataset", closed=True ... ) >>> with open("schema.shacl.ttl", "w") as f: ... f.write(shacl_ttl)
- to_void_from_file(jsonld_path: str) Graph[source]
Convert a mined-schema JSON-LD file to a VoID RDF graph.
Reads the JSON-LD, reconstructs a
MinedSchema, and returns the equivalent VoID graph (rdflibGraph).- Parameters:
jsonld_path – Path to a
*_schema.jsonldfile.- Returns:
rdflib
Graphcontaining the VoID description.