@click.command("manifest-to-rdf")
@click.argument(
"manifest_path",
type=click.Path(exists=True, dir_okay=False, path_type=pathlib.Path),
)
@click.option(
"--format",
"output_format",
type=click.Choice(["turtle", "json-ld", "nt", "xml"], case_sensitive=False),
default="turtle",
show_default=True,
help="RDF output format.",
)
@click.option(
"--base-uri",
required=True,
help="Base URI for manifest resource IRIs (e.g. https://mygraph.dev/manifests/v1).",
)
@click.option(
"--output",
"output_path",
type=click.Path(dir_okay=False, path_type=pathlib.Path),
default=None,
help="Output file path. Prints to stdout when omitted.",
)
@click.option(
"--include-ontology/--no-include-ontology",
default=True,
show_default=True,
help="Embed GraFlo meta-ontology triples in output.",
)
def manifest_to_rdf(
manifest_path: pathlib.Path,
output_format: str,
base_uri: str,
output_path: pathlib.Path | None,
include_ontology: bool,
) -> None:
"""Convert a GraphManifest YAML file to RDF."""
manifest = _load_manifest(manifest_path)
serializer = ManifestRdfSerializer(include_ontology=include_ontology)
graph = serializer.to_graph(manifest, base_uri)
serialized = graph.serialize(format=output_format.lower())
if output_path is None:
click.echo(serialized)
return
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(serialized, encoding="utf-8")