Project

General

Profile

1
import {HostedByCollectedFrom, Journal, Project, RelationResult} from "../../utils/result-preview/result-preview";
2
import {Reference} from "../../utils/entities/resultLandingInfo";
3

    
4
export class ParsingFunctions {
5
  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
  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
    }
20
    
21
    let fundedByProject: Project = {
22
      "id": "", "acronym": "", "title": "",
23
      "funderShortname": "", "funderName": "",
24
      "funding": "", "code": "", "provenanceAction": "", "validated": false
25
    };
26
    
27
    if (relation.title != 'unidentified') {
28
      fundedByProject['id'] = relation['to'].content;
29
      fundedByProject['acronym'] = relation.acronym;
30
      fundedByProject['title'] = relation.title;
31
      fundedByProject['code'] = relation.code;
32
      if(relation.validated && relation.validated.date) {
33
        fundedByProject['validated'] = true;
34
      }
35

    
36
      if (provenanceActionVocabulary != null && relation.provenanceaction in provenanceActionVocabulary) {
37
        fundedByProject['provenanceAction'] = provenanceActionVocabulary[relation.provenanceaction];
38
      }
39
    } else {
40
      fundedByProject['id'] = "";
41
      fundedByProject['acronym'] = "";
42
      fundedByProject['title'] = "";
43
      fundedByProject['code'] = "";
44
      fundedByProject['provenanceAction'] = "";
45
    }
46
    
47
    if (relation.hasOwnProperty("funding")) {
48
      let funding: { "funderName": string, "funderShortname": string, "stream": string };
49
      funding = this.parseFundingTrees(relation.funding);
50
      
51
      if (funding.funderName) {
52
        fundedByProject['funderName'] = funding.funderName;
53
      }
54
      if (funding.funderShortname) {
55
        fundedByProject['funderShortname'] = funding.funderShortname;
56
      }
57
      if (funding.stream) {
58
        fundedByProject['funding'] = funding.stream;
59
      }
60
    }
61
    fundedByProjects.push(fundedByProject);
62
    return fundedByProjects;
63
  }
64
  
65
  // publication & research data : for fundedByProjects | project landing : for funding
66
  public parseFundingTrees(fundingTree: any): { "funderName": string, "funderShortname": string, "stream": string } {
67
    let funding: { "funderName": string, "funderShortname": string, "stream": string } = {
68
      "funderName": "",
69
      "funderShortname": "",
70
      "stream": ""
71
    };
72
    let length = Array.isArray(fundingTree) ? fundingTree.length : 1;
73
    
74
    for (let i = 0; i < length; i++) {
75
      let fundingData = Array.isArray(fundingTree) ? fundingTree[i] : fundingTree;
76
      
77
      if (fundingData.hasOwnProperty("funder")) {
78
        funding.funderShortname = fundingData['funder'].shortname;
79
        funding.funderName = fundingData['funder'].name;
80
      }
81
      
82
      funding.stream = this.addFundingLevel0(fundingData, funding.stream);
83
      
84
      funding.stream = this.addFundingLevel1(fundingData, funding.stream);
85
      
86
      funding.stream = this.addFundingLevel2(fundingData, funding.stream);
87
    }
88
    return funding;
89
  }
90
  
91
  addFundingLevel0(parent: string, fundingStream: string): string {
92
    if (parent.hasOwnProperty("funding_level_0")) {
93
      let level0 = parent['funding_level_0'];
94
      
95
      fundingStream += (fundingStream) ? " ; " : "";
96
      fundingStream += level0.name;
97
    }
98
    return fundingStream;
99
  }
100
  
101
  addFundingLevel1(parent: string, fundingStream: string): string {
102
    if (parent.hasOwnProperty("funding_level_1")) {
103
      let level1 = parent['funding_level_1'];
104
      
105
      // For projects' parsing
106
      if (level1.hasOwnProperty("parent")) {
107
        fundingStream = this.addFundingLevel0(level1.parent, fundingStream);
108
      }
109
      
110
      fundingStream += (fundingStream) ? " | " : "";
111
      fundingStream += level1.name;
112
    }
113
    return fundingStream;
114
  }
115
  
116
  addFundingLevel2(parent: string, fundingStream: string): string {
117
    if (parent.hasOwnProperty("funding_level_2")) {
118
      let level2 = parent['funding_level_2'];
119
      
120
      // For projects' parsing
121
      if (level2.hasOwnProperty("parent")) {
122
        fundingStream = this.addFundingLevel1(level2.parent, fundingStream);
123
      }
124
      
125
      fundingStream += (fundingStream) ? " | " : "";
126
      fundingStream += level2.name;
127
    }
128
    return fundingStream;
129
  }
