Project

General

Profile

1 58275 k.triantaf
import {HostedByCollectedFrom, Journal, Project, RelationResult} from "../../utils/result-preview/result-preview";
2 58288 k.triantaf
import {Reference} from "../../utils/entities/resultLandingInfo";
3 50169 argiro.kok
4
export class ParsingFunctions {
5 59038 konstantin
  public open = 'assets/common-assets/unlock.svg';
6
  public closed = 'assets/common-assets/lock.svg';
7
  public unknown = 'assets/common-assets/question.svg';
8
9 58275 k.triantaf
  constructor() {
10
  }
11
12
  public ngOnDestroy() {
13
  }
14
15
  public parseFundingByProjects(fundedByProjects: Project[], relation: any,
16
                                provenanceActionVocabulary: any): Project[] {
17
    if (fundedByProjects == undefined) {
18
      fundedByProjects = [];
19 50169 argiro.kok
    }
20 58275 k.triantaf
21
    let fundedByProject: Project = {
22
      "id": "", "acronym": "", "title": "",
23
      "funderShortname": "", "funderName": "",
24
      "funding": "", "code": "", "provenanceAction": "", "inline": false
25
    };
26
27
    if (relation.title != 'unidentified') {
28 50169 argiro.kok
      fundedByProject['id'] = relation['to'].content;
29
      fundedByProject['acronym'] = relation.acronym;
30
      fundedByProject['title'] = relation.title;
31
      fundedByProject['code'] = relation.code;
32 58275 k.triantaf
33
      if (provenanceActionVocabulary != null && relation.provenanceaction in provenanceActionVocabulary) {
34 57330 konstantin
        fundedByProject['provenanceAction'] = provenanceActionVocabulary[relation.provenanceaction];
35 50169 argiro.kok
      }
36
    } else {
37
      fundedByProject['id'] = "";
38
      fundedByProject['acronym'] = "";
39
      fundedByProject['title'] = "";
40
      fundedByProject['code'] = "";
41
      fundedByProject['provenanceAction'] = "";
42
    }
43 58275 k.triantaf
44
    if (relation.hasOwnProperty("funding")) {
45
      let funding: { "funderName": string, "funderShortname": string, "stream": string };
46 50169 argiro.kok
      funding = this.parseFundingTrees(relation.funding);
47 58275 k.triantaf
48
      if (funding.funderName) {
49 50169 argiro.kok
        fundedByProject['funderName'] = funding.funderName;
50
      }
51 58275 k.triantaf
      if (funding.funderShortname) {
52 50169 argiro.kok
        fundedByProject['funderShortname'] = funding.funderShortname;
53
      }
54 58275 k.triantaf
      if (funding.stream) {
55 50169 argiro.kok
        fundedByProject['funding'] = funding.stream;
56
      }
57
    }
58
    fundedByProjects.push(fundedByProject);
59
    return fundedByProjects;
60
  }
61 58275 k.triantaf
62 50169 argiro.kok
  // publication & research data : for fundedByProjects | project landing : for funding
63 58275 k.triantaf
  public parseFundingTrees(fundingTree: any): { "funderName": string, "funderShortname": string, "stream": string } {
64
    let funding: { "funderName": string, "funderShortname": string, "stream": string } = {
65
      "funderName": "",
66
      "funderShortname": "",
67
      "stream": ""
68
    };
69 50169 argiro.kok
    let length = Array.isArray(fundingTree) ? fundingTree.length : 1;
70 58275 k.triantaf
71
    for (let i = 0; i < length; i++) {
72 50169 argiro.kok
      let fundingData = Array.isArray(fundingTree) ? fundingTree[i] : fundingTree;
73 58275 k.triantaf
74
      if (fundingData.hasOwnProperty("funder")) {
75 50169 argiro.kok
        funding.funderShortname = fundingData['funder'].shortname;
76
        funding.funderName = fundingData['funder'].name;
77
      }
78 58275 k.triantaf
79 50169 argiro.kok
      funding.stream = this.addFundingLevel0(fundingData, funding.stream);
80 58275 k.triantaf
81 50169 argiro.kok
      funding.stream = this.addFundingLevel1(fundingData, funding.stream);
82 58275 k.triantaf
83 50169 argiro.kok
      funding.stream = this.addFundingLevel2(fundingData, funding.stream);
84
    }
85
    return funding;
86
  }
87 58275 k.triantaf
88
  addFundingLevel0(parent: string, fundingStream: string): string {
89
    if (parent.hasOwnProperty("funding_level_0")) {
90 50169 argiro.kok
      let level0 = parent['funding_level_0'];
91 58275 k.triantaf
92 50169 argiro.kok
      fundingStream += (fundingStream) ? " ; " : "";
93
      fundingStream += level0.name;
94
    }
95
    return fundingStream;
96
  }
97 58275 k.triantaf
98 50169 argiro.kok
  addFundingLevel1(parent: string, fundingStream: string): string {
99 58275 k.triantaf
    if (parent.hasOwnProperty("funding_level_1")) {
100 50169 argiro.kok
      let level1 = parent['funding_level_1'];
101 58275 k.triantaf
102 50169 argiro.kok
      // For projects' parsing
103 58275 k.triantaf
      if (level1.hasOwnProperty("parent")) {
104 50169 argiro.kok
        fundingStream = this.addFundingLevel0(level1.parent, fundingStream);
105
      }
106 58275 k.triantaf
107 50169 argiro.kok
      fundingStream += (fundingStream) ? " | " : "";
108
      fundingStream += level1.name;
109
    }
110
    return fundingStream;
111
  }
112 58275 k.triantaf
113 50169 argiro.kok
  addFundingLevel2(parent: string, fundingStream: string): string {
114 58275 k.triantaf
    if (parent.hasOwnProperty("funding_level_2")) {
115 50169 argiro.kok
      let level2 = parent['funding_level_2'];
116 58275 k.triantaf
117 50169 argiro.kok
      // For projects' parsing
118 58275 k.triantaf
      if (level2.hasOwnProperty("parent")) {
119 50169 argiro.kok
        fundingStream = this.addFundingLevel1(level2.parent, fundingStream);
120
      }
121 58275 k.triantaf
122 50169 argiro.kok
      fundingStream += (fundingStream) ? " | " : "";
123
      fundingStream += level2.name;
124
    }
125
    return fundingStream;
126
  }
127 58275 k.triantaf
128 50169 argiro.kok
  // publication & dataset landing : for collectedFrom
129 58275 k.triantaf
  parseCollectedFrom(collectedFrom: { "name": string, "id": string }[],
130 50169 argiro.kok
                     _collectedFrom: any) {
131
    let length: number = collectedFrom.length;
132
    collectedFrom[length] = {"name": "", "id": ""};
133
    collectedFrom[length]['name'] = _collectedFrom.name;
134
    collectedFrom[length]['id'] = _collectedFrom.id;
135
  }
136 58275 k.triantaf
137 50169 argiro.kok
  // publication & dataset landing : for downloadFrom
138 58275 k.triantaf
  addPublisherToHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[],
139
                                       publisher: string, journal: Journal,
140
                                       identifiers: Map<string, string[]>/*, title: { "name": string, "url": string, "accessMode": string}*/) {
141
    if (publisher && identifiers != null && identifiers.has('doi')) {
142
      if (hostedBy_collectedFrom == null) {
143
        hostedBy_collectedFrom = [];
144 50169 argiro.kok
      }
145 58275 k.triantaf
      let available: HostedByCollectedFrom = {
146
        downloadName: "",
147
        downloadUrl: null,
148
        collectedName: "",
149
        collectedId: "",
150
        accessMode: null,
151
        bestAccessMode: null,
152
        type: "",
153 59038 konstantin
        year: "",
154
        icon: ""
155 58275 k.triantaf
      };
156
157
      if (journal && journal.journal) {
158
        available.downloadName = publisher + "/ " + journal['journal'];
159 50169 argiro.kok
      } else {
160
        available.downloadName = publisher;
161
      }
162 58275 k.triantaf
163
      let url = "https://dx.doi.org/" + identifiers.get("doi")[0];
164
165 50169 argiro.kok
      available.downloadUrl = new Array<string>();
166
      available.accessMode = new Array<string>();
167 58275 k.triantaf
168 50169 argiro.kok
      available.downloadUrl.push(url);
169 59038 konstantin
170
      available.icon = this.unknown;
171 58275 k.triantaf
      /*
172
            if(title != undefined && title['url'] == "") {
173
              title['url'] = url;
174
            }
175
      */
176 50169 argiro.kok
      hostedBy_collectedFrom.push(available);
177
    }
178
    return hostedBy_collectedFrom;
179
  }
