Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/lint-yaml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ jobs:
with:
ruby-version: '3.3'
bundler-cache: true
working-directory: ./scripts

- name: Check YAML normalization
id: check_yaml
working-directory: ./scripts
run: |
bundle exec unitsdb-utils normalize --all --dir ..

- name: Check field uniqueness
id: check_uniqueness
working-directory: ./scripts
run: |
bundle exec unitsdb-utils check_uniqueness --all --dir ..

Expand Down
1 change: 1 addition & 0 deletions dimensions.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=schemas/dimensions-schema.yaml
---
schema_version: 2.0.0
dimensions:
Expand Down
1 change: 1 addition & 0 deletions prefixes.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=schemas/prefixes-schema.yaml
---
schema_version: 2.0.0
prefixes:
Expand Down
1 change: 1 addition & 0 deletions quantities.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=schemas/quantities-schema.yaml
---
schema_version: 2.0.0
quantities:
Expand Down
1 change: 1 addition & 0 deletions scales.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=schemas/scales-schema.yaml
---
schema_version: 2.0.0
scales:
Expand Down
159 changes: 159 additions & 0 deletions schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# UnitsDB YAML Schemas

This directory contains JSON Schema definitions for all YAML files in the UnitsDB repository. These schemas provide validation, documentation, and IDE support for the structured data files.

## Schema Files

### Core Data Schemas

- **`units-schema.yaml`** - Schema for `units.yaml`
- Defines physical units with their symbols, definitions, and relationships
- Includes conversion factors, dimension references, and unit systems

- **`quantities-schema.yaml`** - Schema for `quantities.yaml`
- Defines physical quantities with their dimensional analysis
- Links quantities to their fundamental dimensions

- **`dimensions-schema.yaml`** - Schema for `dimensions.yaml`
- Defines fundamental physical dimensions (length, mass, time, etc.)
- Includes dimensional components and mathematical symbols

- **`prefixes-schema.yaml`** - Schema for `prefixes.yaml`
- Defines unit prefixes (kilo, mega, micro, etc.)
- Includes base/power notation and symbol representations

- **`scales-schema.yaml`** - Schema for `scales.yaml`
- Defines measurement scales and their properties
- Includes scale types and conversion relationships

- **`unit_systems-schema.yaml`** - Schema for `unit_systems.yaml`
- Defines coherent systems of units (SI, CGS, etc.)
- Includes base units and derived unit relationships

## Features

### Validation
All schemas provide comprehensive validation for:
- Required fields and data types
- Enumerated values for controlled vocabularies
- Pattern matching for identifiers and codes
- Cross-references between related entities

### Documentation
Each schema includes:
- Detailed descriptions for all fields
- Examples of valid values
- Explanations of relationships between entities

### IDE Support
The schemas enable:
- Auto-completion in YAML editors
- Real-time validation feedback
- Hover documentation for fields
- Error highlighting and suggestions

## Usage

### In VSCode
The YAML files automatically reference their schemas via the `yaml-language-server` directive at the top of each file:

```yaml
# yaml-language-server: $schema=schemas/units-schema.yaml
```

### Programmatic Validation
Use the provided validation script:

```bash
ruby validate_schemas.rb
```

### Manual Validation
You can validate individual files using any JSON Schema validator that supports YAML, such as:
- `ajv-cli`
- `jsonschema` (Python)
- Online validators like jsonschemavalidator.net

## Schema Structure

All schemas follow a consistent structure:

```yaml
$schema: "http://json-schema.org/draft-06/schema#"
$id: "https://unitsml.org/schemas/[schema-name].yaml"
title: "[Human Readable Title]"
description: "[Detailed description]"

type: object
required: ["schema_version", "[main_array]"]
properties:
schema_version:
type: string
pattern: "^\\d+\\.\\d+\\.\\d+$"
[main_array]:
type: array
items:
$ref: "#/definitions/[MainType]"

definitions:
# Type definitions...
```

## Common Definitions

### Identifier
All entities use a consistent identifier structure:
```yaml
type: object
required: ["type", "id"]
properties:
type:
type: string
enum: ["nist", "unitsml", "si-digital-framework", ...]
id:
type: string
```

### Name
Multilingual names follow this pattern:
```yaml
type: object
required: ["value", "lang"]
properties:
value:
type: string
lang:
type: string
pattern: "^[a-z]{2}(-[A-Z]{2})?$"
```

