WIP ontology tree in menu
This commit is contained in:
@@ -10,25 +10,51 @@
|
||||
*/
|
||||
export async function traverseOntology(jsonPath) {
|
||||
const ontology = await loadOntology(jsonPath);
|
||||
const domains = [];
|
||||
const modules = ontology.modules;
|
||||
|
||||
for (const k of Object.keys(ontology)) {
|
||||
if (k === 'domains') {
|
||||
for (const domainKey of Object.keys(ontology[k])) {
|
||||
domains.push({
|
||||
label: domainKey,
|
||||
child: ontology[k][domainKey][0].label,
|
||||
});
|
||||
let tree = [];
|
||||
|
||||
for (const module of modules) {
|
||||
if (module.id === 'Architecture') {
|
||||
console.debug(module.classTrees);
|
||||
for (const classTree of module.classTrees) {
|
||||
traverseClasses(classTree, tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ontology: ontology.ontology,
|
||||
domains
|
||||
ontology: "Architecture",
|
||||
domains: tree
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} ontologyClass
|
||||
* @param {Array<Object>} tree
|
||||
* @param {Number} depth
|
||||
*/
|
||||
function traverseClasses(ontologyClass, tree, depth = 1) {
|
||||
const ontologyNode = {
|
||||
id: ontologyClass.id,
|
||||
label: ontologyClass.label,
|
||||
depth,
|
||||
children: [],
|
||||
};
|
||||
|
||||
tree.push(ontologyNode);
|
||||
|
||||
if (ontologyClass.children && Array.isArray(ontologyClass.children)) {
|
||||
for(const child of ontologyClass.children) {
|
||||
ontologyNode.children.push(
|
||||
traverseClasses(child, tree, depth + 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an ontology from its JSON description
|
||||
* @param {String} jsonPath The path (URI) of the ontology JSON file
|
||||
|
||||
Reference in New Issue
Block a user