Update RDF Conversion to JSON LD authored by Nidhi Santosh Shinde's avatar Nidhi Santosh Shinde
### **Section 1: Introduction to JSON-LD**
#### **1.1 Purpose of JSON-LD**
JSON-LD (JavaScript Object Notation for Linked Data) provides a JSON-based serialization format for RDF graphs.
**Example**: Ontology **`:contains`** property:
```
:contains rdf:type owl:ObjectProperty;
rdfs:domain :Assembly;
rdfs:range :Component.
```
⇨ JSON-LD :
```
{
@context": {
"contains": "http://www.sfb1574.kit.edu/core#contains"
},
"contains": { ... }
}
```
The context maps "contains" to its full IRI.
#### **1.2 How to define Context?**
##### **Rule 1: IRI Resolution**
Turtle uses _`@prefix`_\* . JSON-LD's **`@context`** maps these to full IRIs.
_Turtle prefix:_
```
@prefix : <http://www.sfb1574.kit.edu/core#> .
```
_⇨ JSON-LD :_
```
@context": {
"core": "http://www.sfb1574.kit.edu/core#",
"Assembly": "core:Assembly",
"contains": "core:contains"
}
```
> Now **`Assembly`** = **`http://www.sfb1574.kit.edu/core#Assembly`**
##### **Rule 2: Constraint Propagation**
Ontology defines rules (like "only Assemblies can contain Components"). JSON-LD preserves these:
_Turtle property definition:_
```
:contains rdf:type owl:ObjectProperty ;
rdfs:domain :Assembly ; // Only Assemblies can "contain"
rdfs:range :Component . // Only Components can be contained
```
_⇨ JSON-LD :_
```
"contains": {
"@id": "core:contains",
"@type": "@id", // Indicates this is a relationship
"domain": "core:Assembly", // Enforces domain constraint
"range": "core:Component" // Enforces range constraint
}
```
### **Section 2: Core Conversion**
#### **2.1 Mapping Rules**
##### **IRIs, Blank Nodes, and Literals**
| **RDF Construct** | **JSON-LD Equivalent** | **Example** |
|-------------------|------------------------|-------------|
| **Absolute IRI** | **`@id`** | **`"@id": "http://.../EngineAssembly"`** |
| **Blank Node** | Nested object | **`"bolt": { "@type": "Component" }`** |
| **Typed Literal** | **`@value`** + **`@type`** | **`"@value": "2025-01-20", "@type": "xsd:date"`** |
**"Core" Ontology Example**:
```
:EnvironmentalCondition rdf:type owl:Class.
```
⇨ JSON-LD:
```
{
"@id": "http://www.sfb1574.kit.edu/core#EnvironmentalCondition",
"@type": "owl:Class"
}
```
#### **2.2 Handling RDF Types and Classes**
##### **Class Declaration Conversion**
OWL class definition:
```
:Component rdf:type owl:Class ;
rdfs:comment "A component is any part or subunit..." .
```
⇨ JSON-LD:
```
{
"@id": "http://www.sfb1574.kit.edu/core#Component",
"@type": "owl:Class",
"rdfs:comment": "A component is any part or subunit..."
}
```
**Explanation**:
* **`@id`**: Unique identifier (like a web link).
* **`@type`**: Specifies this is a "class" (a category of things).
* **`rdfs:comment`**: The description (unchanged).
#### **2.3 Converting Relationships**
```
:contains rdf:type owl:ObjectProperty ;
rdfs:domain :Assembly ;
rdfs:range :Component ;
rdfs:comment "An assembly contains different components" .
```
⇨ JSON-LD :
```
{
"@id": "http://www.sfb1574.kit.edu/core#contains",
"@type": "owl:ObjectProperty",
"rdfs:domain": { "@id": "core:Assembly" },
"rdfs:range": { "@id": "core:Component" },
"rdfs:comment": "An assembly contains different components"
}
```
**Explanation**:
* **`rdfs:domain`**: Defines _where_ the relationship applies (**`Assembly`**).
* **`rdfs:range`**: Defines _what_ it points to (**`Component`**).
* Note: **`core:`** is a shortcut for **`http://www.sfb1574.kit.edu/core#`**.
#### **2.4 Converting Nested Data**
```
:Operation rdf:type owl:Class ;
rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:onProperty :implementsCapability ;
owl:someValuesFrom :Capability
] .
```
⇨ JSON-LD:
```
{
"@id": "core:Operation",
"@type": "owl:Class",
"rdfs:subClassOf": {
"@type": "owl:Restriction",
"owl:onProperty": { "@id": "core:implementsCapability" },
"owl:someValuesFrom": { "@id": "core:Capability" }
}
}
```
**Explanation**:
* Nested structures (like **`owl:Restriction`**) become child objects in JSON.
* Relationships (**`implementsCapability`**, **`Capability`** Keep their links via **`@id`**.
#### 2.5 **Converting Individual Instances**
When there are actual data records (e.g., "Product_X is a Component")
```
:Product_X rdf:type :Component ;
:hasVersion "v2.0" ;
:hasLocation :Factory_A .
```
⇨ JSON-LD :
```
{
"@id": "core:Product_X",
"@type": "core:Component",
"core:hasVersion": "v2.0",
"core:hasLocation": { "@id": "core:Factory_A" }
}
```
**Explanation:**
* **`@type`** replaces **`rdf:type`** for cleaner syntax.
* Literal values (like **`"v2.0"`**) need no extra formatting.
* Relationships (e.g., **`hasLocation`**) use **`@id`** to link entities.
#### **2.6 Inverse Property Handling**
```
:hasCapability owl:inverseOf :providedByResource.
```
⇨ JSON-LD :
```
"hasCapability": {
"@id": "core:hasCapability",
"@reverse": "core:providedByResource"
}
```
**Explanation:**
JSON-LD preserves bidirectional links:
* If **`Resource_A → hasCapability → Capability_B`**, then automatically:\
**`Capability_B → providedByResource → Resource_A`**.
#### 2.7 **Representing RDF in JSON-LD files**
**RDF Triple conversion :**
```
<subject> <predicate> <object>
{ "@id": subject, predicate: object }
```
**"Core" Data**:
```
:EngineAssembly :contains :PistonComponent.
```
⇨ JSON-LD:
```
{
"@id": "core:EngineAssembly",
"contains": { "@id": "core:PistonComponent" }
}
```
\ No newline at end of file