### Symbol
Mathematical symbols are represented as:
```yaml
type: object
required: ["latex", "unicode", "ascii", "html", "id", "mathml"]
properties:
latex: { type: string }
unicode: { type: string }
ascii: { type: string }
html: { type: string }
id: { type: string }
mathml: { type: string }
```

## Validation Results

✅ All schemas successfully validate their corresponding YAML files
✅ Cross-references and relationships are properly defined
✅ Enumerated values match actual data usage
✅ Required fields are correctly identified

## Maintenance

When updating the YAML data files:
1. Ensure changes conform to the existing schemas
2. Update schemas if new fields or structures are added
3. Run validation to verify compatibility
4. Update this documentation if schema structure changes

For questions or issues with the schemas, please refer to the main repository documentation or open an issue.
157 changes: 157 additions & 0 deletions schemas/dimensions-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# yaml-language-server: $schema=http://json-schema.org/draft-06/schema
---
$schema: "http://json-schema.org/draft-06/schema#"
$id: "https://unitsml.org/schemas/dimensions-schema.yaml"
title: "Dimensions Database Schema"
description: "Schema for dimensions.yaml - defines fundamental physical dimensions"

type: object
required: ["schema_version", "dimensions"]
properties:
schema_version:
type: string
pattern: "^\\d+\\.\\d+\\.\\d+$"
description: "Semantic version of the schema"
dimensions:
type: array
description: "Array of dimension definitions"
items:
$ref: "#/definitions/Dimension"

definitions:
Dimension:
type: object
required: ["identifiers", "names", "short"]
properties:
identifiers:
type: array
description: "External identifiers for this dimension"
items:
$ref: "#/definitions/Identifier"
names:
type: array
description: "Multilingual names for this dimension"
items:
$ref: "#/definitions/Name"
short:
type: string
description: "Short identifier for the dimension"
dimensionless:
type: boolean
description: "Whether this is a dimensionless quantity"
length:
$ref: "#/definitions/DimensionComponent"
description: "Length dimension component"
mass:
$ref: "#/definitions/DimensionComponent"
description: "Mass dimension component"
time:
$ref: "#/definitions/DimensionComponent"
description: "Time dimension component"
electric_current:
$ref: "#/definitions/DimensionComponent"
description: "Electric current dimension component"
thermodynamic_temperature:
$ref: "#/definitions/DimensionComponent"
description: "Thermodynamic temperature dimension component"
amount_of_substance:
$ref: "#/definitions/DimensionComponent"
description: "Amount of substance dimension component"
luminous_intensity:
$ref: "#/definitions/DimensionComponent"
description: "Luminous intensity dimension component"
plane_angle:
$ref: "#/definitions/DimensionComponent"
description: "Plane angle dimension component"
references:
type: array
description: "External references and citations"
items:
$ref: "#/definitions/Reference"

Identifier:
type: object
required: ["type", "id"]
properties:
type:
type: string
enum: ["nist", "unitsml", "si-digital-framework"]
description: "Type of identifier system"
id:
type: string
description: "Identifier value within the system"

Name:
type: object
required: ["value", "lang"]
properties:
value:
type: string
description: "Name in the specified language"
lang:
type: string
pattern: "^[a-z]{2}(-[A-Z]{2})?$"
description: "Language code (ISO 639-1, optionally with ISO 3166-1 country)"

Symbol:
type: object
required: ["latex", "unicode", "ascii", "html", "id", "mathml"]
properties:
latex:
type: string
description: "LaTeX representation"
unicode:
type: string
description: "Unicode representation"
ascii:
type: string
description: "ASCII representation"
html:
type: string
description: "HTML representation"
id:
type: string
description: "Identifier for the symbol"
mathml:
type: string
description: "MathML representation"

DimensionComponent:
type: object
required: ["power", "symbol"]
properties:
power:
type: integer
description: "Exponent for this dimension component"
symbol:
type: string
description: "Symbol representing this dimension"
symbols:
type: array
description: "Mathematical and textual representations"
items:
$ref: "#/definitions/Symbol"

Reference:
type: object
required: ["type"]
properties:
type:
type: string
enum: ["standard", "specification", "publication", "website"]
description: "Type of reference"
authority:
type: string
description: "Authoritative body or organization"
uri:
type: string
format: "uri"
description: "URI to the reference"
title:
type: string
description: "Title of the reference"
year:
type: integer
minimum: 1000
maximum: 9999
description: "Publication year"
Loading
Loading