180 58275 k.triantaf
181 50169 argiro.kok
  // publication & dataset landing : for downloadFrom
182 58275 k.triantaf
  parseDownloadFrom(downloadFrom: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, url: string) {
183 50169 argiro.kok
    let key: string = instance['hostedby'].name;
184 58275 k.triantaf
185
    if (key) {
186 50169 argiro.kok
      this.addUrlAndAccessMode(downloadFrom, instance, key, url);
187
    }
188
  }
189 58275 k.triantaf
190 50169 argiro.kok
  // publication & dataset landing : for publishedIn
191 58275 k.triantaf
  parsePublishedIn(publishedIn: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, result: any, url: string, counter: number): number {
192
    if (result != null && result.hasOwnProperty("source")) {
193 50169 argiro.kok
      let key: string;
194 58275 k.triantaf
      if (Array.isArray(result.source)) {
195
        if (counter == result.source.length) {
196 50169 argiro.kok
          counter--;
197
        }
198
        key = result['source'][counter];
199
      } else {
200
        key = result['source'];
201
      }
202 58275 k.triantaf
203
      if (key) {
204 50169 argiro.kok
        this.addUrlAndAccessMode(publishedIn, instance, key, url);
205
        counter++;
206
      }
207
    }
208
    return counter;
209
  }