130
  
131
  // publication & dataset landing : for collectedFrom
132
  parseCollectedFrom(collectedFrom: { "name": string, "id": string }[],
133
                     _collectedFrom: any) {
134
    let length: number = collectedFrom.length;
135
    collectedFrom[length] = {"name": "", "id": ""};
136
    collectedFrom[length]['name'] = _collectedFrom.name;
137
    collectedFrom[length]['id'] = _collectedFrom.id;
138
  }
139
  
140
  // publication & dataset landing : for downloadFrom
141
  addPublisherToHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[],
142
                                       publisher: string, journal: Journal,
143
                                       identifiers: Map<string, string[]>/*, title: { "name": string, "url": string, "accessMode": string}*/) {
144
    if (publisher && identifiers != null && identifiers.has('doi')) {
145
      if (hostedBy_collectedFrom == null) {
146
        hostedBy_collectedFrom = [];
147
      }
148
      let available: HostedByCollectedFrom = {
149
        downloadName: "",
150
        downloadUrl: null,
151
        collectedName: "",
152
        collectedId: "",
153
        accessMode: null,
154
        bestAccessMode: null,
155
        type: "",
156
        year: "",
157
        icon: ""
158
      };
159
      
160
      if (journal && journal.journal) {
161
        available.downloadName = publisher + "/ " + journal['journal'];
162
      } else {
163
        available.downloadName = publisher;
164
      }
165
      
166
      let url = "https://dx.doi.org/" + identifiers.get("doi")[0];
167
      
168
      available.downloadUrl = new Array<string>();
169
      available.accessMode = new Array<string>();
170
      
171
      available.downloadUrl.push(url);
172

    
173
      available.icon = this.unknown;
174
      /*
175
            if(title != undefined && title['url'] == "") {
176
              title['url'] = url;
177
            }
178
      */
179
      hostedBy_collectedFrom.push(available);
180
    }
181
    return hostedBy_collectedFrom;
182
  }
183
  
184
  // publication & dataset landing : for downloadFrom
185
  parseDownloadFrom(downloadFrom: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, url: string) {
186
    let key: string = instance['hostedby'].name;
187
    
188
    if (key) {
189
      this.addUrlAndAccessMode(downloadFrom, instance, key, url);
190
    }
191
  }
192
  
193
  // publication & dataset landing : for publishedIn
194
  parsePublishedIn(publishedIn: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, result: any, url: string, counter: number): number {
195
    if (result != null && result.hasOwnProperty("source")) {
196
      let key: string;
197
      if (Array.isArray(result.source)) {
198
        if (counter == result.source.length) {
199
          counter--;
200
        }
201
        key = result['source'][counter];
202
      } else {
203
        key = result['source'];
204
      }
205
      
206
      if (key) {
207
        this.addUrlAndAccessMode(publishedIn, instance, key, url);
208
        counter++;
209
      }
210
    }
211
    return counter;
212
  }
213
  
214
  // publication & dataset landing : for downloadFrom and publishedIn
215
  addUrlAndAccessMode(mapStructure: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, key: string, url: string) {
216
    if (!mapStructure.has(key)) {
217
      mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
218
    }
219
    
220
    if (mapStructure.get(key)['url'] == null) {
221
      mapStructure.get(key)['url'] = new Array<string>();
222
    }
223
    
224
    if (url) {
225
      mapStructure.get(key)['url'].push(url);
226
    }
227
    
228
    if (mapStructure.get(key)['accessMode'] == null) {
229
      mapStructure.get(key)['accessMode'] = new Array<string>();
230
    }
231
    
232
    if (instance.hasOwnProperty("accessright")) {
233
      if (url) {
234
        mapStructure.get(key)['accessMode'].push(instance['accessright'].classname);
235
      }
236
      
237
      if (this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) {
238
        mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classname;
239
      }
240
    } else if (url) {
241
      mapStructure.get(key)['accessMode'].push("");
242
    }
243
  }
244
  
245
  
246
  parseHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[],
