Project

General

Profile

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