Skip to content

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.

Terminal window
uv run lokf convert examples/acme-knowledge/metrics/weekly-active-users.md --format ttl

convert takes either a concept file or a bundle directory.

  • Point it at one .md file and it emits just that concept’s triples. IRIs are still resolved against the enclosing bundle, so relative links land on the right subjects.
  • Point it at the bundle directory (examples/acme-knowledge) and it projects every concept at once — the whole graph in one document.
Terminal window
# one concept
uv run lokf convert examples/acme-knowledge/glossary/active-user.md
# the whole bundle
uv run lokf convert examples/acme-knowledge --format nt

--format / -f selects the serialization (default ttl):

Value Serialization
ttl Turtle
nt N-Triples
jsonld JSON-LD
xml RDF/XML
n3 Notation3
trig TriG

By default convert streams to stdout. --output / -o writes to a file instead:

Terminal window
uv run lokf convert examples/acme-knowledge --format nt --output acme.nt
# wrote acme.nt

The just gen-rdf-turtle recipe wraps the Turtle case so it is one word to type and easy to remember:

Terminal window
just gen-rdf-turtle examples/acme-knowledge/metrics/weekly-active-users.md

It runs uv run lokf convert --format ttl {{FILE}} — read-only, safe to run against any concept or bundle.

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 works
print(rdf.serialize("examples/acme-knowledge", "ttl"))
# or get an rdflib.Graph to keep working with
g = 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.