CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ontospy

Query, inspect and visualize ontologies encoded via RDF and OWL.

Pending
Overview
Eval results
Files

documentation-generation.mddocs/

Documentation Generation

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.

Capabilities

Visualization Factory

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."""

Documentation Actions

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
    """

HTML Documentation

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 browser

Interactive Visualizations

Generate 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."""

Network Graph Visualization

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.
    """

Markdown Export

Generate markdown documentation suitable for documentation websites, GitHub repositories, and technical documentation systems.

class Viz_markdown:
    """Generate markdown documentation with structured ontology information."""

Complete Workflow Example

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!")

Visualization Types

The following visualization types are available (use show_types() for current list):

  1. HTML Single Page: Complete ontology documentation in a single HTML file
  2. HTML Multi-Page: Professional website with separate pages for classes, properties, etc.
  3. Markdown: Structured markdown suitable for GitHub/documentation sites
  4. D3 Bar Hierarchy: Interactive bar chart showing class/property hierarchies
  5. D3 Bubble Chart: Bubble visualization with entity importance sizing
  6. D3 Dendrogram: Tree diagram of hierarchical relationships
  7. D3 Pack Hierarchy: Packed circle hierarchy visualization
  8. D3 Partition Table: Interactive partition table navigation
  9. D3 Rotating Cluster: Dynamic rotating cluster diagram
  10. Sigma.js Network: Interactive network graph with node/edge exploration

Theme Options

For HTML visualizations, the following Bootstrap themes are available (use show_themes() for current list):

  • default: Standard Bootstrap styling
  • cerulean: Blue-toned professional theme
  • cosmo: Clean, modern appearance
  • flatly: Flat design aesthetic
  • journal: Newspaper-style layout
  • readable: Optimized for text readability
  • simplex: Minimalist design
  • spacelab: Gray-toned professional theme
  • united: Orange-accented theme
  • yeti: Clean, spacious layout

Output Structure

Generated documentation typically includes:

  • index.html: Main entry point with ontology overview
  • classes.html: Complete class listings and details
  • properties.html: Property definitions and relationships
  • individuals.html: Instance data (if included)
  • static/: CSS, JavaScript, and asset files
  • media/: Visualization-specific resources

Interactive visualizations include additional JavaScript libraries and configuration files for dynamic functionality.

Install with Tessl CLI

npx tessl i tessl/pypi-ontospy

docs

cli.md

core-analysis.md

documentation-generation.md

entity-classes.md

index.md

sparql-querying.md

tile.json