Query, inspect and visualize ontologies encoded via RDF and OWL.
—
Ontospy provides comprehensive documentation generation capabilities for creating professional HTML documentation, interactive visualizations, and various export formats from RDF ontologies. The system supports multiple output formats including Bootstrap-themed websites, D3.js visualizations, and markdown documentation.
Central factory class for building ontology visualizations with customizable themes and output formats.
from ontospy.gendocs.viz_factory import VizFactory
class VizFactory:
def __init__(self, ontospy_graph, title=""):
"""
Initialize visualization factory.
Parameters:
- ontospy_graph (Ontospy): Analyzed ontology graph
- title (str): Custom title for visualization
"""
def infer_best_title(self):
"""
Automatically infer appropriate title from ontology metadata.
Returns:
str: Inferred title based on ontology properties
"""
def build(self, output_path=""):
"""
Generate visualization files in specified directory.
Parameters:
- output_path (str): Directory path for output files
"""
def preview(self):
"""Open generated visualization in default web browser."""High-level functions for managing visualization types, themes, and building documentation outputs.
from ontospy.gendocs.actions import (
show_types, show_themes, build_visualization,
ask_visualization, select_visualization
)
def show_types():
"""Display all available visualization types with descriptions."""
def show_themes():
"""Display all available Bootstrap themes for HTML output."""
def random_theme():
"""
Get random Bootstrap theme selection.
Returns:
str: Random theme name
"""
def validate_theme(theme_try, default):
"""
Validate theme selection against available options.
Parameters:
- theme_try (str): Requested theme name
- default (str): Fallback theme if invalid
Returns:
str: Valid theme name
"""
def ask_visualization():
"""
Interactive prompt for visualization type selection.
Returns:
int: Selected visualization type index
"""
def select_visualization(n):
"""
Select visualization type by index number.
Parameters:
- n (int): Visualization type index
Returns:
class: Visualization class for the selected type
"""
def build_visualization(g, viz_index, path=None, title="", theme=""):
"""
Build complete visualization output.
Parameters:
- g (Ontospy): Analyzed ontology graph
- viz_index (int): Visualization type index
- path (str): Output directory path
- title (str): Custom title for documentation
- theme (str): Bootstrap theme name for HTML output
"""Generate comprehensive HTML documentation with Bootstrap styling, interactive navigation, and professional presentation.
# HTML Single Page Documentation
class Viz_html_single:
"""Generate single-page HTML documentation with complete ontology information."""
# HTML Multi-Page Documentation
class Viz_html_multi:
"""Generate multi-page HTML website with separate pages for each entity type."""Usage example:
import ontospy
from ontospy.gendocs.actions import build_visualization, show_types
# Load ontology
g = ontospy.Ontospy("ontology.owl", build_all=True)
# Show available visualization types
show_types()
# Build HTML multi-page documentation
build_visualization(
g,
viz_index=2, # HTML multi-page
path="./docs",
title="My Ontology Documentation",
theme="cerulean"
)
# Using VizFactory directly
from ontospy.gendocs.viz_factory import VizFactory
factory = VizFactory(g, title="Custom Title")
factory.build(output_path="./output")
factory.preview() # Open in browserGenerate D3.js-based interactive visualizations for exploring ontology structure and relationships.
# D3.js Visualizations
class Viz_d3bar_hierarchy:
"""Bar chart hierarchy visualization showing class/property relationships."""
class Viz_d3bubble_chart:
"""Bubble chart visualization with size representing entity importance."""
class Viz_d3dendogram:
"""Tree dendrogram visualization of hierarchical relationships."""
class Viz_d3pack_hierarchy:
"""Packed circle hierarchy showing nested ontological structures."""
class Viz_d3partition_table:
"""Partition table visualization with interactive navigation."""
class Viz_d3rotating_cluster:
"""Rotating cluster diagram for dynamic hierarchy exploration."""Generate network graph visualizations using Sigma.js for exploring ontology relationships and connectivity.
class Viz_sigmajs:
"""
Sigma.js network graph visualization showing entities as nodes
and relationships as edges with interactive exploration capabilities.
"""Generate markdown documentation suitable for documentation websites, GitHub repositories, and technical documentation systems.
class Viz_markdown:
"""Generate markdown documentation with structured ontology information."""import ontospy
from ontospy.gendocs.actions import (
show_types, show_themes, build_visualization
)
# 1. Load and analyze ontology
print("Loading ontology...")
g = ontospy.Ontospy("http://xmlns.com/foaf/0.1/", build_all=True)
# 2. Show available options
print("Available visualization types:")
show_types()
print("\\nAvailable themes:")
show_themes()
# 3. Generate multiple documentation formats
print("\\nGenerating documentation...")
# HTML multi-page with custom theme
build_visualization(
g,
viz_index=2, # HTML multi-page
path="./docs/html-multi",
title="FOAF Ontology Documentation",
theme="flatly"
)
# Single page HTML
build_visualization(
g,
viz_index=1, # HTML single page
path="./docs/html-single",
title="FOAF Ontology - Complete Reference"
)
# Interactive D3 dendrogram
build_visualization(
g,
viz_index=5, # D3 dendrogram
path="./docs/d3-tree",
title="FOAF Class Hierarchy"
)
# Network graph visualization
build_visualization(
g,
viz_index=10, # Sigma.js network
path="./docs/network",
title="FOAF Relationship Network"
)
# Markdown export
build_visualization(
g,
viz_index=3, # Markdown
path="./docs/markdown",
title="FOAF Ontology Reference"
)
print("Documentation generation complete!")The following visualization types are available (use show_types() for current list):
For HTML visualizations, the following Bootstrap themes are available (use show_themes() for current list):
Generated documentation typically includes:
Interactive visualizations include additional JavaScript libraries and configuration files for dynamic functionality.
Install with Tessl CLI
npx tessl i tessl/pypi-ontospy