Help:Creating Graphs with Semantic MediaWiki

Jump to: navigation, search

Semantic extension(s): Semantic MediaWiki, Semantic Result Formats

Further extension(s): Graphviz, Flowchartwiki, ImageMap

Keyword(s): Semantic graph,

  1. tag


In MediaWiki it is possible to render Text in a graph that even has active internal and external links by using Mediawiki extensions. However combining graph rendering with Semantic MediaWiki features can prove tricky, in particular rendering complex graphs as a result of (a)semantic query(s). Hence this collection of some hints.

Semantic Result Format "graph"

One good way to go is to use the "graph" format based on the graphviz library, see documentation here. This might be a good solution for some purposes. However it does have limitations, such as

  • one graph can contain only results from one query
  • one can only use one node shape in one graph


In particular for flowcharts this is an interesting solution. It also relies on the graphviz software library (without needing the graphviz extension). This is a MW extension, so it does not explicitely make use of SMW annotations.

It's syntax collides with SMW, thus the code needs to be patched and different markup be used in order to coexist with SMW:

GraphViz Extension

Fortunately as of writing this (September 2015) the efforts and work of the graphviz extension ( have been resumed. This also is not a semantic but a plain MW extension, relying (among other) on the graphviz library. However it does not collide with SMW but rather blends in nicely.

This is possibly one of the more powerfull ways to combine semantic data and graph drawing. There is one pitfall to circumvent: GraphViz is a tag extension, yet the MW parser would need to render his results into the

Graph image creation requires permission to upload.


3. Now how to bring these together? The following will *NOT* work:

  <graphviz  format="png" >
   digraph nr2 {
   Hello [shape=oval,URL="[[Hello]]"];
   World [shape=box, URL="{{#show: Name| ?Who}}"];
   Hello -> World

(Note: Even if "Who" is of type text und you add the bracket manually it will not work)

But #tag will do the trick for you:

  {{#tag:graphviz|digraph nr3 {
   Hello [shape=oval,URL="[[Hello]]"];
   World [shape=box, URL="{{#show: Name| ?Who}}"];
   Hello -> World

So what one can do is to construct one or several(!) #show or #ask queries, possibly using the template output format, so to generate the (in this example) 3 inner lines of this code snippet, and all results will render in one single graph. Use conditional statements in the template e.g. to set box vs. oval shape depending on attribute values.