210 58275 k.triantaf
211 50169 argiro.kok
  // publication & dataset landing : for downloadFrom and publishedIn
212 58275 k.triantaf
  addUrlAndAccessMode(mapStructure: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, key: string, url: string) {
213
    if (!mapStructure.has(key)) {
214 50169 argiro.kok
      mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
215
    }
216 58275 k.triantaf
217
    if (mapStructure.get(key)['url'] == null) {
218 50169 argiro.kok
      mapStructure.get(key)['url'] = new Array<string>();
219
    }
220 58275 k.triantaf
221
    if (url) {
222 50169 argiro.kok
      mapStructure.get(key)['url'].push(url);
223
    }
224 58275 k.triantaf
225
    if (mapStructure.get(key)['accessMode'] == null) {
226 50169 argiro.kok
      mapStructure.get(key)['accessMode'] = new Array<string>();
227
    }
228 58275 k.triantaf
229
    if (instance.hasOwnProperty("accessright")) {
230
      if (url) {
231
        mapStructure.get(key)['accessMode'].push(instance['accessright'].classname);
232 50169 argiro.kok
      }
233 58275 k.triantaf
234
      if (this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) {
235
        mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classname;
236 50169 argiro.kok
      }
237 58275 k.triantaf
    } else if (url) {
238 50169 argiro.kok
      mapStructure.get(key)['accessMode'].push("");
239
    }
240
  }
241 58275 k.triantaf
242
243
  parseHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[],