247
                              instance: any, data: any, url: string, counter: number/*,
248
                              title: { "name": string, "url": string, "accessMode": string}*/, accessMode: string): number {
249
    let available: HostedByCollectedFrom = {
250
      "downloadName": "",
251
      "downloadUrl": null,
252
      "collectedName": "",
253
      "collectedId": "",
254
      "accessMode": null,
255
      "bestAccessMode": null,
256
      "type": "",
257
      "year": "",
258
      "icon": ""
259
    };
260
    
261
    if (instance['hostedby'].name && instance['hostedby'].name != "other resources" && instance['hostedby'].name != "Unknown Repository") {
262
      available.downloadName = instance['hostedby'].name;
263
    } else {
264
    //   if (data != null && data.hasOwnProperty("source")) {
265
    //     let downloadName: string;
266
    //     if (Array.isArray(data.source)) {
267
    //
268
    //       if (counter == data.source.length) {
269
    //         counter--;
270
    //       }
271
    //       downloadName = data['source'][counter];
272
    //     } else {
273
    //       downloadName = data['source'];
274
    //     }
275
    //     if (downloadName) {
276
    //       counter++;
277
    //       available.downloadName = downloadName;
278
    //     }
279
    //   }
280
    //
281
    // }
282
    //
283
    // if(!available.downloadName) {
284
      available.downloadName = url.substring(0, 30) + '...';  // substring(from, to);
285
    }
286

    
287
    if (available.downloadName) {
288
      if (instance.hasOwnProperty("collectedfrom")) {
289
        available.collectedId = instance['collectedfrom'].id;
290
        available.collectedName = instance['collectedfrom'].name;
291
      }
292
      
293
      if (instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
294
        available.type = instance['instancetype'].classname;
295
      }
296
      
297
      if (instance.hasOwnProperty("dateofacceptance")) {
298
        var date: string = (instance.dateofacceptance) + ""; // transform to string in case it is an integer
299
        available.year = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
300
      }
301
      
302
      available.accessMode = new Array<string>();
303
      available.downloadUrl = new Array<string>();
304
      available['downloadUrl'].push(url);
305
      if (instance.hasOwnProperty("accessright")) {
306
        if (url) {
307
          available['accessMode'].push(instance['accessright'].classname);
308
        }
309
        
310
        if (this.changeBestAccessMode(available.bestAccessMode, instance['accessright'])) {
311
          available.bestAccessMode = instance['accessright'].classname;
312
          /*
313
                     if(title != undefined) {
314
                       if(this.changeBestAccessMode(title['accessMode'], instance['accessright'])) {
315
                         title['accessMode'] = instance['accessright'].classid;
316
                         title['url'] = url;
317
                       }
318
                     }
319
          */
320
          if (this.changeBestAccessMode(accessMode, instance['accessright'])) {
321
            accessMode = instance['accessright'].classname;
322
          }
323
        }
324
        /*
325
                 if(title != undefined) {
326
                   if(!title['url']) {
327
                     title['url'] = url;
328
                   }
329
                 }
330
        */
331
      } else if (url) {
332
        available['accessMode'].push("");
333
      }
334

    
335
      if (available.bestAccessMode) {
336
        if (available.bestAccessMode.toLowerCase().indexOf('open') !== -1) {
337
          available.icon = this.open;
338
        } else if (available.bestAccessMode.toLowerCase().indexOf('not available') !== -1) {
339
          available.icon = this.unknown;
340
        } else {
341
          available.icon = this.closed;
342
        }
343
      } else {
344
        available.icon = this.unknown;
345
      }
346
      
347
      hostedBy_collectedFrom.push(available);
348
    }
349
    
350
    return counter;
351
  }
352
  
353
  // publication & dataset landing : for downloadFrom and publishedIn
354
  changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean {
355
    if (!accessMode) {
356
      return false;
357
    }
358
    accessMode = accessMode.classid;
359
    
360
    switch (currentAccessMode) {
361
      case null:
362
        if (accessMode != "UNKNOWN") {
363
          return true;
364
        }
365
        return false;
366
      case "CLOSED":
367
        if (accessMode == "OPEN" ||
368
          accessMode == "OPEN SOURCE" ||
369
          accessMode == "EMBARGO" ||
370
          accessMode == "RESTRICTED") {
371
          return true;
372
        }
373
        return false;
374
      case "RESTRICTED":
375
        if (accessMode == "OPEN" ||
376
          accessMode == "OPEN SOURCE" ||
377
          accessMode == "EMBARGO") {
378
          return true;
379
        }
380
        return false;
381
      case "EMBARGO":
382
        if (accessMode == "OPEN" ||
383
          accessMode == "OPEN SOURCE") {
384
          return true;
385
        }
386
        return false;
387
      case "OPEN SOURCE":
388
        if (accessMode == "OPEN") {
389
          return true;
390
        }
391
        return false;
392
    }
393
    return false;
394
  }
