A Python tool for analyzing conflicts across multiple ontology files before merging them. This script helps identify critical conflicts that would break ontology merging and semantic issues that need attention.
The conflict detector analyzes ontologies across three priority levels:
- URI Collisions: Same URIs with different definitions across files
- Property Type Conflicts: Properties defined as both ObjectProperty and DatatypeProperty
- Semantic Duplicates: Different URIs representing the same concepts
- Inverse Property Candidates: Properties that might be inverses of each other
- Equivalent Class Candidates: Classes that might be equivalent but not declared as such
- Unlabeled Classes: Classes without rdfs:label
- Underspecified Properties: Properties without domain or range
pip install rdflibAnalyze a single ontology file:
python "onto_conflict_detect.py" path/to/ontology.ttlAnalyze multiple ontology files:
python "onto_conflict_detect.py" file1.ttl file2.ttl file3.ttlpython "onto_conflict_detect.py" [files] [options]
Options:
-o, --output-dir DIR Output directory for log files (default: logs)
-l, --log-name NAME Custom log file name (default: auto-generated)
-a, --agnostic Enable namespace-agnostic mode (compare by local names)
-h, --help Show help messageThe --agnostic (or -a) flag enables namespace-agnostic comparison mode. In this mode, the detector groups ontology elements by their local names (the part after # or the last / in the URI) rather than comparing full URIs.
When to use:
- Comparing ontologies from different organizations with different namespaces
- Finding potential semantic duplicates across namespace boundaries
- Harmonizing terminology before formally merging ontologies
- Detecting unintentional naming conflicts in distributed development
Example:
# Compare by local names across namespaces
python "onto_conflict_detect.py" file1.ttl file2.ttl --agnostic
# Normal mode: compare exact URIs (default)
python "onto_conflict_detect.py" file1.ttl file2.ttlIn agnostic mode, URIs like http://example.org#Vehicle and http://different.org#Vehicle will be grouped together and compared, even though they have different namespaces. The output will show:
- NAMESPACE-AGNOSTIC URI GROUPS: URIs with the same local name
- MERGE-BREAKING conflicts: Structural incompatibilities (types, domains, ranges)
- SEMANTIC CANDIDATES: Label or comment differences
See examples/agnostic_example.md for a detailed walkthrough.
# Analyze multiple ontologies with custom output directory
python "onto_conflict_detect.py" *.ttl -o analysis_results
# Analyze with custom log name
python "onto_conflict_detect.py" ontology1.ttl ontology2.ttl -l custom_conflicts.log
# Analyze all TTL files in current directory
python "onto_conflict_detect.py" *.ttl- Turtle (.ttl)
- OWL (.owl)
- RDF/XML (.rdf)
- N3 (.n3)
The script creates a detailed log file with:
- Console output (real-time analysis)
- Complete log file with timestamps
- Structured conflict reports by priority
- Summary statistics
By default, log files are saved to the logs/ directory with timestamps:
- Single file:
conflict_analysis_[filename]_[timestamp].log - Multiple files:
conflict_analysis_multi_[timestamp].log
These MUST be resolved before merging:
β οΈ URI TYPE CONFLICT: http://data.europa.eu/949/name
Different types across files: Class, DatatypeProperty
- file1.ttl: Class
- file2.ttl: DatatypeProperty
Action Required: Decide whether this should be a Class or DatatypeProperty and update accordingly.
These SHOULD be reviewed for data quality:
π Potential semantic duplicates for 'station':
- http://data.europa.eu/949/Station (from: file1.ttl)
- http://data.europa.eu/949/TrainStation (from: file2.ttl)
Action Suggested: Consider using owl:equivalentClass or owl:sameAs to link these concepts.
These are NICE TO FIX for better ontology quality:
Found 25 classes without labels:
- http://data.europa.eu/949/SomeClass (from: file1.ttl)
Action Suggested: Add rdfs:label properties for better usability.
- Files >100MB will show a warning and may take longer to process
- Consider splitting very large ontologies if possible
- The script loads all files into memory simultaneously
- Each ontology is loaded completely into memory
- For multiple large files, ensure sufficient RAM is available
- Monitor memory usage with large datasets
"File not found" errors:
Warning: File not found: nonexistent.ttl- Check file paths are correct
- Ensure files exist and are readable
"Error parsing" messages:
Error parsing file.ttl: Invalid syntax at line 123- Verify the ontology file syntax is valid
- Try opening the file in an RDF editor to check for errors
Large number of inverse property candidates:
- This might indicate overly broad pattern matching
- Focus on the first 25 results shown in the output
- Many false positives are normal and can be ignored
If you encounter memory errors with large files:
- Process files individually instead of all at once
- Increase available system memory
- Consider using smaller subsets for initial analysis
- β Run conflict detector on all files to be merged
- β Resolve all Priority 1 (Critical) conflicts
- β Review Priority 2 (Semantic) conflicts
- β Consider fixing Priority 3 (Quality) issues
- β Re-run analysis to confirm fixes
Consider running this script as part of your ontology development pipeline to catch conflicts early.
To extend the conflict detector:
- Add new conflict detection methods to the
OntologyConflictDetectorclass - Follow the priority system (1=Critical, 2=Semantic, 3=Quality)
- Include source file information in all conflict reports
- Add appropriate emoji indicators for visual clarity
To verify the agnostic mode functionality:
cd tests
python test_agnostic_mode.pyThis smoke test verifies that:
- The
--agnosticflag is properly recognized - Agnostic mode banner appears in output
- Namespace-agnostic grouping occurs correctly
- Default mode continues to work without the flag
The tests/ directory contains example ontology files:
example1.ttl: Sample ontology with namespacehttp://example.org/ontology1#example2.ttl: Sample ontology with namespacehttp://different.org/vocab#
Both files define similar concepts (Vehicle, Car, hasOwner) with the same local names but different namespaces and labels, making them ideal for demonstrating agnostic mode.
- v3: Added namespace-agnostic comparison mode with
--agnosticflag - v2: Added priority-based conflict categorization, improved inverse property detection, enhanced logging
- v1: Initial version with basic conflict detection