244 52606 konstantin
                              instance: any, data: any, url: string, counter: number/*,
245
                              title: { "name": string, "url": string, "accessMode": string}*/, accessMode: string): number {
246 58275 k.triantaf
    let available: HostedByCollectedFrom = {
247
      "downloadName": "",
248
      "downloadUrl": null,
249
      "collectedName": "",
250
      "collectedId": "",
251
      "accessMode": null,
252
      "bestAccessMode": null,
253
      "type": "",
254 59038 konstantin
      "year": "",
255
      "icon": ""
256 58275 k.triantaf
    };
257
258
    if (instance['hostedby'].name && instance['hostedby'].name != "other resources" && instance['hostedby'].name != "Unknown Repository") {
259
      available.downloadName = instance['hostedby'].name;
260
    } else {
261 59124 konstantin
    //   if (data != null && data.hasOwnProperty("source")) {
262
    //     let downloadName: string;
263
    //     if (Array.isArray(data.source)) {
264
    //
265
    //       if (counter == data.source.length) {
266
    //         counter--;
267
    //       }
268
    //       downloadName = data['source'][counter];
269
    //     } else {
270
    //       downloadName = data['source'];
271
    //     }
272
    //     if (downloadName) {
273
    //       counter++;
274
    //       available.downloadName = downloadName;
275
    //     }
276
    //   }
277
    //
278
    // }
279
    //
280
    // if(!available.downloadName) {
281 59038 konstantin
      available.downloadName = url.substring(0, 30) + '...';  // substring(from, to);
282
    }
283
284 58275 k.triantaf
    if (available.downloadName) {
285
      if (instance.hasOwnProperty("collectedfrom")) {
286
        available.collectedId = instance['collectedfrom'].id;
287
        available.collectedName = instance['collectedfrom'].name;
288
      }
289
290
      if (instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
291
        available.type = instance['instancetype'].classname;
292
      }
293
294
      if (instance.hasOwnProperty("dateofacceptance")) {
295
        var date: string = (instance.dateofacceptance) + ""; // transform to string in case it is an integer
296
        available.year = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
297
      }
298
299
      available.accessMode = new Array<string>();
300
      available.downloadUrl = new Array<string>();
301
      available['downloadUrl'].push(url);
302
      if (instance.hasOwnProperty("accessright")) {
303
        if (url) {
304
          available['accessMode'].push(instance['accessright'].classname);
305
        }
306
307
        if (this.changeBestAccessMode(available.bestAccessMode, instance['accessright'])) {
308
          available.bestAccessMode = instance['accessright'].classname;
309
          /*
310
                     if(title != undefined) {
311
                       if(this.changeBestAccessMode(title['accessMode'], instance['accessright'])) {
312
                         title['accessMode'] = instance['accessright'].classid;
313
                         title['url'] = url;
314
                       }
315
                     }
316
          */
317
          if (this.changeBestAccessMode(accessMode, instance['accessright'])) {
318
            accessMode = instance['accessright'].classname;
319
          }
320
        }
321
        /*
322
                 if(title != undefined) {
323
                   if(!title['url']) {
324
                     title['url'] = url;
325
                   }
326
                 }
327
        */
328
      } else if (url) {
329
        available['accessMode'].push("");
330
      }
331 59038 konstantin
332
      if (available.bestAccessMode) {
333
        if (available.bestAccessMode.toLowerCase().indexOf('open') !== -1) {
334
          available.icon = this.open;
335
        } else if (available.bestAccessMode.toLowerCase().indexOf('not available') !== -1) {
336
          available.icon = this.unknown;
337
        } else {
338
          available.icon = this.closed;
339
        }
340
      } else {
341
        available.icon = this.unknown;
342
      }
343 58275 k.triantaf
344
      hostedBy_collectedFrom.push(available);
345
    }
346
347
    return counter;
348 50169 argiro.kok
  }
349 58275 k.triantaf
350 50169 argiro.kok
  // publication & dataset landing : for downloadFrom and publishedIn
351
  changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean {
352 58275 k.triantaf
    if (!accessMode) {
353 50169 argiro.kok
      return false;
354
    }
355
    accessMode = accessMode.classid;
356 58275 k.triantaf
357 50169 argiro.kok
    switch (currentAccessMode) {
358
      case null:
359 58275 k.triantaf
        if (accessMode != "UNKNOWN") {
360 52606 konstantin
          return true;
361
        }
362
        return false;
363 50169 argiro.kok
      case "CLOSED":
364 58275 k.triantaf
        if (accessMode == "OPEN" ||
365
          accessMode == "OPEN SOURCE" ||
366
          accessMode == "EMBARGO" ||
367
          accessMode == "RESTRICTED") {
368
          return true;
369 50169 argiro.kok
        }
370
        return false;
371
      case "RESTRICTED":
372 58275 k.triantaf
        if (accessMode == "OPEN" ||
373
          accessMode == "OPEN SOURCE" ||
374
          accessMode == "EMBARGO") {
375
          return true;
376 50169 argiro.kok
        }
377
        return false;
378
      case "EMBARGO":
379 58275 k.triantaf
        if (accessMode == "OPEN" ||
380
          accessMode == "OPEN SOURCE") {
381 50169 argiro.kok
          return true;
382 52606 konstantin
        }
383
        return false;
384
      case "OPEN SOURCE":
385 58275 k.triantaf
        if (accessMode == "OPEN") {
386 52606 konstantin
          return true;
387
        }
388
        return false;
389 50169 argiro.kok
    }
390
    return false;
391
  }
