I am currently working on adapting a product's ontology with its properties using JSON. The structure I have in mind is outlined below.
Each Product (Concept) has two types of properties: 1. Data Properties 2. Object Properties
When using Protege, the typical definitions for these properties are as followsSO Thread:
In Protégé, there are different tabs for creating Object Properties and Datatype Properties. If a property relates individuals to individuals, it needs to be an object property; if it relates individuals to literals, it needs to be a datatype property.
For each property, I believe it should have the following attributes:
name: string
url: string
type: dataprop or objprop
objPropSource: available only for Objproperties
I have designed a small recursive JSON structure as shown below:
{
"name": "chair",
"url": "http://namespace.org#chair",
"type": "main",
"properties": [
{
"name": "height",
"url": "http://namespace.org#height",
"type": "dataprop"
},
{
"name": "width",
"url": "http://namespace.org#width",
"type": "dataprop"
},
{
"name": "horizontalsurface",
"url": "http://namespace.org#horizontalsurface",
"type": "objprop",
"objPropSource": "http://namespace.org#hasHorizontalSurface",
"properties": [
{
"name": "Legislation",
"url": "http://namespace.org#legislation",
"type": "objprop",
"objPropSource": "http://namespace.org#compliesWithLegislation",
"properties": [
{
"name": "hasLegislationName",
"url": "http://namespace.org#hasLegislationName",
"type": "dataprop"
}
]
}
]
},
{
"name": "legislation",
"url": "http://namespace.org#legislation",
"type": "objprop",
"objPropSource": "http://namespace.org#compliesWithLegistion",
"properties": [
{
"name": "hasLegislationName",
"url": "http://namespace.org#hasLegislationName",
"type": "dataprop"
}
]
}
]
}
This structure essentially provides a Binary Tree for a chair, where properties like height
, width
are considered as dataproperties, while horizontalsurface
and legislation
are treated as objectproperties.
JSON to Interface in Typescript
To visualize how the JSON converts to Typescript Interfaces, I utilized the JSON to TS Online Converter and obtained the following outcome:
interface RootObject {
name: string;
url: string;
type: string;
properties: Property3[];
}
interface Property3 {
name: string;
url: string;
type: string;
objPropSource?: string;
properties?: Property2[];
}
interface Property2 {
name: string;
url: string;
type: string;
objPropSource?: string;
properties?: Property[];
}
interface Property {
name: string;
url: string;
type: string;
}
Inference
From my inference, utilizing Interfaces for large recursive JSON structures may not be scalable. As demonstrated in the example above, when dealing with thousands of properties within properties, constantly creating interfaces can become cumbersome.
Expectation
Should I continue using Typescript Interfaces with such a JSON structure, or would it be more efficient to create a Class and implement a conventional method of constructing a Binary Tree as shown below:
export class leaf {
name: string;
url: string;
type: string;
children: leaf[] = [];
}
Followed by writing a recursive function for parsing through the complete structure?
TL;DR
Can Typescript interfaces effectively handle Large Recursive JSON Structures?