Overview
I had the opportunity to use “ARC2 RDF Graph Visualization” published by Masahide Kanzaki from Python, so here are my notes.
The public page for “ARC2 RDF Graph Visualization” is below.
https://www.kanzaki.com/works/2009/pub/graph-draw
By providing RDF described in Turtle, RDF/XML, JSON-LD, TriG, or Microdata as input, you can obtain visualization results as png or svg files.
Usage Example in Python
import requests
text = "@prefix ns1: <http://example.org/propery/> .\n\n<http://example.org/bbb> ns1:aaa \"ccc\" ."
output_path = "./graph.png"
# Data needed for POST request
url = "https://www.kanzaki.com/works/2009/pub/graph-draw"
data = {
"RDF": text,
"rtype": "turtle",
"gtype": "png",
"rankdir": "lr",
"qname": "on",
}
# Send POST request
response = requests.post(url, data=data)
# Check if response is not a PNG image
if response.headers['Content-Type'] != 'image/png':
print("Response is not a PNG image. Displaying content:")
# print(response.text[:500]) # Display first 500 characters # [:500]
else:
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# Save response as PNG file
with open(output_path, 'wb') as f:
f.write(response.content)
Summary
I hope this is helpful for visualizing RDF data.