Ontology Validator
Goal
Validate that material sample annotations comply with ontology constraints: correct class names, valid properties, consistent domain/range relationships, and required fields present.
Requirements
- Python 3.8+
- No external dependencies (Python standard library only)
- Requires ontology-explorer's
cmso_summary.json and ontology_registry.json
Inputs to Gather
| Input |
Description |
Example |
| Annotation |
JSON dict or list of annotation dicts |
{"class":"UnitCell","properties":{"has Bravais lattice":"cF"}} |
| Class name |
Class to check completeness for |
Crystal Structure |
| Provided properties |
Comma-separated property names |
"has unit cell,has space group" |
| Relationships |
JSON array of subject-property-object triples |
[{"subject_class":"Material","property":"has structure","object_class":"Crystal Structure"}] |
Decision Guidance
What do you need to validate?
├── An annotation (classes and properties are correct)
│ └── schema_checker.py --ontology cmso --annotation '<json>'
├── Completeness of a class annotation
│ └── completeness_checker.py --ontology cmso --class <name> --provided <props>
└── Object property relationships
└── relationship_checker.py --ontology cmso --relationships '<json>'
Script Outputs (JSON Fields)
| Script |
Key Outputs |
scripts/schema_checker.py |
results.valid, results.errors, results.warnings, results.class_valid, results.properties_valid |
scripts/completeness_checker.py |
results.completeness_score, results.required_missing, results.recommended_missing, results.optional_missing, results.unrecognized |
scripts/relationship_checker.py |
results.valid, results.results, results.errors |
Workflow
- After mapping a sample with ontology-mapper, pass the annotations to
schema_checker.py to verify correctness.
- For a specific class, use
completeness_checker.py to see what required/recommended properties are missing.
- When building relationships between instances, use
relationship_checker.py to ensure domain/range consistency.
Conversational Workflow Example
User: I annotated my sample as CrystalStructure with properties hasUnitCell and hasBasis.
Is this correct and complete?
Agent: Let me validate your annotation and check completeness.
[Runs: completeness_checker.py --ontology cmso --class "Crystal Structure" --provided "has unit cell,has basis" --json]
Your annotation is partially complete:
- has unit cell: provided (required)
- has basis: not a direct property of Crystal Structure (it belongs to Unit Cell)
- **Missing required**: has space group
The "has basis" property belongs to the Unit Cell class, not Crystal Structure.
You should add "has space group" to Crystal Structure and move "has basis"
to the Unit Cell annotation.
CLI Examples
# Validate an annotation
python3 skills/ontology/ontology-validator/scripts/schema_checker.py \
--ontology cmso \
--annotation '{"class":"Unit Cell","properties":{"has Bravais lattice":"cF"}}' \
--json
# Check completeness
python3 skills/ontology/ontology-validator/scripts/completeness_checker.py \
--ontology cmso \
--class "Crystal Structure" \
--provided "has unit cell,has space group" \
--json
# Validate relationships
python3 skills/ontology/ontology-validator/scripts/relationship_checker.py \
--ontology cmso \
--relationships '[{"subject_class":"Computational Sample","property":"has material","object_class":"Material"}]' \
--json
Error Handling
| Error |
Cause |
Resolution |
Class 'X' not found |
Invalid class name |
Use ontology-explorer to find correct name |
Property 'X' not found |
Invalid property name |
Use property_lookup.py to search |
Annotation must be a dict |
Wrong input format |
Provide valid JSON dict |
Relationships must be a non-empty list |
Wrong input format |
Provide JSON array of relationship dicts |
Interpretation Guidance
- Errors indicate definite problems (unknown class/property, range mismatch)
- Warnings indicate potential issues (domain mismatch — may be intentional for subclasses)
- Completeness score: 0.0-1.0 ratio of provided vs. total tracked properties
- required_missing: must fix for valid annotation
- recommended_missing: should fix for quality
- unrecognized: may indicate typos or properties from a different ontology
Limitations
- Constraints file is manually curated, not derived from OWL axioms
- Does not validate data types (e.g., whether a value is actually a float vs string)
- Does not validate cardinality (e.g., exactly one space group per structure)
- Subclass checking uses simple parent traversal, not full OWL reasoning
References
- Validation Rules — what is validated and why
- CMSO Constraints — required/recommended properties per class
- CMSO Guide — CMSO ontology overview
Version History
| Date |
Version |
Changes |
| 2026-02-25 |
1.0 |
Initial release with CMSO validation support |
1---2name: ontology-validator3description: Validate material sample annotations and data structures against ontology constraints. Use when checking if CMSO annotations are correct, verifying that required properties are present, or validating that object property relationships have consistent domain and range. Catches unknown classes, unknown properties, domain mismatches, and missing required fields.4---5
6# Ontology Validator
7
8## Goal
9
10Validate that material sample annotations comply with ontology constraints: correct class names, valid properties, consistent domain/range relationships, and required fields present.
11
12## Requirements
13
14- Python 3.8+
15- No external dependencies (Python standard library only)
16- Requires ontology-explorer's `cmso_summary.json` and `ontology_registry.json`
17
18## Inputs to Gather
19
20| Input | Description | Example |
21|-------|-------------|---------|
22| Annotation | JSON dict or list of annotation dicts | `{"class":"UnitCell","properties":{"has Bravais lattice":"cF"}}` |
23| Class name | Class to check completeness for | `Crystal Structure` |
24| Provided properties | Comma-separated property names | `"has unit cell,has space group"` |
25| Relationships | JSON array of subject-property-object triples | `[{"subject_class":"Material","property":"has structure","object_class":"Crystal Structure"}]` |
26
27## Decision Guidance
28
29```
30What do you need to validate?
31├── An annotation (classes and properties are correct)
32│ └── schema_checker.py --ontology cmso --annotation '<json>'
33├── Completeness of a class annotation
34│ └── completeness_checker.py --ontology cmso --class <name> --provided <props>
35└── Object property relationships
36 └── relationship_checker.py --ontology cmso --relationships '<json>'
37```
38
39## Script Outputs (JSON Fields)
40
41| Script | Key Outputs |
42|--------|-------------|
43| `scripts/schema_checker.py` | `results.valid`, `results.errors`, `results.warnings`, `results.class_valid`, `results.properties_valid` |
44| `scripts/completeness_checker.py` | `results.completeness_score`, `results.required_missing`, `results.recommended_missing`, `results.optional_missing`, `results.unrecognized` |
45| `scripts/relationship_checker.py` | `results.valid`, `results.results`, `results.errors` |
46
47## Workflow
48
491. After mapping a sample with ontology-mapper, pass the annotations to `schema_checker.py` to verify correctness.
502. For a specific class, use `completeness_checker.py` to see what required/recommended properties are missing.
513. When building relationships between instances, use `relationship_checker.py` to ensure domain/range consistency.
52
53## Conversational Workflow Example
54
55```
56User: I annotated my sample as CrystalStructure with properties hasUnitCell and hasBasis.
57 Is this correct and complete?
58
59Agent: Let me validate your annotation and check completeness.
60
61[Runs: completeness_checker.py --ontology cmso --class "Crystal Structure" --provided "has unit cell,has basis" --json]
62
63Your annotation is partially complete:
64- has unit cell: provided (required)
65- has basis: not a direct property of Crystal Structure (it belongs to Unit Cell)
66- **Missing required**: has space group
67
68The "has basis" property belongs to the Unit Cell class, not Crystal Structure.
69You should add "has space group" to Crystal Structure and move "has basis"
70to the Unit Cell annotation.
71```
72
73## CLI Examples
74
75```bash
76# Validate an annotation
77python3 skills/ontology/ontology-validator/scripts/schema_checker.py \
78 --ontology cmso \
79 --annotation '{"class":"Unit Cell","properties":{"has Bravais lattice":"cF"}}' \
80 --json
81
82# Check completeness
83python3 skills/ontology/ontology-validator/scripts/completeness_checker.py \
84 --ontology cmso \
85 --class "Crystal Structure" \
86 --provided "has unit cell,has space group" \
87 --json
88
89# Validate relationships
90python3 skills/ontology/ontology-validator/scripts/relationship_checker.py \
91 --ontology cmso \
92 --relationships '[{"subject_class":"Computational Sample","property":"has material","object_class":"Material"}]' \
93 --json
94```
95
96## Error Handling
97
98| Error | Cause | Resolution |
99|-------|-------|------------|
100| `Class 'X' not found` | Invalid class name | Use ontology-explorer to find correct name |
101| `Property 'X' not found` | Invalid property name | Use property_lookup.py to search |
102| `Annotation must be a dict` | Wrong input format | Provide valid JSON dict |
103| `Relationships must be a non-empty list` | Wrong input format | Provide JSON array of relationship dicts |
104
105## Interpretation Guidance
106
107- **Errors** indicate definite problems (unknown class/property, range mismatch)
108- **Warnings** indicate potential issues (domain mismatch — may be intentional for subclasses)
109- **Completeness score**: 0.0-1.0 ratio of provided vs. total tracked properties
110- **required_missing**: must fix for valid annotation
111- **recommended_missing**: should fix for quality
112- **unrecognized**: may indicate typos or properties from a different ontology
113
114## Limitations
115
116- Constraints file is manually curated, not derived from OWL axioms
117- Does not validate data types (e.g., whether a value is actually a float vs string)
118- Does not validate cardinality (e.g., exactly one space group per structure)
119- Subclass checking uses simple parent traversal, not full OWL reasoning
120
121## References
122
123- [Validation Rules](references/validation_rules.md) — what is validated and why
124- [CMSO Constraints](references/cmso_constraints.json) — required/recommended properties per class
125- [CMSO Guide](../ontology-explorer/references/cmso_guide.md) — CMSO ontology overview
126
127## Version History
128
129| Date | Version | Changes |
130|------|---------|---------|
131| 2026-02-25 | 1.0 | Initial release with CMSO validation support |