Skip to content

Rosetta

Rosetta, inspired by the Rosetta Stone, transforms e.g. between:

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

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 ?