Convert
lokf convert projects LOKF markdown to RDF. It is the CLI in front of
lokf.rdf.serialize: attach the generated context,
expand the JSON-LD, and emit triples — no glue code on your side.
uv run lokf convert examples/acme-knowledge/metrics/weekly-active-users.md --format ttlSingle file vs. bundle
Section titled “Single file vs. bundle”convert takes either a concept file or a bundle directory.
- Point it at one
.mdfile and it emits just that concept’s triples. IRIs are still resolved against the enclosing bundle, so relative links land on the right subjects. The enclosing bundle is the nearest folder above the file whoseindex.mddeclares it (base_iri,lokf_version, …), so a section’s ownindex.mdpage does not cut it short. - Point it at the bundle directory (
examples/acme-knowledge) and it projects every concept at once — the whole graph in one document.
# one conceptuv run lokf convert examples/acme-knowledge/glossary/active-user.md
# the whole bundleuv run lokf convert examples/acme-knowledge --format ntFormats
Section titled “Formats”--format / -f selects the serialization (default ttl):
| Value | Serialization |
|---|---|
ttl |
Turtle |
nt |
N-Triples |
jsonld |
JSON-LD |
xml |
RDF/XML |
n3 |
Notation3 |
trig |
TriG |
Writing to a file
Section titled “Writing to a file”By default convert streams to stdout. --output / -o writes to a file
instead:
uv run lokf convert examples/acme-knowledge --format nt --output acme.nt# wrote acme.ntA domain vocabulary
Section titled “A domain vocabulary”A bundle that validates with lokf validate --schema takes the same file
here; the Domain vocabularies guide says how
to write one, or make one from a published schema with
lokf adapt:
uv run lokf convert knowledge --schema domain.yamlOr declare it once as [tool.lokf] schema = "domain.yaml" in the project’s
pyproject.toml above the bundle, and convert, query, serve, export,
validate and the MCP server all read it.
The graph then uses a JSON-LD context generated from that file. Its classes
and slots project under their own IRIs instead of as lokf: terms, and its
classes count as declared instead of reading as lokf:Concept. A key that
neither that file nor lokf.yaml declares still projects as a lokf: term,
as it does without --schema. Generating the context needs the build extra
(lokf[build]).
The just recipe
Section titled “The just recipe”The just gen-rdf-turtle recipe wraps the Turtle case so it is one word to
type and easy to remember:
just gen-rdf-turtle examples/acme-knowledge/metrics/weekly-active-users.mdIt runs uv run lokf convert --format ttl {{FILE}} — read-only, safe to run
against any concept or bundle.
From Python
Section titled “From Python”The CLI is a thin wrapper. In code, call the same function directly:
from lokf import rdf
# a concept file or a bundle directory — either worksprint(rdf.serialize("examples/acme-knowledge", "ttl"))
# or get an rdflib.Graph to keep working withg = rdf.graph_of("examples/acme-knowledge/metrics/weekly-active-users.md")len(g)See Markdown to RDF for the mechanics of the projection, and Query to run SPARQL over the result.