lambdamusic / Ontospy

Python library and command-line interface for inspecting and visualizing RDF models aka ontologies.
http://lambdamusic.github.io/Ontospy/
MIT License
219 stars 52 forks source link

Use visualize through a script #10

Closed prokolyvakis closed 7 years ago

prokolyvakis commented 8 years ago

Hello,

I would like to use the "visualize" functionality through scripting, instead of using it through the ontospy shell. How can I do that?

Thank you in advance!

Regards, Prodromos

lambdamusic commented 7 years ago

I'm cleaning up that part of the codebase soon, so will provide an example of how to create visualizations programmatically.

lambdamusic commented 7 years ago

The API isn't very good still, but something like this will work:

In [1]: import ontospy

In [2]: model = ontospy.Ontospy("http://xmlns.com/foaf/0.1/")
----------
Reading: <http://xmlns.com/foaf/0.1/>
.. trying rdf serialization: <xml>
..... success!
----------
Loaded 631 triples.
----------
RDF sources loaded successfully: 1 of 1.
----------
-> http://xmlns.com/foaf/0.1/
Scanning entities...
----------
Ontologies.........: 1
Classes............: 14
Properties.........: 67
..annotation.......: 7
..datatype.........: 26
..object...........: 34
Concepts (SKOS)....: 0
----------

In [3]: from ontospy.viz import VISUALIZATIONS_LIST

In [4]: VISUALIZATIONS_LIST
Out[4]:
[{'Description': '@todo',
  'File-extension': 'html',
  'ID': 'html',
  'Static-files': [],
  'Title': 'Javadoc',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'md',
  'ID': 'markdown',
  'Static-files': [],
  'Title': 'Markdown',
  'Type': 'multi-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'splitter_multi',
  'Static-files': ['jquery-1.7.1.min.js', 'splitter.js'],
  'Title': 'Split Columns',
  'Type': 'multi-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3tree',
  'Static-files': ['d3.layout.tree.js',
   'd3.v2.min.js',
   'jquery-1.7.1.min.js',
   'jquery.slidereveal.min.js'],
  'Title': 'Dendogram',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3packHierarchy',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Pack Hierarchy',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3bubblechart',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Bubble Chart',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3cluster',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Cluster Tree',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3barHierarchy',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Bar Hierarchy',
  'Type': 'single-file'},
 {'Description': '@todo',
  'File-extension': 'html',
  'ID': 'd3partitionTable',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Partition Table',
  'Type': 'single-file'},
 {'Description': 'buggy!',
  'File-extension': 'html',
  'ID': 'd3treePie',
  'Static-files': ['d3.v3.min.js'],
  'Title': 'Tree Pie',
  'Type': 'single-file'}]

In [6]: from ontospy.viz import build_viz

In [7]: out_path = "/Users/michele.pasin/Desktop/temp/"

In [8]: build_viz("http://xmlns.com/foaf/0.1/", model, 0, out_path)
Documentation generated: <file:///Users/michele.pasin/Desktop/temp/httpxmlnscomfoaf01.html>
Out[9]: u'file:///Users/michele.pasin/Desktop/temp/httpxmlnscomfoaf01.html'

For more info, look at these methods:

Hope this helps...