395
  
396
  // publication & dataset & software & orp landing : for relatedResearchResults
397
  parseRelatedResearchResults(relatedResearchResults: RelationResult[], relation: any, provenanceAction: string):
398
    RelationResult[] {
399
    if (relatedResearchResults == undefined) {
400
      relatedResearchResults = []
401
    }
402
    relatedResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust", provenanceAction));
403
    return relatedResearchResults;
404
  }
405
  
406
  // publication & dataset & software & orp landing : for supplementaryResearchResults
407
  parseSupplementaryResearchResults(supplementaryResearchResults: RelationResult[], relation: any): RelationResult[] {
408
    if (supplementaryResearchResults == undefined) {
409
      supplementaryResearchResults = [];
410
    }
411
    supplementaryResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
412
    return supplementaryResearchResults;
413
  }
414
  
415
  // publication & dataset & software & orp landing : for supplementedByResearchResults
416
  parseSupplementedByResearchResults(supplementedByResearchResults: RelationResult[], relation: any): RelationResult[] {
417
    if (supplementedByResearchResults == undefined) {
418
      supplementedByResearchResults = [];
419
    }
420
    supplementedByResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
421
    return supplementedByResearchResults;
422
  }
423
  
424
  // publication & dataset & software & orp landing : for similarResearchResults
425
  parseSimilarResearchResults(similarResearchResults: RelationResult[], relation: any): RelationResult[] {
426
    if (similarResearchResults == undefined) {
427
      similarResearchResults = [];
428
    }
429
    similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "similarity"));
430
    return similarResearchResults;
431
  }
432
  
433
  // publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults
434
  parseRelatedOrSimilarResearchResult(relation: any, percentageName: string, provenanceAction: string = null): RelationResult {
435
    let researchResult: RelationResult = {
436
      name: "",
437
      id: "",
438
      date: "",
439
      percentage: null,
440
      class: "",
441
      provenanceAction: provenanceAction
442
    };
443
    if(relation['resulttype']) {
444
      if (relation['resulttype'].classname == "publication") {
445
        researchResult['class'] = "publication";
446
      } else if (relation['resulttype'].classname == "dataset") {
447
        researchResult['class'] = "dataset";
448
      } else if (relation['resulttype'].classname == "software") {
449
        researchResult['class'] = "software";
450
      } else if (relation['resulttype'].classname == "other") {
451
        researchResult['class'] = "other";
452
      }
453
    }
454
    researchResult['id'] = relation['to'].content;
455
    let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : (relation['title']?relation['title'].content:null);
456
    researchResult['name'] = titleName;
457
    if(!researchResult['name']) {
458
      researchResult['name'] = "[no title available]";
459
    }
460
    if (relation.hasOwnProperty("dateofacceptance")) {
461
      var date: string = ((Array.isArray(relation.dateofacceptance)) ? (relation.dateofacceptance[0]) : (relation.dateofacceptance)) + ""; // transform to string in case it is an integer
462
      researchResult['date'] = (date && (date).indexOf('-') !== -1) ? date.split('-')[0] : date;
463
    }
464
    //researchResult['date'] = relation.dateofacceptance.substring(0,4);;
465
    researchResult['percentage'] = Math.round(relation[percentageName] * 100);
466
    return researchResult;
467
  }
468
  
469
  sortByPercentage(results: RelationResult[]): RelationResult[] {
470
    if (results) {
471
      return results.sort(function (a, b) {
472
        return b["percentage"] - a["percentage"]
473
      });
474
    }
475
    return results;
476
  }
477
  
478
  // publication & dataset landing : for identifiers
479
  parseIdentifiers(pid: any): Map<string, string[]> {
480
    let identifiers = new Map<string, string[]>();
481
    
482
    if (pid.hasOwnProperty("classid") && pid['classid'] != "") {
483
      if (pid.classid == "doi" || pid.classid == "pmc" || pid.classid == "handle" || pid.classid == "pmid") {
484
        if (!identifiers.has(pid.classid)) {
485
          identifiers.set(pid.classid, new Array<string>());
486
        }
487
        
488
        identifiers.get(pid.classid).push(pid.content);
489
      }
490
    } else {
491
      for (let i = 0; i < pid.length; i++) {
492
        if (pid[i].classid == "doi" || pid[i].classid == "pmc" || pid[i].classid == "handle" || pid[i].classid == "pmid") {
493
          if (!identifiers.has(pid[i].classid)) {
494
            identifiers.set(pid[i].classid, new Array<string>());
495
          }
496
          identifiers.get(pid[i].classid).push(pid[i].content);
497
        }
498
      }
499
    }
500
    return identifiers;
501
  }
