rudof-project / rudof

RDF data shapes implementation in Rust
https://rudof-project.github.io
Apache License 2.0
39 stars 3 forks source link

Add RDF graph visualization options #102

Open labra opened 3 months ago

labra commented 3 months ago

It would be nice to convert small RDF graphs to SVG, PNG, etc. images.

One approach is to convert the graphs to .dot files and leverage on GraphViz for the conversion to any of those image formats.

We already did that in rdfshape where we converted RDF graphs to Dot in the SGraph module.

We also explored other possibilities like using cytoscape.js which is a javascript port of Cytoscape.

@jonassmedegaard also suggested to explore the use of plantuml like in rdfpuml which uses a perl script.

It would be nice to explore different possibilities for RDF visualizations which could also be adapted for ShEx/SHACL visualizations.

jonassmedegaard commented 3 months ago

Perl-based rdfpuml tries to visualize most possible from an input data graph, optionally reducing by declaring patterns of which nodes or edges to either ignore or only mention within a related node.

Nice about rdfpuml is that styling is expressed in RDF, as a separate styling graph. Unfortunately I have found it cumbersome to reduce a relatively small ontology enough to visualize comprehensively using rdfpuml.

Python-based rdf2dot and rdfs2dot takes the opposite approach of only looking for specific patterns in an input graph.

rdf2dot and rdfs2dot quickly produces comprehensible visualizations but do not allow for semantic customizing. For some sample output, see my recent work on crating an ontology and visualizing it at https://purl.org/learn (only in danish for now, but the visualizations should be comprehensible regardless).

Both approaches, since they produce dot data as output, obviously allow for visual customization by piping through the graphviz commandline tool gvpr.

I see benefit in both approaches, but for starters I recommend to reimplement rdf2dot/rdfs2dot as-is: Simple look for spcific hardcoded patterns, and spit out dot representations for those bits to stdout. Then later that can be extended, by replacing the hardcoded patterns with default shapes matching same/similar patterns and allowing to extend and/or override the default shapes. And later that show-what-we-know can be complemented by a show-most-possible approach - or perhaps that is really same approach of detecting shapes, just with a large library of shapes and a command-line flag to include most possible shapes.

jonassmedegaard commented 3 months ago

On a Debian system you can play with rdf2dot if first installing needed packages:

On a Debian system you can play with rdf2dot like this:

  1. Save the sample graph from https://rdfshape.weso.es/dataInfo as document.ttl
  2. rdf2dot document.ttl | xdot -

To see how a graph can get too messy, try do similar for my tentacular learning ontology:

  1. wget https://purl.org/learn/0.1.1/tentacular.ttl
  2. rdf2dot tentacular.ttl | xdot -

Since it is an RDF-schema-based ontology, see how rdfs2dot does a better job at visualizing the same graph, by looking only narrowly for rdfs-related data in the graph:

  1. rdfs2dot tentacular.ttl | xdot -

I imagine that rdfsx would contain a library of shapes, optimal for different types of graphs, and the default would be to try pick a sensible shape - e.g. in above tentacular.ttl graph notice that the base node is <> rdf:type owl:Ontology.