Rosetta¶
Rosetta, inspired by the Rosetta Stone, transforms e.g. between:
- Text Encodings (e.g. UTF-8 β ISO 8859-1 etc.)
- RDF Turtle β JSON-LD β YAML-LD β Enola Things
- YAML & JSON β RDF Turtle with JSON-LD Contexts
YAML
βJSON
βTextProto
β Binary Protocol Buffer “Wire” formats.
Specifying the --schema
flag is optional for YAML <=> JSON conversion, but required for TextProto.
YAML to JSON¶
$ ./enola rosetta --in=file:docs/use/library/model.yaml --out=file:docs/use/library/model.json --schema=EntityKinds
The model.json
file now contains:
{"kinds":[{"id":{"ns":"demo","entity":"book_kind","paths":["isbn"]},"label":"Book (Kind)","emoji":"π","link":{"google":{"label":"Google Book Search","uriTemplate":"https://www.google.com/search?tbm\u003dbks\u0026q\u003disbn:{path.isbn}"}}},{"id":{"ns":"demo","entity":"library","paths":["id"]},"label":"Library","emoji":"π"},{"id":{"ns":"demo","entity":"book","paths":["library","isbn","copy"]},"label":"Book (Copy)","emoji":"π","related":{"library":{"id":{"ns":"demo","entity":"library","paths":["{path.library}"]}},"kind":{"id":{"ns":"demo","entity":"book_kind","paths":["{path.isbn}"]}}}}]}
YAML to TextProto¶
$ ./enola rosetta --in=file:docs/use/library/model.yaml --out=file:docs/use/library/model.textproto --schema=EntityKinds
The model.textproto
file now contains:
kinds {
id {
ns: "demo"
entity: "book_kind"
paths: "isbn"
}
label: "Book (Kind)"
emoji: "π"
link {
key: "google"
value {
label: "Google Book Search"
uri_template: "https://www.google.com/search?tbm=bks&q=isbn:{path.isbn}"
}
}
}
kinds {
id {
ns: "demo"
entity: "library"
paths: "id"
}
label: "Library"
emoji: "π"
}
kinds {
id {
ns: "demo"
entity: "book"
paths: "library"
paths: "isbn"
paths: "copy"
}
label: "Book (Copy)"
emoji: "π"
related {
key: "kind"
value {
id {
ns: "demo"
entity: "book_kind"
paths: "{path.isbn}"
}
}
}
related {
key: "library"
value {
id {
ns: "demo"
entity: "library"
paths: "{path.library}"
}
}
}
}
YAML to Binary Protocol Buffer¶
$ ./enola rosetta --in=file:docs/use/library/model.yaml --out=file:docs/use/library/model.binpb --schema=EntityKinds
The model.binpb
now contains binary protocol buffer wire format.
Turtle π’ to JSON-LD π¶
$ ./enola rosetta --in file:test/picasso.ttl --out file:picasso.jsonld
JSON & YAML to Turtle π’ via JSON-LD¶
Turtle π’ to Things βοΈ¶
$ ./enola rosetta --in file:test/picasso.ttl --out file:picasso.thing.yaml
UTF-8 to ISO 8859-1¶
$ file docs/use/rosetta/hello.txt
docs/use/rosetta/hello.txt: Unicode text, UTF-8 text
$ cat docs/use/rosetta/hello.txt
hello, wΓΆrld π
$ ./enola rosetta --in='file:docs/use/rosetta/hello.txt?charset=UTF-8' --out='file:/tmp/hello-windows.txt?charset=ISO-8859-1'
$ file /tmp/hello-windows.txt
/tmp/hello-windows.txt: ISO-8859 text
$ cat /tmp/hello-windows.txt
hello, wοΏ½rld ?