502
  
503
  // publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
504
  parseAllSubjects(_subjects: any): [string[], Map<string, string[]>, Map<string, string[]>] {
505
    let subjects: string[];
506
    let otherSubjects: Map<string, string[]>;
507
    let classifiedSubjects: Map<string, string[]>;
508
    
509
    let subject;
510
    let length = Array.isArray(_subjects) ? _subjects.length : 1;
511
    
512
    for (let i = 0; i < length; i++) {
513
      subject = Array.isArray(_subjects) ? _subjects[i] : _subjects;
514
      if (subject.classid != "") {
515
        if (subject.inferred && subject.inferred == true) {
516
          if (classifiedSubjects == undefined) {
517
            classifiedSubjects = new Map<string, string[]>();
518
          }
519
          
520
          if (!classifiedSubjects.has(subject.classname)) {
521
            classifiedSubjects.set(subject.classname, new Array<string>());
522
          }
523
          
524
          classifiedSubjects.get(subject.classname).push(subject.content);
525
        } else {
526
          if (subject.classid == "keyword") {
527
            if (subjects == undefined) {
528
              subjects = new Array<string>();
529
            }
530
            
531
            subjects.push(subject.content);
532
          } else {
533
            if (otherSubjects == undefined) {
534
              otherSubjects = new Map<string, string[]>();
535
            }
536
            
537
            if (!otherSubjects.has(subject.classname)) {
538
              otherSubjects.set(subject.classname, new Array<string>());
539
            }
540
            otherSubjects.get(subject.classname).push(subject.content);
541
          }
542
        }
543
      }
544
    }
545
    return [subjects, otherSubjects, classifiedSubjects];
546
  }
547
  
548
  parseContexts(_contexts: any): {
549
    "labelContext": string, "idContext": string,
550
    "labelCategory": string, "idCategory": string,
551
    "labelConcept": string, "idConcept": string
552
  }[] {
553
    let contexts = new Array<{
554
      "labelContext": string, "idContext": string,
555
      "labelCategory": string, "idCategory": string,
556
      "labelConcept": string, "idConcept": string
557
    }>();
558
    
559
    let position = 0;
560
    let labels = "";
561
    let context;
562
    let length = Array.isArray(_contexts) ? _contexts.length : 1;
563
    for (let i = 0; i < length; i++) {
564
      context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
565
      
566
      if (context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
567
        if (context.hasOwnProperty("category")) {
568
          let category;
569
          let length2 = Array.isArray(context['category']) ? context['category'].length : 1;
570
          for (let z = 0; z < length2; z++) {
571
            category = Array.isArray(context['category']) ? context['category'][z] : context['category'];
572
            if (category.hasOwnProperty("concept")) {
573
              let categoryConcept;
574
              let length1 = Array.isArray(category['concept']) ? category['concept'].length : 1;
575
              for (let j = 0; j < length1; j++) {
576
                categoryConcept = Array.isArray(category['concept']) ? category['concept'][j] : category['concept'];
577
                
578
                contexts[position] = {"labelContext": "", "idContext": "",
579
                                      "labelCategory": "", "idCategory": "",
580
                                      "labelConcept": "", "idConcept": ""};
581
                contexts[position]['labelContext'] = context.label;
582
                contexts[position]['idContext'] = context.id;
583
                contexts[position]['labelCategory'] = category.label;
584
                contexts[position]['idCategory'] = category.id;
585
                contexts[position]['labelConcept'] = categoryConcept.label;
586
                contexts[position]['idConcept'] = categoryConcept.id;
587

    
588
                position++;
589
              }
590
            } else {
591
              contexts[position] = {"labelContext": "", "idContext": "",
592
                                    "labelCategory": "",  "idCategory": "",
593
                                    "labelConcept": "", "idConcept": ""};
594
              contexts[position]['labelContext'] = context.label;
595
              contexts[position]['idContext'] = context.id;
596
              contexts[position]['labelCategory'] = category.label;
597
              contexts[position]['idCategory'] = category.id;
598
              contexts[position]['labelConcept'] = null;
599
              contexts[position]['idConcept'] = null;
600
              position++;
601
            }
602
          }
603
        } else {
604
          contexts[position] = {"labelContext": "", "idContext": "",
605
            "labelCategory": "",  "idCategory": "",
606
            "labelConcept": "", "idConcept": ""};
607
          contexts[position]['labelContext'] = context.label;
608
          contexts[position]['idContext'] = context.id;
609
          contexts[position]['labelCategory'] = null;
610
          contexts[position]['idCategory'] = null;
611
          contexts[position]['labelConcept'] = null;
612
          contexts[position]['idConcept'] = null;
613
          contexts[position]['new'] = false;
614
          position++;
615
        }
616
      }
617
    }
618
    return contexts;
619
  }
