On the examples, you need a reference alignment file for evaluation. However this is just for using OntoAligner:
!pip install ontoaligner
and since it does not support Turtle, make it xml:
from rdflib import Graph
def rdf_to_xml(input_file, output_file):
g = Graph()
g.parse(input_file)
g.serialize(destination=output_file, format="xml")
rdf_to_xml('O1.ttl', 'O1.xml')
rdf_to_xml('O2.ttl', 'O2.xml')
here is the alignment:
from ontoaligner.ontology import GenericOMDataset
from ontoaligner.encoder import ConceptParentLightweightEncoder
from ontoaligner.aligner import SimpleFuzzySMLightweight
from ontoaligner import AlignerPipeline
from ontoaligner.utils import xmlify # for exporting results, optional
task = GenericOMDataset()
# task.track = "MyDomain" # optional, just a label
# task.ontology_name = "OntoA-OntoB" # optional, just a label
# 2. Collect — note: NO reference_matching_path passed at all
dataset = task.collect(
source_ontology_path="/content/Logs4batch_id 1.xml",
target_ontology_path="/content/Logs4batch_id 2.xml",
)
# 3. Encode + align (lightweight fuzzy matching, no LLM/GPU needed)
aligner_pipeline = AlignerPipeline(
encoder=ConceptParentLightweightEncoder(),
aligner=SimpleFuzzySMLightweight(fuzzy_sm_threshold=0.9),
om_dataset=dataset,
)
matchings = aligner_pipeline.generate()
# 4. No evaluation call since there's no reference — just inspect/save matchings
rows = [
(
row["source"].split("/")[-1],
row["target"].split("/")[-1],
f"{row['score']:.3f}",
)
for row in sorted(matchings, key=lambda r: r["score"], reverse=True)
]
src_width = max(len(r[0]) for r in rows)
tgt_width = max(len(r[1]) for r in rows)
print(f'{"Source":<{src_width}} {"Target":<{tgt_width}} Score')
print(f'{"-" * src_width} {"-" * tgt_width} -----')
for source, target, score in rows:
print(f"{source:<{src_width}} {target:<{tgt_width}} {score:>5}")
On the examples, you need a reference alignment file for evaluation. However this is just for using OntoAligner:
!pip install ontoalignerand since it does not support Turtle, make it xml:
here is the alignment: