I am trying to adapt a product's ontology with its properties using JSON. The below mentioned JSON structure is what I am thinking about.
Each Product (Concept) has two types of properties: 1. Data Properties 2. Object Properties
Typical Definitions for these properties when using Protege is as followsSO Thread:
In Protégé there are are different tabs for creating Object Properties and Datatype Properties. If a property should relate individuals to individuals, then it needs to be an object property, and if it relates individuals to literals, then it needs to be a datatype property.
I think of every property to have the following attributes:
name: string
url: string
type: dataprop or objprop
objPropSource: available only for Objproperties
I have drawn up a small recursive JSON as 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"
}
]
}
]
}
In a way structure provides a Binary Tree for a chair which has height
, width
etc. as dataproperties and horizontalsurface
and legislation
as objectproperties
JSON to Interface in Typescript
I used the JSON to TS Online Converter to see how will the JSON be converted to Typescript Interfaces and the outcome is following:
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
I infer that the aprroach for using Interfaces from Recursive JSON is not scalable since such an Ontology of a Product can scale upto 1000's of properties and properties within properties. As above mentioned example show that for every Property within a parent property would keep creating interfaces.
Expectation
Should I expect to use Typescript Interfaces with such JSON structure or should to stick to creating a Class and then following the conventional method of creating a Binary Tree viz.
export class leaf {
name: string;
url: string;
type: string;
children: leaf[] = [];
}
and then writing a recursion till the complete structure is parsed?
TL;DR
Can Typescript interfaces be used for Large Recursive JSON Structures?