620
  public static getEnermapsConceptId(contexts: any): string{
621
    // let enermapsconcepts = contexts.filter(c=> {return c.idCategory == "enermaps::selection" && c.idConcept});
622
    // return enermapsconcepts && enermapsconcepts.length > 0?enermapsconcepts[0].idConcept.split("enermaps::selection::")[1]:null;
623
    return "hotmaps_heat_tot_curr_density"
624
  }
625
  parseTypes(types: string[], uniqueTypes: Set<string>, instance: any) {
626
    if (instance && instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
627
      if (!uniqueTypes.has(instance['instancetype'].classname)) {
628
        types.push(instance['instancetype'].classname);
629
        uniqueTypes.add(instance['instancetype'].classname);
630
      }
631
    }
632
  }
633
  
634
  parseLanguages(_languages: any) {
635
    var languages = new Array<string>();
636

    
637
    if (!Array.isArray(_languages)) {
638
      if (_languages.classname != "Undetermined" && _languages.classname) {
639
        languages.push(_languages.classname);
640
      }
641
    } else {
642
      for (let i = 0; i < _languages.length; i++) {
643
        if (_languages[i].classname != "Undetermined" && _languages[i].classname) {
644
          languages.push(_languages[i].classname);
645
        }
646
      }
647
    }
648
    return languages;
649
  }
650
  
651
  parseCountries(_countries: any) {
652
    var countries = new Array<string>();
653
    
654
    if (!Array.isArray(_countries)) {
655
      if (_countries.classname != "Undetermined" && _countries.classname) {
656
        countries.push(_countries.classname);
657
      }
658
    } else {
659
      for (let i = 0; i < countries.length; i++) {
660
        if (_countries[i].classname != "Undetermined" && _countries[i].classname) {
661
          countries.push(_countries[i].classname);
662
        }
663
      }
664
    }
665
    return countries;
666
  }
667
  
668
  parseProgrammingLanguages(_pLanguages) {
669
    var pLanguages = new Array<string>();
670
    
671
    if (!Array.isArray(_pLanguages)) {
672
      if (_pLanguages.classname != "Undetermined" && _pLanguages.classname) {
673
        pLanguages.push(_pLanguages.classname);
674
      }
675
    } else {
676
      for (let i = 0; i < _pLanguages.length; i++) {
677
        if (_pLanguages[i].classname != "Undetermined" && _pLanguages[i].classname) {
678
          pLanguages.push(_pLanguages[i].classname);
679
        }
680
      }
681
    }
682
    return pLanguages;
683
  }
684
  
685
  parseReferences(citations: any): Reference[] {
686
    let references: Reference[] = [];
687
    citations = Array.isArray(citations) ? citations : [citations];
688
    citations.forEach(citation => {
689
      let reference: Reference = {name: null, ids: []};
690
      if(citation.rawText) {
691
        reference.name = citation.rawText;
692
      }
693
      if(citation.id) {
694
        let ids: any[] = Array.isArray(citation.id) ? citation.id : [citation.id];
695
        ids.forEach(id => {
696
          reference.ids.push({
697
            type: id.type,
698
            value: id.value,
699
            trust: id.confidenceLevel
700
          });
701
        });
702
      }
703
      references[citation.position - 1] = reference;
704
    });
705
    return references;
706
  }
707
  static parseRelCanonicalId(record, type){
708
    try{
709
      if(record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"] && record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
710
        for(let child of record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
711
          return child["objidentifier"];
712
        }
713
      }
714
    }catch(e){
715
      // console.error(e);
716
    }
717
    return  record["result"]["header"]["dri:objIdentifier"];
718

    
719
  }
720
}
(5-5/16)