[Trunk | Explore]: parsingFunctions.class.ts: [Bug fix] Parse contexts properly when a label is null/undefined or empty string (result landing page).

This commit is contained in:
Konstantina Galouni 2021-10-11 14:02:22 +03:00
parent 7a375ee6f7
commit 64051887ce
1 changed files with 27 additions and 17 deletions

View File

@ -599,49 +599,59 @@ export class ParsingFunctions {
"labelCategory": string, "idCategory": string,
"labelConcept": string, "idConcept": string
}>();
let position = 0;
let labels = "";
let context;
let length = Array.isArray(_contexts) ? _contexts.length : 1;
for (let i = 0; i < length; i++) {
let numOfCategories: number = 0; // count categories with label
context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
if (context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
if (context.label && context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
if (context.hasOwnProperty("category")) {
let category;
let length2 = Array.isArray(context['category']) ? context['category'].length : 1;
for (let z = 0; z < length2; z++) {
let numOfConcepts: number = 0; // count category concepts with label
category = Array.isArray(context['category']) ? context['category'][z] : context['category'];
if (category.hasOwnProperty("concept")) {
if (category.label && category.hasOwnProperty("concept")) {
let categoryConcept;
let length1 = Array.isArray(category['concept']) ? category['concept'].length : 1;
for (let j = 0; j < length1; j++) {
categoryConcept = Array.isArray(category['concept']) ? category['concept'][j] : category['concept'];
contexts[position] = {"labelContext": "", "idContext": "",
"labelCategory": "", "idCategory": "",
"labelConcept": "", "idConcept": ""};
contexts[position]['labelContext'] = context.label;
contexts[position]['idContext'] = context.id;
contexts[position]['labelCategory'] = category.label;
contexts[position]['idCategory'] = category.id;
contexts[position]['labelConcept'] = categoryConcept.label;
contexts[position]['idConcept'] = categoryConcept.id;
position++;
// initalize if there is concept label or this is the last concept of the category and there were no concepts
// otherwise we could have multiple entries for the same category but without concepts
if(categoryConcept.label || (numOfConcepts == 0 && j == (length1 - 1))) {
contexts[position] = {
"labelContext": "", "idContext": "",
"labelCategory": "", "idCategory": "",
"labelConcept": "", "idConcept": ""
};
contexts[position]['labelContext'] = context.label;
contexts[position]['idContext'] = context.id;
contexts[position]['labelCategory'] = category.label;
contexts[position]['idCategory'] = category.id;
contexts[position]['labelConcept'] = categoryConcept.label ? categoryConcept.label : null;
contexts[position]['idConcept'] = categoryConcept.label ? categoryConcept.id : null;
position++;
numOfConcepts++;
}
}
} else {
} else if(category.label || (numOfCategories == 0 && z == (length2 - 1))) {
contexts[position] = {"labelContext": "", "idContext": "",
"labelCategory": "", "idCategory": "",
"labelConcept": "", "idConcept": ""};
contexts[position]['labelContext'] = context.label;
contexts[position]['idContext'] = context.id;
contexts[position]['labelCategory'] = category.label;
contexts[position]['idCategory'] = category.id;
contexts[position]['labelCategory'] = category.label ? category.label : null;
contexts[position]['idCategory'] = category.label ? category.id : null;
contexts[position]['labelConcept'] = null;
contexts[position]['idConcept'] = null;
position++;
numOfCategories++;
}
}
} else {