! Introduction
asd
On this page the ''SparqlVisualization'' markup is demonstrated via examples based on the Simpsons ontology from the [Simpsons Demo | Demo - Simpsons]

For using the ''SparqlVisualization'' markup a sparql query with exactly three variables has to be defined. Each triple variable binding of the result set of the query defines one edge of the drawn visualization graph. The first variable value will create the source node, while the third variable value creates the target node. The source and target node will be connected by an edge having the value of variable two.
This can be represented by the following pattern:

{{{
%%SparqlVisualization
SELECT ?source ?edge ?target WHERE { <selection-pattern>}
%
}}}


! Display the Class Hierarchy as a Tree

%%SparqlVisualization
     SELECT ?x ?y ?z WHERE {
	    ?x ?y ?z . 
	    ?x rdfs:subClassOf si:SimpsonsConcept. 
	    ?z rdfs:subClassOf si:SimpsonsConcept. 
	    ?x rdfs:subClassOf ?z.
	    FILTER NOT EXISTS { 
	    	?middleObject rdfs:subClassOf si:SimpsonsConcept. 
	    	?x rdfs:subClassOf ?middleObject. 
	    	?middleObject rdfs:subClassOf ?z.
	    	FILTER (?middleObject != ?x ).
	    	FILTER (?middleObject != ?z ).
 	    }
 	    FILTER (?x != owl:Nothing).
 	    FILTER (?x != ?z).
	    BIND (" " AS ?edge).

}
@rankDir: BT
@linkMode: browse
@size: 700
%


{{{
%%SparqlVisualization
     SELECT ?x ?edge ?z WHERE {
	    ?x ?y ?z . 
	    ?x rdfs:subClassOf si:SimpsonsConcept. 
	    ?z rdfs:subClassOf si:SimpsonsConcept. 
	    ?x rdfs:subClassOf ?z.
	    FILTER NOT EXISTS { 
	    	?middleObject rdfs:subClassOf si:SimpsonsConcept. 
	    	?x rdfs:subClassOf ?middleObject. 
	    	?middleObject rdfs:subClassOf ?z.
	    	FILTER (?middleObject != ?x ).
	    	FILTER (?middleObject != ?z ).
 	    }
 	    FILTER (?x != owl:Nothing).
 	     FILTER (?x != ?z).
	    BIND (" " AS ?edge).

}
@rankDir: BT
@linkMode: browse
@size: 700
%
}}}


! Display the family relations as a graph using labels

One can use the available features of SPARQL to create customized labels for the nodes and edges to generate a more nicely readable visualization.


%%SparqlVisualization
   SELECT ?xLabel ?yLabel ?zLabel WHERE {
	    ?x ?y ?z . 
	    ?x rdf:type si:Human. 
	    ?z rdf:type si:Human.
	    ?x rdfs:label ?xLabel.
	    ?z rdfs:label ?zLabel.
	    FILTER (?y != si:relatedWith).
	    FILTER (?y != si:child).
  	    FILTER (?y != si:parent).
	    FILTER (?y != si:grandparent).
	    FILTER (?z != ?x).
	    BIND (SUBSTR(STR(?y), 33) AS ?yLabel)  
}
@rankDir: BT
@size: 600

%


{{{
   SELECT ?xLabel ?yLabel ?zLabel WHERE {
	    ?x ?y ?z . 
	    ?x rdf:type si:Human. 
	    ?z rdf:type si:Human.
	    ?x rdfs:label ?xLabel.
	    ?z rdfs:label ?zLabel.
	    FILTER (?y != si:relatedWith).
	    FILTER (?y != si:parent).
	    FILTER (?y != si:child).
	    FILTER (?y != si:grandparent).
	    FILTER (?z != ?x).
	    BIND (SUBSTR(STR(?y), 33) AS ?yLabel)  
}
@rankDir: BT
@size: 600
}}}


! Visualize lost of stuff (be careful for large ontologies!)

__Note:__ You can use the option "display svg" from the tool menu on the top right of the visualization to open the diagram in a distinct window. Then you can use browser functions to zoom an navigate the graph.

__Colors__: The annotation ''@colors'' allows to specify a color schema by defining a property. With this property colors can be assigned to Classes and Properties. The color schema for this example can be found on [Visualization Util].


%%SparqlVisualization
    SELECT ?x ?y ?z WHERE {
	    ?x ?y ?z . 
	    FILTER (STRSTARTS(STR(?x), "http://www.example.org/ontology#")).
	    FILTER (STRSTARTS(STR(?z), "http://www.example.org/ontology#")).
	    FILTER NOT EXISTS {?x rdf:type rdfs:Class}.
	    FILTER NOT EXISTS {?z rdf:type rdfs:Class}.
	    FILTER NOT EXISTS {?x rdf:type rdf:Property}.
	    FILTER NOT EXISTS {?z rdf:type rdf:Property}.
	    FILTER (?y != si:relatedWith).
	    FILTER (?y != si:parent).
	    FILTER (?y != si:child).
	    FILTER (?y != si:grandparent).
	    FILTER (?z != ?x).

}
@rankDir: BT
@size: 1200
@colors: si:color
%


{{{
%%SparqlVisualization

    SELECT ?x ?y ?z WHERE {
	    ?x ?y ?z . 
	    FILTER (STRSTARTS(STR(?x), "http://www.example.org/ontology#")).
	    FILTER (STRSTARTS(STR(?z), "http://www.example.org/ontology#")).
	    FILTER NOT EXISTS {?x rdf:type rdfs:Class}.
	    FILTER NOT EXISTS {?z rdf:type rdfs:Class}.
	    FILTER NOT EXISTS {?x rdf:type rdf:Property}.
	    FILTER NOT EXISTS {?z rdf:type rdf:Property}.
	    FILTER (?y != si:relatedWith).
	    FILTER (?y != si:parent).
	    FILTER (?y != si:child).
	    FILTER (?y != si:grandparent).
	    FILTER (?z != ?x).

}
@rankDir: BT
@size: 1200
%
}}}


! Show all Properties of the Simpsons Ontology 


%%SparqlVisualization
    SELECT ?x ?y ?z WHERE {
	    ?x ?y ?z . 
	    ?x rdf:type rdf:Property.
	    FILTER (?x != <http://www.w3.org/2000/01/rdf-schema#Resource>).
	    FILTER (STRSTARTS(STR(?x), "http://www.example.org/ontology#")).
	    FILTER (STRSTARTS(STR(?z), "http://www.example.org/ontology#")).
	    FILTER (?z != ?x).

}
@rankDir: BT
@size: 1200
%


{{{
%%SparqlVisualization

    SELECT ?x ?y ?z WHERE {
	    ?x ?y ?z . 
	    ?x rdf:type rdf:Property.
	    FILTER (?z != <http://www.w3.org/2000/01/rdf-schema#Resource>). 
	    FILTER (STRSTARTS(STR(?x), "http://www.example.org/ontology#")).
	    FILTER (STRSTARTS(STR(?z), "http://www.example.org/ontology#")).
	    FILTER (?z != ?x).

}
@rankDir: BT
@size: 1200
%
}}}

%%package simpsons