392 58275 k.triantaf
393 52828 konstantin
  // publication & dataset & software & orp landing : for relatedResearchResults
394 58275 k.triantaf
  parseRelatedResearchResults(relatedResearchResults: RelationResult[], relation: any, provenanceAction: string):
395
    RelationResult[] {
396
    if (relatedResearchResults == undefined) {
397
      relatedResearchResults = []
398 50169 argiro.kok
    }
399 58275 k.triantaf
    relatedResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust", provenanceAction));
400 50169 argiro.kok
    return relatedResearchResults;
401
  }
402 58275 k.triantaf
403 57404 konstantin
  // publication & dataset & software & orp landing : for supplementaryResearchResults
404 58275 k.triantaf
  parseSupplementaryResearchResults(supplementaryResearchResults: RelationResult[], relation: any): RelationResult[] {
405
    if (supplementaryResearchResults == undefined) {
406
      supplementaryResearchResults = [];
407 57404 konstantin
    }
408
    supplementaryResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
409
    return supplementaryResearchResults;
410
  }
411 58275 k.triantaf
412 57404 konstantin
  // publication & dataset & software & orp landing : for supplementedByResearchResults
413 58275 k.triantaf
  parseSupplementedByResearchResults(supplementedByResearchResults: RelationResult[], relation: any): RelationResult[] {
414
    if (supplementedByResearchResults == undefined) {
415
      supplementedByResearchResults = [];
416 57404 konstantin
    }
417
    supplementedByResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
418
    return supplementedByResearchResults;
419
  }
420 58275 k.triantaf
421 52828 konstantin
  // publication & dataset & software & orp landing : for similarResearchResults
422 58275 k.triantaf
  parseSimilarResearchResults(similarResearchResults: RelationResult[], relation: any): RelationResult[] {
423
    if (similarResearchResults == undefined) {
424
      similarResearchResults = [];
425 50169 argiro.kok
    }
426 52103 konstantin
    similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "similarity"));
427 50169 argiro.kok
    return similarResearchResults;
428
  }
429 58275 k.triantaf
430 52828 konstantin
  // publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults
431 58275 k.triantaf
  parseRelatedOrSimilarResearchResult(relation: any, percentageName: string, provenanceAction: string = null): RelationResult {
432
    let researchResult: RelationResult = {
433
      name: "",
434
      id: "",
435
      date: "",
436
      percentage: null,
437
      class: "",
438
      provenanceAction: provenanceAction
439
    };
440 58496 argiro.kok
    if(relation['resulttype']) {
441
      if (relation['resulttype'].classname == "publication") {
442
        researchResult['class'] = "publication";
443
      } else if (relation['resulttype'].classname == "dataset") {
444
        researchResult['class'] = "dataset";
445
      } else if (relation['resulttype'].classname == "software") {
446
        researchResult['class'] = "software";
447
      } else if (relation['resulttype'].classname == "other") {
448
        researchResult['class'] = "other";
449
      }
450 50169 argiro.kok
    }
451
    researchResult['id'] = relation['to'].content;
452 58496 argiro.kok
    let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : (relation['title']?relation['title'].content:null);
453 50169 argiro.kok
    researchResult['name'] = titleName;
454 58496 argiro.kok
    if(!researchResult['name']) {
455
      researchResult['name'] = "[no title available]";
456
    }
457 58275 k.triantaf
    if (relation.hasOwnProperty("dateofacceptance")) {
458
      var date: string = ((Array.isArray(relation.dateofacceptance)) ? (relation.dateofacceptance[0]) : (relation.dateofacceptance)) + ""; // transform to string in case it is an integer
459
      researchResult['date'] = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
460 52606 konstantin
    }
461 50169 argiro.kok
    //researchResult['date'] = relation.dateofacceptance.substring(0,4);;
462 58275 k.triantaf
    researchResult['percentage'] = Math.round(relation[percentageName] * 100);
463 50169 argiro.kok
    return researchResult;
464
  }
