Select Git revision
postcss.config.js
scorer_batch.py 3.36 KiB
#!/usr/bin/python3.10
# -*-coding:Utf-8 -*-
"""
ontoScorer: Batch Module for comparing multiple pairs of reference and generated ontologies.
------------------------------------------------------------------------------------------
This module facilitates the batch processing of ontology pairs, computing metrics and
generating comparison reports for each pair and a summary report for all.
"""
import os
from ontology import Ontology
from report import Report
from metrics import Metrics
from scorer import OntoScorer
class ScorerBatch:
"""
The ScorerBatch class is used to compare multiple pairs of reference and generated ontologies.
Attributes:
- ontology_pairs (list): List of tuples, where each tuple contains the paths to the reference and generated ontology.
- output_dir (str): Path to the directory where the reports will be written.
- results (list): List of metrics for each pair of ontologies.
"""
def __init__(self, ontology_pairs, equivalent_prefix, output_dir):
"""
Initializes the ScorerBatch with a list of ontology pairs and output directory.
Args:
- ontology_pairs (list): List of tuples. Each tuple contains paths to the reference and generated ontology.
- equivalent_prefix (str): Prefix to handle equivalent terms or concepts.
- output_dir (str): Path to the directory where the reports will be written.
"""
self.ontology_pairs = ontology_pairs
self.equivalent_prefix = equivalent_prefix
self.output_dir = output_dir
self.results = {}
# Create the output directory if it doesn't exist
os.makedirs(self.output_dir, exist_ok=True)
def compute_all_metrics(self):
"""
Computes metrics for each pair of ontologies and stores them in the results dictionary.
"""
for ref_onto, gen_onto in self.ontology_pairs:
scorer = OntoScorer(ref_onto, gen_onto, self.equivalent_prefix)
scorer.compute_metrics()
self.results[(ref_onto, gen_onto)] = scorer.metrics
def generate_all_reports(self):
"""
Generates and writes a report for each pair of ontologies to the output directory.
"""
for idx, (ref_onto, gen_onto) in enumerate(self.ontology_pairs):
scorer = OntoScorer(ref_onto, gen_onto, self.equivalent_prefix)
report_content = scorer.generate_report()
report_filename = os.path.join(self.output_dir, f'report_{idx + 1}.txt')
with open(report_filename, 'w') as f:
f.write(report_content)
def generate_summary_report(self):
"""
Generates a summary report for all the ontologies and writes it to the output directory.
"""
summary_content = "Summary Report for All Ontologies\n"
summary_content += "="*80 + "\n"
for idx, ((ref_onto, gen_onto), metrics) in enumerate(self.results.items()): # Adjusted loop to access metrics from dictionary
summary_content += f"Metrics for Ontology Pair {idx + 1}:\n"
report = Report(ref_onto, gen_onto, metrics)
summary_content += report.generate() + "\n"
summary_content += "-"*80 + "\n"
summary_filename = os.path.join(self.output_dir, 'summary_report.txt')
with open(summary_filename, 'w') as f:
f.write(summary_content)