An advanced ontology alignment system that leverages semantic embeddings and multiple similarity metrics to automatically discover mappings between entities across different ontologies.
The Ontology Alignment System is a Python-based tool designed to find and establish alignments between ontologies from diverse domains. It combines:
- OWL and RDF Parsing: Support for multiple ontology formats
- Semantic Embeddings: OWL2Vec-Star embeddings for deep semantic understanding
- Multi-metric Similarity: Lexical and embedding, cosine-based similarity computation
- Alignment Mapping: Automated generation of alignment correspondences
- Evaluation Framework: Precision, recall, and F-score metrics for validation
Comprehensive Entity Extraction
- Classes/Concepts
- Object Properties
- Data Properties
- Individuals/Instances
Advanced Similarity Measures
- Lexical Similarity (Levenshtein distance)
- Cosine Similarity (from semantic embeddings)
- Structural similarity checking ancestors
Scalability
- Block-based entity matching for efficiency
- Multi-processing to paralalise the similarity computation across available CPU cores
Semantic Embeddings
- OWL2Vec-Star model for ontology embedding
- Gensim-based word2vec models
- Multiple output formats (Gensim binary & text)
Alignment Evaluation
- Compare system output with reference alignments
- Precision, Recall, and F-Score metrics
- Support for bidirectional mappings
Used Predicates
- owl:equivalentClass (class mappings)
- rdfs:subClassOf (class mappings)
- owl:equivalentProperty (property mappings)
- rdfs:subPropertyOf (property mappings)
- owl:sameAs (instance mappings)
- Python 3.8+ ( used version Python 3.9.6)
- Dependencies (see
requirements.txt):
cd /path/to/ontology-alignment-systempython3 -m venv ven4
source ven4/bin/activate # On Windows: ven4\Scripts\activatepip install -r requirements.txtpython main.py <ontology1_path> <ontology2_path>Example:
python main.py ontology/human.owl ontology/mouse.owlpython main.py ontology/cmt.owl ontology/confOf.owlWhat Happens:
- Parses both ontologies from specified files
- Extracts entities (classes, properties, individuals)
- Merges ontologies to create a merget.owl file to create the embedding from
- Generates semantic embeddings using OWL2Vec-Star
- Computes lexical and cosine similarities
- Compares it against the tresholds
- If the similarity passes the treshold
- Checks the ancestors
- Produces alignment mappings
- Saves embeddings and alignment output
- Evaluates the output with OAEI output
- Returns result to terminal
Output:
Comparing 'alignmentOutputs/oas-cmt-confOf.ttl' with 'alignmentOutputs/reference.ttl'
Precision: 0.8234
Recall: 0.7891
F-Score: 0.8060
Using the file from tutorial
convert_ttl_to_embedding(owl1, owl2): Generates embeddings for ontology pairloadEmbedding(embedding_file): Loads pre-computed embeddings- Uses OWL2Vec-Star with Gensim word2vec models
getLexicalSimilarity(entity1, entity2): I-Sub string similaritygetCosineSimilarity(entity1, entity2, embedding): Embedding-based similaritycheckSimilarity(): Combined similarity with blocking strategy- Block-based matching optimizes performance
getOntology(graph): Extracts classes, properties, individualsgetOntoClass(graph): Retrieves class entities with labels and ancestorsgetOntoProperty(data, graph): Processes property information- Coordinates the main pipeline
Using the file from tutorial
- Compares system-generated alignments against reference alignments
- Computes:
- Precision: TP / (TP + FP)
- Recall: TP / (TP + FN)
- F-Score: 2 × (Precision × Recall) / (Precision + Recall)
- Handles bidirectional mappings
ontology-alignment-system/
├── embeddingOutputs/
│── ontology/
├── subtask_oa2/
└── subtask_oa4/
- embeddingOutputs = Stores created embedding outputs with oas-ontology.{onto1}-{onto2}.ontology structure
- ontology = Store all ontology files
- subtask_oa2 = Store the result of subtask_oa2
- subtask_oa4 = Store the created alignments for subtask_oa4
- Lexical Alignment
- Structural Alignment
- Embeddings (Cosine)
- Entities blocked by first 1 characters of name
- Reduces unnecessary similarity computations
- Significant speedup for large ontologies
- Parallel similarity computation across available CPU cores
- Efficient utilization of multi-core systems while comparing pairs
The result is stored in subtask_oa2 folder. Alignment system successfully detected subClass, equivalentClass, equivalentProperty relationships. The processing time is 8.6 seconds. There were no instances used in both ontologies, so the keyword sameAs didn't appear in the result and also there were no subproperties. Alignment system overall is successful. However, can be argued that it is a bit strict for matching. The struggle was low (cosine * 0.5 + lexical * 0.5) formula treshold improved the semantic matching in some ontologies like this one and human-mouse one, but it also lowered the F1 score in other ontologies like omim-ordo. So I decided to keep the treshold hide. It was hard to balance it. Due to this imbalance some sematic matching like (hasAgeRating owl:equivalentProperty hasRequiredAge) triple did not appeared in the alignment file.(System behaves inconsistently across different ontology pairs) Can it be related to their difference in structure?
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX lochlann: <http://www.city.ac.uk/inm713-in3067/2026/lochlann/>
PREFIX ece: <http://www.city.ac.uk/inm713-in3067/2026/ece/>
SELECT DISTINCT (?x AS ?class) WHERE {
?c rdf:type owl:Class .
?c owl:equivalentClass ece:Genre .
?x rdfs:subClassOf ?c .
?x owl:equivalentClass lochlann:Sport
} ORDER BY ?x| Result |
|---|
| ece:SportGenre |
| lochlann:Sport |
The query was to find the classes that are equivalent to Sport from lochlann prefix and that is also subclass of the class that is equivalent to Genre class with ece prefix distinct and ordered. The return result was ece:SportGenre and lochlann:Sport as expected.
| Type | Name | Precision | Recall | F-score | Computation times |
|---|---|---|---|---|---|
| ANOTOMY | human-mouse | 0.7 | 0.2 | 0.4 | 1 min 12 sec |
| CIRCULAR-ECONOMY | CEON-BiOnto | 0.7 | 0.6 | 0.6 | 37 sec |
| CIRCULAR-ECONOMY | CEON-MATONTO | 0.3 | 0.7 | 0.4 | 26 sec |
| CONFERENCE | cmt-conference | 0.6 | 0.2 | 0.3 | 10 sec |
| CONFERENCE | cmt-confOf | 0.6 | 0.2 | 0.3 | 8 sec |
| CONFERENCE | cmt-edas | 1.0 | 0.6 | 0.7 | 9 sec |
| CONFERENCE | cmt-ekaw | 0.8 | 0.4 | 0.5 | 13 sec |
| CONFERENCE | cmt-iasted | 0.8 | 1.0 | 0.8 | 15 sec |
| CONFERENCE | cmt-sigkdd | 1 | 0.5 | 0.6 | 12 sec |
| CONFERENCE | conference-confOf | 0.8 | 0.4 | 0.6 | 12 sec |
| CONFERENCE | conference-edas | 0.8 | 0.4 | 0.5 | 13 sec |
| CONFERENCE | conference-ekaw | 0.7 | 0.2 | 0.3 | 13 sec |
| CONFERENCE | conference-iasted | 0.6 | 0.2 | 0.4 | 15 sec |
| CONFERENCE | conference-sigkdd | 0.8 | 0.3 | 0.4 | 12 sec |
| CONFERENCE | confOf-edas | 0.7 | 0.4 | 0.5 | 11 sec |
| CONFERENCE | confOf-ekaw | 0.7 | 0.3 | 0.4 | 10 sec |
| CONFERENCE | confOf-iasted | 1.0 | 0.4 | 0.6 | 12 sec |
| CONFERENCE | confOf-sigkdd | 1.0 | 0.5 | 0.7 | 9 sec |
| CONFERENCE | edas-ekaw | 0.7 | 0.2 | 0.3 | 12 sec |
| CONFERENCE | edas-iasted | 0.8 | 0.2 | 0.3 | 14 sec |
| CONFERENCE | edas-sigkdd | 1.0 | 0.4 | 0.6 | 11 sec |
| CONFERENCE | ekaw-iasted | 0.8 | 0.2 | 0.3 | 14 sec |
| CONFERENCE | ekaw-sigkdd | 1.0 | 0.6 | 0.7 | 10 sec |
| CONFERENCE | iasted-sigkdd | 0.7 | 0.7 | 0.7 | 12 sec |
| DIGITAL-HUMANITIES | defc-pactols | 1.0 | 0.6 | 0.7 | 6 sec |
| DIGITAL-HUMANITIES | dha-unesco -- | AttributeError: 'OntologyAccess' object has no attribute 'graph' | |||
| DIGITAL-HUMANITIES | idai-pactols | 0 | 0 | 0 | 5 sec |
| DIGITAL-HUMANITIES | idai-parthenos | 1.0 | 0.1 | 0.2 | 6 sec |
| DIGITAL-HUMANITIES | ironagedanube-pactols | 0.8 | 0.8 | 0.8 | 6 sec |
| DIGITAL-HUMANITIES | oeai-parthenos | 0.1 | 0.4 | 0.5 | 6 sec |
| DIGITAL-HUMANITIES | pactols-parthenos | 0 | 0 | 0 | 5 sec |
| DIGITAL-HUMANITIES | tadirah-unesco | 1.0 | 0.2 | 0.4 | 9 sec |
| BIO-ML | ncit-doid | 0.4 | 0.0 | 0.0 | 15 min |
| BIO-ML | omim-ordo | 0.3 | 0.2 | 0.3 | 19 min |
| BIO-ML | snomed.neoplas-ncit.neoplas | 0.3 | 0.20 | 0.0 | 41 min |
| BIO-ML | snomed.body-fma.body | Took 2+ hours | |||
| BIO-ML | snomed.pharm-ncit.pharm | Took 2+ hours | |||
| KNOWLEDGE-GRAPH | marvelcinematicuniverse-marvel | Took 2+ hours | |||
| KNOWLEDGE-GRAPH | memoryalpha-memorybeta | Took 2+ hours | |||
| KNOWLEDGE-GRAPH | memoryalpha-stexpanded | Took 2+ hours | |||
| KNOWLEDGE-GRAPH | starwars-swg | 0 | 0 | 0 | 40 min |
| KNOWLEDGE-GRAPH | starwars-swtor | Took 2+ hours |
During the tests, observed behaviour was ontologies has different needs. While human-mouse ontology is performant with embedding and (cosine * 0.5 + lexical * 0.5), it is not as performant with lexical matching. On the other hand, confOf-sigkdd was more suitable with lexical search combination of lexical and cosine even lowered its score. Due to this reason I limited some ontologies to only use lexical similarity or combination of lexical and cosine.
Another observation was the Recall and Precision tradeoff. High Recall values lowered the precision vice versa. While F values didn't change.
Scalability implemented with block matching and multiprocessing. However, for the large knowledge graphs such as starwars-swtor and snomed.pharm-ncit.pharm the system couldn't finish before 2 hours. More scalability and even adopting a database solution to recieve the values only after ANN search then checking the similarity might be better idea??
Finding a fix treshold was also difficult. While lexical >= 1 work very well for some ontologies, some ontologies worked better with lexical >= 0.9. same with (cosine * 0.5 + lexical * 0.5) treshold, while 0.85<= was good for some ontologies, other ontologies needed more strict matching like 9.0<=
- OWL2Vec-Star: Extended OWL2Vec embeddings for ontology representation
- RDFlib: Python library for working with RDF/OWL
- Gensim: Python library for word and document embeddings
- I-Sub: Semantic string similarity metric
Copilot used to create the base READ.ME file of the project. I added the detailed information and additional sections myself. prompt: 'Create README.MD file for this project'
Chatgpt is used to create repo image. Prompt: 'create an image for otology alignment system that contains puzzle pieces, make it cool'
Claude used to learn how to get classes, properties and individuals from the SKOS type file such as pactols.rdf, I integrated it to system. prompt 'how to get classes, properties and individuals from SKOS ontology file'
Code created by Copilot used to speed up embedding creation in OWL2Vec. prompt 'how to speed up embedding creation for large files?'
Chatgpt is used to investigate different scalability techniques, prompt 'how to efficiently scale large alignments for an ontology alignment system'
- Is it wise to combine two ontologies to create merged embedding files?
- If I integrate Atlas Vector search for embedding creation and retrieval, would that make the system more production ready and stable?
Last Updated: May 2026
Version: 2.0