Skip to content

Instantly share code, notes, and snippets.

@epoz
Created January 29, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epoz/c4d150014732e95eefd44a74593e6a36 to your computer and use it in GitHub Desktop.
Save epoz/c4d150014732e95eefd44a74593e6a36 to your computer and use it in GitHub Desktop.
Scan a NDJSON file of JSON-LD data and convert it to Turtle
# Make sure you have the rdflib and rdflib-jsonld libraries installed
# This gist is the Pythn equivalent of Mark's repo from here: https://github.com/mightymax/ndjson2ttl
# As referenced in this tweet: https://twitter.com/markuitheiloo/status/1355252255327449090
import sys
from rdflib import Graph
for line in open(sys.argv[1]):
g = Graph().parse(data=line, format="json-ld")
print(g.serialize(format="n3").decode("utf8"))
@epoz
Copy link
Author

epoz commented Jan 29, 2021

You can run the script above by calling it with the file to convert as the first argument, for example:
python ndjson2nt.py iconclass.ndjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment