Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Most ontologies are based on semantic web standards such as OWL, RDF, and RDFS.
To use a model with Azure Digital Twins, you must convert it to DTDL format. This article describes general design guidance in the form of a conversion pattern for converting RDF-based models to DTDL so that you can use them with Azure Digital Twins.
Although the examples in this article are building-focused, you can apply similar processes to standard ontologies across different industries to convert them to DTDL as well.
Conversion pattern
There are several third-party libraries that can be used when converting RDF-based models to DTDL. Some of these libraries allow you to load your model file into a graph. You can loop through the graph looking for specific RDFS and OWL constructs, and convert them to DTDL.
The following table is an example of how RDFS and OWL constructs can be mapped to DTDL.
| RDFS/OWL concept | RDFS/OWL construct | DTDL concept | DTDL construct |
|---|---|---|---|
| Classes | owl:ClassIRI suffix rdfs:labelrdfs:comment |
Interface | @type:Interface@iddisplayNamecomment |
| Subclasses | owl:ClassIRI suffix rdfs:labelrdfs:commentrdfs:subClassOf |
Interface | @type:Interface@iddisplayNamecommentextends |
| Datatype Properties | owl:DatatypePropertyrdfs:label or INoderdfs:labelrdfs:range |
Interface Properties | @type:PropertynamedisplayNameschema |
| Object Properties | owl:ObjectPropertyrdfs:label or INoderdfs:rangerdfs:commentrdfs:label |
Relationship | type:Relationshipnametarget (or omitted if no rdfs:range)commentdisplayName |
The following C# code snippet shows how an RDF model file is loaded into a graph and converted to DTDL, using the dotNetRDF library.
using VDS.RDF.Ontology;
using VDS.RDF.Parsing;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace DigitalTwins_Samples
{
public class DigitalTwinsConvertRDFSample
{
public void Run()
{
Console.WriteLine("Reading file...");
FileLoader.Load(_ontologyGraph, rdfFile.FullName);
// Start looping through for each owl:Class
foreach (OntologyClass owlClass in _ontologyGraph.OwlClasses)
{
// Generate a DTMI for the owl:Class
string Id = GenerateDTMI(owlClass);
if (!String.IsNullOrEmpty(Id))
{
Console.WriteLine($"{owlClass.ToString()} -> {Id}");
// Create Interface
var dtdlInterface = new DtdlInterface
{
Id = Id,
Type = "Interface",
DisplayName = GetInterfaceDisplayName(owlClass),
Comment = GetInterfaceComment(owlClass),
Contents = new List<DtdlContents>(),
};
// An OWL graph can have parent/child classes.
// So to understand if an OWL class is a base class or a child class,
// look for a superclass on any given OWL class.
// If found, convert these to parent + child Interfaces using DTDL extends.
IEnumerable<OntologyClass> foundSuperClasses = owlClass.DirectSuperClasses;
//...
}
// Add interface to the list of interfaces
_interfaceList.Add(dtdlInterface);
}
// Serialize to JSON
var json = JsonConvert.SerializeObject(_interfaceList);
}
}
}
Next steps
Continue on the path for developing models based on ontologies: Full model development path.