RDF::Trine::Exporter::GraphViz - Serialize RDF graphs as dot graph diagrams
version 0.141
use RDF::Trine::Exporter::GraphViz; my $ser = RDF::Trine::Exporter::GraphViz->new( as => 'dot' ); my $dot = $ser->to_string( $rdf ); $ser->to_file( 'graph.svg', $rdf ); # highly configurable my $g = RDF::Trine::Exporter::GraphViz->new( namespaces => { foaf => 'http://xmlns.com/foaf/0.1/' }, alias => { 'http://www.w3.org/2002/07/owl#sameAs' => '=', }, prevar => '$', # variables as '$x' instead of '?x' url => 1, # hyperlink all URIs # see below for more configuration options ); $g->to_file( 'test.svg', $model );
RDF::Trine::Model includes a nice but somehow misplaced and non-customizable method as_graphviz. This module implements an extended version, put in a extends this method in a RDF::Trine::Exporter object. (actually it is a subclass of RDF::Trine::Serializer as long as RDF::Trine has no common class RDF::Trine::Exporter). This module also includes a command line script rdfdot to create graph diagrams from RDF data.
as_graphviz
This modules derives from RDF::Trine::Serializer with all of its methods (a future version may be derived from RDF::Trine::Exporter). The following methods are of interest in particular:
Creates a new serializer with configuration options as described below.
Serialize RDF data, provided as RDF::Trine::Iterator or as RDF::Trine::Model to a file. $file can be a filehandle or file name. The serialization format is automatically derived from known file extensions.
$file
Serialize RDF data, provided as RDF::Trine::Iterator or as RDF::Trine::Model to a string.
Creates and returns a GraphViz object for further processing. You must provide RDF data as RDF::Trine::Iterator or as RDF::Trine::Model.
Returns the exporter's mime type. For instance if you create an exporter with as => 'svg', this method returns ('image/svg+xml').
as => 'svg'
('image/svg+xml')
Provided as alias for to_file for compatibility with other RDF::Trine::Exporter classes.
to_file
RDF::Trine::Exporter
Provided as alias for to_string for compatibility with other RDF::Trine::Exporter classes.
to_string
Serialize a RDF::Trine::Iterator as graph diagram to a string.
Internal core method, used by to_string and to_file, which one should better call instead.
The following configuration options can be set when creating a new object.
Specific serialization format with dot as default. Supported formats include canonical DOT format (dot), Graphics Interchange Format (gif), JPEG File Interchange Format (jpeg), Portable Network Graphics (png), Scalable Vector Graphics (svg and svgz), server side HTML imape map (imap or map), client side HTML image map (cmapx), PostScript (ps), Hewlett Packard Graphic Language (hpgl), Printer Command Language (pcl), FIG format (fig), Maker Interchange Format (mif), Wireless BitMap format (wbmp), and Virtual Reality Modeling Language (vrml).
dot
gif
jpeg
png
svg
svgz
imap
map
cmapx
ps
hpgl
pcl
fig
mif
wbmp
vrml
Mime type. By default automatically set based on as.
as
General graph style options as hash reference. Defaults to { rankdir => 'TB', concentrate => 1 }.
{ rankdir => 'TB', concentrate => 1 }
Hash reference with general options to style nodes. Defaults to { shape => 'plaintext', color => 'gray' }.
{ shape => 'plaintext', color => 'gray' }
Hash reference with options to style resource nodes. Defaults to { shape => 'box', style => 'rounded', fontcolor => 'blue' }.
{ shape => 'box', style => 'rounded', fontcolor => 'blue' }
Hash reference with options to style literal nodes. Defaults to { shape => 'box' }.
{ shape => 'box' }
Hash reference with options to style blank nodes. Defaults to { label => '', shape => 'point', fillcolor => 'white', color => 'gray', width => '0.3' }.
{ label => '', shape => 'point', fillcolor => 'white', color => 'gray', width => '0.3' }
Code referece with a function that get passed a predicate and variable $_ set to the predicate's URI. The function must return undef to skip the RDF statement or a hash reference with options to style the edge.
$_
Add clickable URLs to nodes You can either provide a boolean value or a code reference that returns an URL when given a RDF::Trine::Node::Resource.
Hash reference with URL aliases to show as resource and predicate labels.
Hash reference with options to style variable nodes. Defaults to { fontcolor => 'darkslategray' }.
{ fontcolor => 'darkslategray' }
Which character to prepend to variable names. Defaults to '?'. You can also set it to '$'. By now the setting does not affect variables in Notation3 formulas.
An URI that is marked as 'root' node.
Add a title to the graph.
Hash reference with mapping from prefixes to URI namespaces to abbreviate URIs. By default the prefix mapping from RDF::NS is used.
This serializer does not support negotiate on purpose. It may optionally be enabled in a future version. GraphViz may fail on large graphs, its error message is not catched yet. Configuration in general is not fully covered by unit tests. Identifiers of blank nodes are not included.
negotiate
Jakob Voß <voss@gbv.de>
This software is copyright (c) 2012 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install RDF::Trine::Exporter::GraphViz, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RDF::Trine::Exporter::GraphViz
CPAN shell
perl -MCPAN -e shell install RDF::Trine::Exporter::GraphViz
For more information on module installation, please visit the detailed CPAN module installation guide.