465 58275 k.triantaf
466
  sortByPercentage(results: RelationResult[]): RelationResult[] {
467
    if (results) {
468
      return results.sort(function (a, b) {
469
        return b["percentage"] - a["percentage"]
470
      });
471 52115 konstantin
    }
472
    return results;
473
  }
474 58275 k.triantaf
475 50169 argiro.kok
  // publication & dataset landing : for identifiers
476
  parseIdentifiers(pid: any): Map<string, string[]> {
477
    let identifiers = new Map<string, string[]>();
478 58275 k.triantaf
479 59087 konstantin
    if (pid.hasOwnProperty("classid") && pid['classid'] != "") {
480
      if (pid.classid == "doi" || pid.classid == "pmc" || pid.classid == "handle" || pid.classid == "pmid") {
481
        if (!identifiers.has(pid.classid)) {
482
          identifiers.set(pid.classid, new Array<string>());
483 50169 argiro.kok
        }
484 58275 k.triantaf
485 59087 konstantin
        identifiers.get(pid.classid).push(pid.content);
486 50169 argiro.kok
      }
487
    } else {
488 58275 k.triantaf
      for (let i = 0; i < pid.length; i++) {
489 59087 konstantin
        if (pid[i].classid == "doi" || pid[i].classid == "pmc" || pid[i].classid == "handle" || pid[i].classid == "pmid") {
490
          if (!identifiers.has(pid[i].classid)) {
491
            identifiers.set(pid[i].classid, new Array<string>());
492 50169 argiro.kok
          }
493 59087 konstantin
          identifiers.get(pid[i].classid).push(pid[i].content);
494 50169 argiro.kok
        }
495
      }
496
    }
497
    return identifiers;
498
  }
499 58275 k.triantaf
500 50169 argiro.kok
  // publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
501
  parseAllSubjects(_subjects: any): [string[], Map<string, string[]>, Map<string, string[]>] {
502
    let subjects: string[];
503
    let otherSubjects: Map<string, string[]>;
504
    let classifiedSubjects: Map<string, string[]>;
505 58275 k.triantaf
506 50169 argiro.kok
    let subject;
507
    let length = Array.isArray(_subjects) ? _subjects.length : 1;
508 58275 k.triantaf
509
    for (let i = 0; i < length; i++) {
510 50169 argiro.kok
      subject = Array.isArray(_subjects) ? _subjects[i] : _subjects;
511 58275 k.triantaf
      if (subject.classid != "") {
512
        if (subject.inferred && subject.inferred == true) {
513
          if (classifiedSubjects == undefined) {
514 50169 argiro.kok
            classifiedSubjects = new Map<string, string[]>();
515
          }
516 58275 k.triantaf
517
          if (!classifiedSubjects.has(subject.classname)) {
518 50169 argiro.kok
            classifiedSubjects.set(subject.classname, new Array<string>());
519
          }
520 58275 k.triantaf
521 50169 argiro.kok
          classifiedSubjects.get(subject.classname).push(subject.content);
522
        } else {
523 58275 k.triantaf
          if (subject.classid == "keyword") {
524
            if (subjects == undefined) {
525 50169 argiro.kok
              subjects = new Array<string>();
526
            }
527 58275 k.triantaf
528 50169 argiro.kok
            subjects.push(subject.content);
529
          } else {
530 58275 k.triantaf
            if (otherSubjects == undefined) {
531 50169 argiro.kok
              otherSubjects = new Map<string, string[]>();
532
            }
533 58275 k.triantaf
534
            if (!otherSubjects.has(subject.classname)) {
535 50169 argiro.kok
              otherSubjects.set(subject.classname, new Array<string>());
536
            }
537
            otherSubjects.get(subject.classname).push(subject.content);
538
          }
539
        }
540
      }
541
    }
542
    return [subjects, otherSubjects, classifiedSubjects];
543
  }
