Tools¶
Analyzer¶
- class ontolearner.tools.analyzer.Analyzer[source]¶
Bases:
ABCBase class for comprehensive ontology analysis and metrics computation.
This class provides a unified interface for analyzing ontologies and computing both structural topology metrics and dataset quality metrics. It serves as the foundation for ontology benchmarking, quality assessment, and comparative analysis across different domains and ontology types.
The analyzer computes two main categories of metrics: 1. Topology Metrics: Structural properties of the ontology graph including
depth, breadth, connectivity, and knowledge coverage statistics.
Dataset Metrics: Quality and characteristics of extracted learning datasets for the three fundamental ontology learning tasks.
Used by the Processor class to generate comprehensive metrics for ontology repositories and benchmark studies.
Initialize the analyzer.
The analyzer is stateless and can be reused across multiple ontologies.
- static compute_complexity_score(topology_metrics: TopologyMetrics, dataset_metrics: DatasetMetrics, a: float = 0.4, b: float = 6.0, eps: float = 1e-12) float¶
Compute a single normalized complexity score for an ontology.
This function combines structural topology metrics and dataset quality metrics into a weighted aggregate score, then applies a logistic transformation to normalize it to the range [0, 1]. The score reflects overall ontology complexity, considering graph structure, hierarchy, breadth, coverage, and dataset richness.
- Parameters:
topology_metrics (TopologyMetrics) – Precomputed structural metrics of the ontology graph.
dataset_metrics (DatasetMetrics) – Precomputed metrics of extracted learning datasets.
a (float, optional) – Steepness parameter for the logistic normalization function. Default is 0.4.
b (float, optional) – Centering parameter for the logistic function, should be tuned to match the scale of aggregated metrics. Default is 6.0.
eps (float, optional) – Small epsilon to prevent numerical issues in logistic computation. Default is 1e-12.
- Returns:
Normalized complexity score in [0, 1], where higher values indicate more complex ontologies.
- Return type:
float
Notes
Weights are assigned to different metric categories: graph metrics, coverage metrics, hierarchy metrics, breadth metrics, and dataset metrics (term-types, taxonomic, non-taxonomic relations).
Metrics are log-normalized before weighting to reduce scale differences.
The logistic transformation ensures the final score is bounded and interpretable.
- static compute_dataset_metrics(ontology: BaseOntology) DatasetMetrics¶
Compute quality and characteristics metrics for extracted learning datasets.
This method analyzes the machine learning datasets extracted from an ontology to assess their quality, balance, and suitability for the three fundamental ontology learning tasks. The metrics help evaluate dataset richness and identify potential issues like class imbalance or sparse relationships.
The computation analyzes: - Term typing dataset: Number and distribution of term-type mappings - Taxonomic relations: Count of hierarchical relationships - Non-taxonomic relations: Count of semantic associations - Class balance: Average terms per type for distribution analysis
- Parameters:
ontology – Loaded ontology instance. The extract() method will be called to obtain the learning datasets for analysis.
- Returns:
Dataset metrics including counts and distribution measures for all three ontology learning tasks.
- static compute_topology_metrics(ontology: BaseOntology) TopologyMetrics¶
Compute comprehensive structural topology metrics for an ontology.
This method analyzes the NetworkX graph representation of an ontology to extract detailed structural characteristics including graph connectivity, hierarchical organization, and knowledge coverage. The metrics provide insights into ontology complexity, quality, and design patterns.
The computation includes: - Basic graph structure (nodes, edges, roots, leaves) - Hierarchical depth analysis with multi-root support - Breadth distribution across hierarchy levels - Knowledge coverage (classes, properties, individuals)
- Parameters:
ontology – Loaded ontology with NetworkX graph representation. Must have both rdf_graph and nx_graph attributes populated.
- Returns:
Comprehensive topology metrics including all structural measures. Returns zero-valued metrics for empty ontologies.
Visualizer¶
- class ontolearner.tools.visualizer.Visualizer(style_config: Dict | None = None)[source]¶
Bases:
objectClass for visualizing ontology structure and metrics.
Initialize visualizer with optional style configuration.
- static visualize_class_distribution(ontology: BaseOntology, save_path: str | None = None) None¶
Visualize the distribution of classes in the ontology.
- Parameters:
ontology – The ontology to visualize
save_path – Optional path to save the visualization
- visualize_metrics(ontology: BaseOntology, save_path: str | None = None) None¶
Create a comprehensive visualization of ontology metrics.
- Parameters:
ontology – The ontology to visualize
save_path – Optional path to save the visualization