| Crates.io | oxirs-samm |
| lib.rs | oxirs-samm |
| version | 0.1.0 |
| created_at | 2025-10-12 10:12:59.47148+00 |
| updated_at | 2026-01-20 22:02:54.344793+00 |
| description | Semantic Aspect Meta Model (SAMM) implementation for OxiRS |
| homepage | https://github.com/cool-japan/oxirs |
| repository | https://github.com/cool-japan/oxirs |
| max_upload_size | |
| id | 1879133 |
| size | 1,669,516 |
Status: ✅ Production Release (v0.1.0) - Production Ready ✅ APIs stable. Ready for production use with backward compatibility guarantees.
OxiRS SAMM is a Rust implementation of the Semantic Aspect Meta Model (SAMM), which enables the creation of semantic models to describe digital twins and their aspects.
SAMM was developed by the Eclipse Semantic Modeling Framework (ESMF) project and provides a standardized way to model domain-specific aspects of digital twins.
Add this to your Cargo.toml:
[dependencies]
oxirs-samm = "0.1.0"
use oxirs_samm::parser::parse_aspect_model;
use oxirs_samm::validator::validate_aspect;
use oxirs_samm::generators::generate_typescript;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Parse a SAMM model from a Turtle file
let aspect = parse_aspect_model("path/to/AspectModel.ttl").await?;
println!("Aspect: {}", aspect.name());
println!("Properties: {}", aspect.properties().len());
// Validate the model
let validation = validate_aspect(&aspect).await?;
if validation.is_valid {
println!("✓ Model is valid!");
}
// Generate TypeScript code
let ts_code = generate_typescript(&aspect, Default::default())?;
println!("{}", ts_code);
Ok(())
}
The crate includes 7 comprehensive examples demonstrating real-world workflows:
model_query - Model introspection, dependency analysis, and complexity metrics
cargo run --example model_query
model_transformation - Refactoring models (rename, namespace changes, optional/required)
cargo run --example model_transformation
model_comparison - Version comparison with diff reports and breaking change detection
cargo run --example model_comparison
code_generation_pipeline - Multi-language code generation (TypeScript, Python, Java, GraphQL)
cargo run --example code_generation_pipeline
performance_optimization - Caching, parallel processing, and production metrics
cargo run --example performance_optimization
model_lifecycle - Complete CRUD operations and workflow patterns
cargo run --example model_lifecycle
dtdl_generation - Azure Digital Twins DTDL generation with deployment guide
cargo run --example dtdl_generation
Each example includes extensive documentation and demonstrates best practices for production use.
Bidirectional Conversion:
# SAMM → DTDL (Generate Azure models)
oxirs aspect to Movement.ttl dtdl -o azure/Movement.json
# DTDL → SAMM (Import Azure models)
oxirs aspect from azure/Movement.json -o samm/Movement.ttl
Features:
See DTDL_GUIDE.md and DTDL_COMPLETE_GUIDE.md for complete usage guide.
OxiRS SAMM implements all core SAMM metamodel elements:
Supports all SAMM characteristic types:
| Type | Description |
|---|---|
Trait |
Basic characteristic |
Quantifiable |
Characteristic with unit |
Measurement |
Quantifiable with specific value |
Enumeration |
Set of allowed values |
State |
Enumeration representing states |
Duration |
Time duration |
Collection |
Collection of values |
List |
Ordered collection |
Set |
Unordered unique collection |
SortedSet |
Sorted collection |
TimeSeries |
Time-indexed data |
Code |
String with encoding |
Either |
One of two alternatives |
SingleEntity |
Single entity instance |
StructuredValue |
Value with structure |
Supports all SAMM constraint types:
LanguageConstraint: Restrict to specific languageLocaleConstraint: Restrict to specific localeRangeConstraint: Value range limitsLengthConstraint: String/collection length limitsRegularExpressionConstraint: Pattern matchingEncodingConstraint: Character encodingFixedPointConstraint: Decimal precisionoxirs-samm/
├── src/
│ ├── lib.rs # Crate entry point
│ ├── error.rs # Error types
│ ├── metamodel/ # SAMM metamodel types
│ │ ├── aspect.rs
│ │ ├── property.rs
│ │ ├── characteristic.rs
│ │ ├── entity.rs
│ │ └── operation.rs
│ ├── parser/ # RDF/Turtle parser
│ │ ├── ttl_parser.rs
│ │ └── resolver.rs
│ └── validator/ # SHACL validation
│ └── shacl_validator.rs
└── tests/
└── fixtures/ # Example SAMM models
Powerful introspection and analysis:
use oxirs_samm::query::ModelQuery;
let query = ModelQuery::new(&aspect);
// Find optional properties
let optional = query.find_optional_properties();
// Analyze complexity
let metrics = query.complexity_metrics();
println!("Properties: {}", metrics.total_properties);
println!("Max nesting: {}", metrics.max_nesting_depth);
// Build dependency graph
let dependencies = query.build_dependency_graph();
// Detect circular dependencies
let cycles = query.detect_circular_dependencies();
Fluent API for model refactoring:
use oxirs_samm::transformation::ModelTransformation;
let mut aspect = create_aspect();
let mut transformation = ModelTransformation::new(&mut aspect);
transformation.rename_property("oldName", "newName");
transformation.change_namespace("old:namespace", "new:namespace");
transformation.make_property_optional("propertyName");
let result = transformation.apply();
println!("Applied {} transformations", result.transformations_applied);
Version comparison with diff generation:
use oxirs_samm::comparison::ModelComparison;
let v1 = parse_aspect_model("v1.ttl").await?;
let v2 = parse_aspect_model("v2.ttl").await?;
let comparison = ModelComparison::compare(&v1, &v2);
println!("Added properties: {}", comparison.properties_added.len());
println!("Breaking changes: {}", comparison.has_breaking_changes());
let report = comparison.generate_report();
use oxirs_samm::metamodel::{Aspect, Property, Characteristic, CharacteristicKind};
let mut aspect = Aspect::new("urn:samm:com.example:1.0.0#Movement".to_string());
aspect.metadata.add_preferred_name("en".to_string(), "Movement".to_string());
let property = Property::new("urn:samm:com.example:1.0.0#speed".to_string())
.with_characteristic(
Characteristic::new(
"urn:samm:com.example:1.0.0#SpeedCharacteristic".to_string(),
CharacteristicKind::Measurement {
unit: "unit:kilometrePerHour".to_string(),
},
)
);
aspect.add_property(property);
use oxirs_samm::parser::parse_aspect_from_string;
let ttl = r#"
@prefix : <urn:samm:com.example:1.0.0#> .
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.3.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.3.0#> .
:Movement a samm:Aspect ;
samm:preferredName "Movement"@en ;
samm:properties ( :speed ) .
:speed a samm:Property ;
samm:characteristic :SpeedCharacteristic .
:SpeedCharacteristic a samm-c:Measurement ;
samm:dataType xsd:float ;
samm-c:unit unit:kilometrePerHour .
"#;
let aspect = parse_aspect_from_string(ttl, "http://example.org").await?;
The oxirs aspect command suite provides tools for working with SAMM Aspect Models (Java ESMF SDK compatible):
# Validate a SAMM Aspect model
oxirs aspect validate AspectModel.ttl
oxirs aspect validate AspectModel.ttl --detailed
oxirs aspect validate AspectModel.ttl --format json
# Pretty-print a model
oxirs aspect prettyprint AspectModel.ttl
oxirs aspect prettyprint AspectModel.ttl -o formatted.ttl
# Generate Rust code
oxirs aspect AspectModel.ttl to rust
# Generate Markdown documentation
oxirs aspect AspectModel.ttl to markdown
# Generate JSON Schema
oxirs aspect AspectModel.ttl to jsonschema
# Generate OpenAPI 3.1 specification
oxirs aspect AspectModel.ttl to openapi
# Generate AsyncAPI 2.6 specification
oxirs aspect AspectModel.ttl to asyncapi
# Generate HTML documentation
oxirs aspect AspectModel.ttl to html
# Generate GraphQL schema
oxirs aspect AspectModel.ttl to graphql
# Generate TypeScript interfaces
oxirs aspect AspectModel.ttl to typescript
# Generate Python dataclasses
oxirs aspect AspectModel.ttl to python
# Generate Java code (POJOs/Records)
oxirs aspect AspectModel.ttl to java
# Generate Scala case classes
oxirs aspect AspectModel.ttl to scala
# Generate SQL DDL (PostgreSQL)
oxirs aspect AspectModel.ttl to sql --format postgresql
# Generate AAS (Asset Administration Shell) JSON
oxirs aspect AspectModel.ttl to aas --format json
# Generate diagram (DOT format)
oxirs aspect AspectModel.ttl to diagram --format dot
# Generate diagram (SVG format, requires Graphviz installed)
oxirs aspect AspectModel.ttl to diagram --format svg
# Generate sample JSON payload
oxirs aspect AspectModel.ttl to payload
# Generate JSON-LD with semantic context
oxirs aspect AspectModel.ttl to jsonld
# Generate DTDL for Azure Digital Twins
oxirs aspect AspectModel.ttl to dtdl
oxirs aspect AspectModel.ttl to dtdl -o azure/models/Movement.json
OxiRS is a drop-in replacement for the Java ESMF SDK. Simply replace samm with oxirs in your commands:
# Java ESMF SDK
samm aspect Movement.ttl to aas --format xml
# OxiRS (identical syntax, just replace 'samm' with 'oxirs')
oxirs aspect Movement.ttl to aas --format xml
OxiRS v0.1.0 includes bidirectional AAS (Asset Administration Shell) integration:
# Convert AAS Submodel Templates to SAMM Aspect Models
oxirs aas AssetAdminShell.aasx to aspect
oxirs aas AssetAdminShell.aasx to aspect -d output/
oxirs aas AssetAdminShell.aasx to aspect -s 1 -s 2 -d output/
# List all submodel templates in an AAS file
oxirs aas AssetAdminShell.aasx list
# Supports all AAS formats (XML, JSON, AASX)
oxirs aas file.xml to aspect # XML format
oxirs aas file.json to aspect # JSON format
oxirs aas file.aasx to aspect # AASX (default)
Implementation Status (v0.1.0):
Complete command comparison: See SAMM_CLI_COMPARISON.md
446 tests passing (100% pass rate):
| Metric | Value | Status |
|---|---|---|
| Test Pass Rate | 100% | ✅ |
| Clippy Warnings | 0 | ✅ |
| Documentation | 100% | ✅ |
| Code Coverage | ~98% | ✅ |
| Benchmarks | 15 | ✅ |
| Examples | 6 runnable | ✅ |
All generators and parsers are benchmarked:
Run benchmarks:
cargo bench
Comprehensive property-based testing with proptest:
Robust fuzz testing for parser resilience:
✅ Published: API_STABILITY.md
✅ Published: MIGRATION_GUIDE.md
✅ 100% Coverage:
All major features complete and tested:
Remaining items for General Availability:
Licensed under either of:
at your option.
Contributions are welcome! This is part of the OxiRS project. Please see the main CONTRIBUTING.md for guidelines.
Note: This crate is part of the OxiRS ecosystem, a Rust-native platform for Semantic Web, SPARQL 1.2, GraphQL, and AI-augmented reasoning.