RDF Module¶
This module provides a comprehensive framework for parsing, analyzing, and rendering RDF (Resource Description Framework) schemas, with a focus on the Common Information Model (CIM) and related standards. It enables the transformation of RDF-based ontologies into strongly-typed C#, Java(experimental) and Python(experimental) classes and enumerations, supporting advanced code generation and schema management scenarios.
It is easily extendable to support new RDF vocabularies, code generation templates, or schema analysis strategies.
User Interface¶
This module doesn't provides UI.
Features¶
-
RDF Schema Parsing
- Extracts namespaces, headers, classes, attributes, data types, enumerations, and concrete classes from RDF/XML files.
- Supports detailed introspection of RDF graphs using the dotNetRDF library.
-
Schema Analysis
- Analyzes RDF classes, attributes, and data types to determine their render requirements and C#, Java(experimental) and Python(experimental) type mappings.
- Distinguishes between primitive types, references, enumerations, and concrete classes.
-
Code Generation
- Renders C#, Java(experimental) and Python(experimental) classes and enumerations from RDF schema definitions using Scriban templates.
- Supports extensible and customizable code generation pipelines.
-
Schema Management
- Provides a domain service for loading, updating, and managing RDF schema representations.
- Enables updating of schema elements (classes, attributes, data types, enumerations) in a consistent and type-safe manner.
-
Ontology Hierarchy Support (experimental)
- Support for ontology graph parsing and hierarchy building, including class inheritance and property relationships.
Options¶
RdfSchemaAnalyzerOptions¶
RdfSchemaAnalyzerOptions
can be configured in the application layer, within the ConfigureServices
method of your module. Example:
Configure<RdfSchemaAnalyzerOptions>(options =>
{
// Set options here...
});
Options for configuring the RDF Schema Parser.
Option | Type | Default | Description |
---|---|---|---|
IgnoreUnknownTypes | bool | false | If true, parser will ignore unknown or unsupported RDF types instead of throwing. |
InferLabels | bool | false | If true, parser will attempt to infer missing labels from URIs. |
NormalizeLiterals | bool | true | If true, parser will normalize literal values (e.g., trim whitespace, convert to lowercase). |
RdfSchemaParserOptions¶
RdfSchemaParserOptions
can be configured in the application layer, within the ConfigureServices
method of your module. Example:
Configure<RdfSchemaParserOptions>(options =>
{
// Set options here...
});
Options for configuring the RDF Schema Analyzer.
Option | Type | Default | Description |
---|---|---|---|
ThrowOnUnknownTypes | bool | false | If true, analyzer will treat unknown/unsupported types as errors. |
InferPropertyTypes | bool | false | If true, analyzer will infer missing property types from context. |
NormalizeNames | bool | false | If true, analyzer will normalize property and class names (e.g., PascalCase, SnakeCase). |
ReservedKeywordSuffix | string | "_" | Suffix to append to reserved keywords to avoid conflicts. |
TemplateRendererOptions¶
TemplateRendererOptions
can be configured in the application layer, within the ConfigureServices
method of your module. Example:
Configure<TemplateRendererOptions>(options =>
{
// Set options here...
});
Options for configuring the Template Renderer.
Option | Type | Default | Description |
---|---|---|---|
IncludeAutoGeneratedComment | bool | true | If true, will include an auto-generated comment in generated files. |
Model Generator Tool¶
The ModelGenerator
is a command-line tool for generating code from RDF schema files (such as CGMES or CIM). It supports multiple target languages (CSharp, Java, Python) and is highly configurable via command-line options. The tool can be run directly or as a Docker container.
Usage¶
-
Running Locally
You can run the tool directly from the command line after building the project:
dotnet run --project host/GridLab.PSSX.ModelGenerator -- [OPTIONS]
Or, if you have a published executable:
GridLab.PSSX.ModelGenerator.exe [OPTIONS]
Common Options:
Option Description -i, --input Directory containing RDF files -p, --rdfFilePattern File pattern to search for RDF files (default: *.rdf) -f, --inputFile Single RDF file to process -o, --output Output directory (defaults to executable location) -m, --mergeSchemas Merge all schemas and their attributes --profileName Name of the profile for generated classes (if schemas are merged) --version Version for generated classes (if schemas are merged) --namespace Namespace for generated classes (if schemas are merged) --overwriteFiles Overwrite existing files in the output directory --classTemplatePath Path to custom Scriban template for classes --enumerationTemplatePath Path to custom Scriban template for enumerations -l, --language Target language: CSharp, Java, Python -w, --logWarnings Log warnings for missing/malformed schema elements -d, --includeDeprecated Include deprecated classes/properties --namespaces Allowed namespace prefixes (comma-separated) --allowedClassNames Allowed class names (comma-separated) --allowedAttributeNames Allowed attribute names (comma-separated) --allowedEnumerationNames Allowed enumeration names (comma-separated) --ignoreUnknownTypes Ignore unknown/unsupported RDF types instead of throwing --inferLabels Infer missing labels from URIs --normalizeLiterals Normalize literal values --throwOnUnknownTypes Treat unknown/unsupported types as errors --inferPropertyTypes Infer missing property types from context --normalizeNames Normalize property/class names (e.g., PascalCase, SnakeCase) --reservedKeywordSuffix Suffix to append to reserved keywords --includeAutoGeneratedComment Include an auto-generated comment in generated files To see all options and their descriptions, run:
GridLab.PSSX.ModelGenerator.exe --help
-
Running as a Docker Image
A Docker image is provided for easy execution in containerized environments.
Build the Docker Image:
Use
build\build-images-locally.ps1
powershell script.Example:
Mount your RDF schema directory and specify output as needed:
docker run --rm \ -v /path/to/your/rdf:/app/CGMES_Schema \ -v /path/to/output:/app/models \ gridlab.pssx.modelgenerator/application \ --input /app/CGMES_Schema/CGMES_3.0.0 \ --output /app/models \ --language CSharp \ --mergeSchemas true \ --profileName IEC61970 \ --namespace Profiles.IEC61970 \ --version 3.0.0
-
Replace
/path/to/your/rdf
with the path to your RDF files on your host. - Replace
/path/to/output
with the desired output directory on your host.