544 58275 k.triantaf
545
  parseContexts(_contexts: any): {
546 60780 konstantin
    "labelContext": string, "idContext": string,
547
    "labelCategory": string, "idCategory": string,
548
    "labelConcept": string, "idConcept": string, inline: boolean
549 58275 k.triantaf
  }[] {
550
    let contexts = new Array<{
551 60780 konstantin
      "labelContext": string, "idContext": string,
552
      "labelCategory": string, "idCategory": string,
553
      "labelConcept": string, "idConcept": string, inline: boolean
554 58275 k.triantaf
    }>();
555
556 50169 argiro.kok
    let position = 0;
557
    let labels = "";
558
    let context;
559
    let length = Array.isArray(_contexts) ? _contexts.length : 1;
560 58275 k.triantaf
    for (let i = 0; i < length; i++) {
561 50169 argiro.kok
      context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
562 58275 k.triantaf
563
      if (context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
564
        if (context.hasOwnProperty("category")) {
565 56937 konstantin
          let category;
566
          let length2 = Array.isArray(context['category']) ? context['category'].length : 1;
567
          for (let z = 0; z < length2; z++) {
568
            category = Array.isArray(context['category']) ? context['category'][z] : context['category'];
569
            if (category.hasOwnProperty("concept")) {
570
              let categoryConcept;
571
              let length1 = Array.isArray(category['concept']) ? category['concept'].length : 1;
572
              for (let j = 0; j < length1; j++) {
573
                categoryConcept = Array.isArray(category['concept']) ? category['concept'][j] : category['concept'];
574 58275 k.triantaf
575 60780 konstantin
                contexts[position] = {"labelContext": "", "idContext": "",
576
                                      "labelCategory": "", "idCategory": "",
577
                                      "labelConcept": "", "idConcept": "", inline: false};
578 56937 konstantin
                contexts[position]['labelContext'] = context.label;
579 60780 konstantin
                contexts[position]['idContext'] = context.id;
580 56937 konstantin
                contexts[position]['labelCategory'] = category.label;
581 60780 konstantin
                contexts[position]['idCategory'] = category.id;
582 56937 konstantin
                contexts[position]['labelConcept'] = categoryConcept.label;
583 60780 konstantin
                contexts[position]['idConcept'] = categoryConcept.id;
584
585 56937 konstantin
                position++;
586
              }
587
            } else {
588 60780 konstantin
              contexts[position] = {"labelContext": "", "idContext": "",
589
                                    "labelCategory": "",  "idCategory": "",
590
                                    "labelConcept": "", "idConcept": "", inline: false};
591 50169 argiro.kok
              contexts[position]['labelContext'] = context.label;
592 60780 konstantin
              contexts[position]['idContext'] = context.id;
593 56937 konstantin
              contexts[position]['labelCategory'] = category.label;
594 60780 konstantin
              contexts[position]['idCategory'] = category.id;
595 56937 konstantin
              contexts[position]['labelConcept'] = null;
596 60780 konstantin
              contexts[position]['idConcept'] = null;
597 50169 argiro.kok
              position++;
598
            }
599
          }
600 57082 konstantin
        } else {
601 60780 konstantin
          contexts[position] = {"labelContext": "", "idContext": "",
602
            "labelCategory": "",  "idCategory": "",
603
            "labelConcept": "", "idConcept": "", inline: false};
604 57082 konstantin
          contexts[position]['labelContext'] = context.label;
605 60780 konstantin
          contexts[position]['idContext'] = context.id;
606 57082 konstantin
          contexts[position]['labelCategory'] = null;
607 60780 konstantin
          contexts[position]['idCategory'] = null;
608 57082 konstantin
          contexts[position]['labelConcept'] = null;
609 60780 konstantin
          contexts[position]['idConcept'] = null;
610 57082 konstantin
          contexts[position]['new'] = false;
611
          position++;
612 50169 argiro.kok
        }
613
      }
614
    }
615
    return contexts;
616
  }
