Classes and instances in ontology menu

This commit is contained in:
2026-07-07 16:26:31 +02:00
parent 60646cebf6
commit 6a8acfeb0f
4 changed files with 4443 additions and 26 deletions

View File

@@ -2,15 +2,47 @@
* @module Ontology
*/
export class Ontology {
#data;
/**
* @param {Object} data The parsed ontology object (from JSON)
*/
set data(data) {
this.#data = data;
}
/**
* @param {String} id
*/
getInstanceById(id) {
return this.#data.instancesById[id];
}
/**
* @returns {Array<{en: string, it: string}>} The bloody array of label objects
*/
getInstanceLabels() {
const data = this.#data;
const instances = [];
for (const key of Object.keys(data.instancesById)) {
instances.push(data.instancesById[key]?.label);
}
return instances;
}
}
/**
* @todo Temporarily returns domains and ontology labels only
* Traverse an ontology from its JSON description
* @param {String} jsonPath The path (URI) of the ontology JSON file
* @param {Object} ontologyObject The parsed ontology JSON
* @returns {Object}
*/
export async function traverseOntology(jsonPath) {
const ontology = await loadOntology(jsonPath);
const modules = ontology.modules;
export async function traverseOntology(ontologyObject) {
//const ontology = await loadOntology(jsonPath);
const modules = ontologyObject.domains;
const domains = [];
@@ -20,7 +52,7 @@ export async function traverseOntology(jsonPath) {
traverseClasses(classTree, tree);
}
domains.push({
id: module.id,
id: module.label.it ?? module.label.en,
tree
});
}