617 60783 argiro.kok
  public static getEnermapsConceptId(contexts: any): string{
618 60814 argiro.kok
    // let enermapsconcepts = contexts.filter(c=> {return c.idCategory == "enermaps::selection" && c.idConcept});
619
    // return enermapsconcepts && enermapsconcepts.length > 0?enermapsconcepts[0].idConcept.split("enermaps::selection::")[1]:null;
620
    return "hotmaps_heat_tot_curr_density"
621 60783 argiro.kok
  }
622 50169 argiro.kok
  parseTypes(types: string[], uniqueTypes: Set<string>, instance: any) {
623 59223 argiro.kok
    if (instance && instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
624 58275 k.triantaf
      if (!uniqueTypes.has(instance['instancetype'].classname)) {
625 50169 argiro.kok
        types.push(instance['instancetype'].classname);
626
        uniqueTypes.add(instance['instancetype'].classname);
627
      }
628
    }
629
  }
630 58275 k.triantaf
631 50728 konstantin
  parseLanguages(_languages: any) {
632
    var languages = new Array<string>();
633 60780 konstantin
634 58275 k.triantaf
    if (!Array.isArray(_languages)) {
635
      if (_languages.classname != "Undetermined" && _languages.classname) {
636 50728 konstantin
        languages.push(_languages.classname);
637
      }
638
    } else {
639 58275 k.triantaf
      for (let i = 0; i < _languages.length; i++) {
640
        if (_languages[i].classname != "Undetermined" && _languages[i].classname) {
641 50728 konstantin
          languages.push(_languages[i].classname);
642
        }
643
      }
644
    }
645
    return languages;
646
  }
647 58275 k.triantaf
648 52606 konstantin
  parseCountries(_countries: any) {
649
    var countries = new Array<string>();
650 58275 k.triantaf
651
    if (!Array.isArray(_countries)) {
652
      if (_countries.classname != "Undetermined" && _countries.classname) {
653 52606 konstantin
        countries.push(_countries.classname);
654
      }
655
    } else {
656 58275 k.triantaf
      for (let i = 0; i < countries.length; i++) {
657
        if (_countries[i].classname != "Undetermined" && _countries[i].classname) {
658 52606 konstantin
          countries.push(_countries[i].classname);
659
        }
660
      }
661
    }
662
    return countries;
663
  }
664 58275 k.triantaf
665 52606 konstantin
  parseProgrammingLanguages(_pLanguages) {
666
    var pLanguages = new Array<string>();
667 58275 k.triantaf
668
    if (!Array.isArray(_pLanguages)) {
669
      if (_pLanguages.classname != "Undetermined" && _pLanguages.classname) {
670 52606 konstantin
        pLanguages.push(_pLanguages.classname);
671
      }
672
    } else {
673 58275 k.triantaf
      for (let i = 0; i < _pLanguages.length; i++) {
674
        if (_pLanguages[i].classname != "Undetermined" && _pLanguages[i].classname) {
675 52606 konstantin
          pLanguages.push(_pLanguages[i].classname);
676
        }
677
      }
678
    }
679
    return pLanguages;
680
  }
681 58275 k.triantaf
682 58288 k.triantaf
  parseReferences(citations: any): Reference[] {
683
    let references: Reference[] = [];
684
    citations = Array.isArray(citations) ? citations : [citations];
685
    citations.forEach(citation => {
686
      let reference: Reference = {name: null, ids: []};
687
      if(citation.rawText) {
688
        reference.name = citation.rawText;
689 54905 konstantin
      }
690 58288 k.triantaf
      if(citation.id) {
691
        let ids: any[] = Array.isArray(citation.id) ? citation.id : [citation.id];
692
        ids.forEach(id => {
693
          reference.ids.push({
694
            type: id.type,
695
            value: id.value,
696
            trust: id.confidenceLevel
697
          });
698
        });
699
      }
700
      references[citation.position - 1] = reference;
701
    });
702 54905 konstantin
    return references;
703
  }
704 59293 argiro.kok
  static parseRelCanonicalId(record, type){
705
    try{
706
      if(record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"] && record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
707
        for(let child of record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
708
          return child["objidentifier"];
709
        }
710
      }
711
    }catch(e){
712
      // console.error(e);
713
    }
714
    return  record["result"]["header"]["dri:objIdentifier"];
715
716
  }
717 50169 argiro.kok
}