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

    
170
      available.icon = this.unknown;
171
      /*
172
            if(title != undefined && title['url'] == "") {
173
              title['url'] = url;
174
            }
175
      */
176
      hostedBy_collectedFrom.push(available);
177
    }
178
    return hostedBy_collectedFrom;
179
  }
180
  
181
  // publication & dataset landing : for downloadFrom
182
  parseDownloadFrom(downloadFrom: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, url: string) {
183
    let key: string = instance['hostedby'].name;
184
    
185
    if (key) {
186
      this.addUrlAndAccessMode(downloadFrom, instance, key, url);
187
    }
188
  }
189
  
190
  // publication & dataset landing : for publishedIn
191
  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
      let key: string;
194
      if (Array.isArray(result.source)) {
195
        if (counter == result.source.length) {
196
          counter--;
197
        }
198
        key = result['source'][counter];
199
      } else {
200
        key = result['source'];
201
      }
202
      
203
      if (key) {
204
        this.addUrlAndAccessMode(publishedIn, instance, key, url);
205
        counter++;
206
      }
207
    }
208
    return counter;
209
  }
210
  
211
  // publication & dataset landing : for downloadFrom and publishedIn
212
  addUrlAndAccessMode(mapStructure: Map<string, { "url": string[], "accessMode": string[], "bestAccessMode": string }>, instance: any, key: string, url: string) {
213
    if (!mapStructure.has(key)) {
214
      mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
215
    }
216
    
217
    if (mapStructure.get(key)['url'] == null) {
218
      mapStructure.get(key)['url'] = new Array<string>();
219
    }
220
    
221
    if (url) {
222
      mapStructure.get(key)['url'].push(url);
223
    }
224
    
225
    if (mapStructure.get(key)['accessMode'] == null) {
226
      mapStructure.get(key)['accessMode'] = new Array<string>();
227
    }
228
    
229
    if (instance.hasOwnProperty("accessright")) {
230
      if (url) {
231
        mapStructure.get(key)['accessMode'].push(instance['accessright'].classname);
232
      }
233
      
234
      if (this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) {
235
        mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classname;
236
      }
237
    } else if (url) {
238
      mapStructure.get(key)['accessMode'].push("");
239
    }
240
  }
241
  
242
  
243
  parseHostedBy_collectedFrom(hostedBy_collectedFrom: HostedByCollectedFrom[],
244
                              instance: any, data: any, url: string, counter: number/*,
245
                              title: { "name": string, "url": string, "accessMode": string}*/, accessMode: string): number {
246
    let available: HostedByCollectedFrom = {
247
      "downloadName": "",
248
      "downloadUrl": null,
249
      "collectedName": "",
250
      "collectedId": "",
251
      "accessMode": null,
252
      "bestAccessMode": null,
253
      "type": "",
254
      "year": "",
255
      "icon": ""
256
    };
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
    //   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
      available.downloadName = url.substring(0, 30) + '...';  // substring(from, to);
282
    }
283

    
284
    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

    
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
      
344
      hostedBy_collectedFrom.push(available);
345
    }
346
    
347
    return counter;
348
  }
349
  
350
  // publication & dataset landing : for downloadFrom and publishedIn
351
  changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean {
352
    if (!accessMode) {
353
      return false;
354
    }
355
    accessMode = accessMode.classid;
356
    
357
    switch (currentAccessMode) {
358
      case null:
359
        if (accessMode != "UNKNOWN") {
360
          return true;
361
        }
362
        return false;
363
      case "CLOSED":
364
        if (accessMode == "OPEN" ||
365
          accessMode == "OPEN SOURCE" ||
366
          accessMode == "EMBARGO" ||
367
          accessMode == "RESTRICTED") {
368
          return true;
369
        }
370
        return false;
371
      case "RESTRICTED":
372
        if (accessMode == "OPEN" ||
373
          accessMode == "OPEN SOURCE" ||
374
          accessMode == "EMBARGO") {
375
          return true;
376
        }
377
        return false;
378
      case "EMBARGO":
379
        if (accessMode == "OPEN" ||
380
          accessMode == "OPEN SOURCE") {
381
          return true;
382
        }
383
        return false;
384
      case "OPEN SOURCE":
385
        if (accessMode == "OPEN") {
386
          return true;
387
        }
388
        return false;
389
    }
390
    return false;
391
  }
392
  
393
  // publication & dataset & software & orp landing : for relatedResearchResults
394
  parseRelatedResearchResults(relatedResearchResults: RelationResult[], relation: any, provenanceAction: string):
395
    RelationResult[] {
396
    if (relatedResearchResults == undefined) {
397
      relatedResearchResults = []
398
    }
399
    relatedResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust", provenanceAction));
400
    return relatedResearchResults;
401
  }
402
  
403
  // publication & dataset & software & orp landing : for supplementaryResearchResults
404
  parseSupplementaryResearchResults(supplementaryResearchResults: RelationResult[], relation: any): RelationResult[] {
405
    if (supplementaryResearchResults == undefined) {
406
      supplementaryResearchResults = [];
407
    }
408
    supplementaryResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
409
    return supplementaryResearchResults;
410
  }
411
  
412
  // publication & dataset & software & orp landing : for supplementedByResearchResults
413
  parseSupplementedByResearchResults(supplementedByResearchResults: RelationResult[], relation: any): RelationResult[] {
414
    if (supplementedByResearchResults == undefined) {
415
      supplementedByResearchResults = [];
416
    }
417
    supplementedByResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
418
    return supplementedByResearchResults;
419
  }
420
  
421
  // publication & dataset & software & orp landing : for similarResearchResults
422
  parseSimilarResearchResults(similarResearchResults: RelationResult[], relation: any): RelationResult[] {
423
    if (similarResearchResults == undefined) {
424
      similarResearchResults = [];
425
    }
426
    similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "similarity"));
427
    return similarResearchResults;
428
  }
429
  
430
  // publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults
431
  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
    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
    }
451
    researchResult['id'] = relation['to'].content;
452
    let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : (relation['title']?relation['title'].content:null);
453
    researchResult['name'] = titleName;
454
    if(!researchResult['name']) {
455
      researchResult['name'] = "[no title available]";
456
    }
457
    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
    }
461
    //researchResult['date'] = relation.dateofacceptance.substring(0,4);;
462
    researchResult['percentage'] = Math.round(relation[percentageName] * 100);
463
    return researchResult;
464
  }
465
  
466
  sortByPercentage(results: RelationResult[]): RelationResult[] {
467
    if (results) {
468
      return results.sort(function (a, b) {
469
        return b["percentage"] - a["percentage"]
470
      });
471
    }
472
    return results;
473
  }
474
  
475
  // publication & dataset landing : for identifiers
476
  parseIdentifiers(pid: any): Map<string, string[]> {
477
    let identifiers = new Map<string, string[]>();
478
    
479
    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
        }
484
        
485
        identifiers.get(pid.classid).push(pid.content);
486
      }
487
    } else {
488
      for (let i = 0; i < pid.length; i++) {
489
        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
          }
493
          identifiers.get(pid[i].classid).push(pid[i].content);
494
        }
495
      }
496
    }
497
    return identifiers;
498
  }
499
  
500
  // 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
    
506
    let subject;
507
    let length = Array.isArray(_subjects) ? _subjects.length : 1;
508
    
509
    for (let i = 0; i < length; i++) {
510
      subject = Array.isArray(_subjects) ? _subjects[i] : _subjects;
511
      if (subject.classid != "") {
512
        if (subject.inferred && subject.inferred == true) {
513
          if (classifiedSubjects == undefined) {
514
            classifiedSubjects = new Map<string, string[]>();
515
          }
516
          
517
          if (!classifiedSubjects.has(subject.classname)) {
518
            classifiedSubjects.set(subject.classname, new Array<string>());
519
          }
520
          
521
          classifiedSubjects.get(subject.classname).push(subject.content);
522
        } else {
523
          if (subject.classid == "keyword") {
524
            if (subjects == undefined) {
525
              subjects = new Array<string>();
526
            }
527
            
528
            subjects.push(subject.content);
529
          } else {
530
            if (otherSubjects == undefined) {
531
              otherSubjects = new Map<string, string[]>();
532
            }
533
            
534
            if (!otherSubjects.has(subject.classname)) {
535
              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
  
545
  parseContexts(_contexts: any): {
546
    "labelContext": string, "labelCategory": string,
547
    "labelConcept": string, inline: boolean
548
  }[] {
549
    let contexts = new Array<{
550
      "labelContext": string, "labelCategory": string,
551
      "labelConcept": string, inline: boolean
552
    }>();
553
    
554
    let position = 0;
555
    let labels = "";
556
    let context;
557
    let length = Array.isArray(_contexts) ? _contexts.length : 1;
558
    for (let i = 0; i < length; i++) {
559
      context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
560
      
561
      if (context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
562
        if (context.hasOwnProperty("category")) {
563
          let category;
564
          let length2 = Array.isArray(context['category']) ? context['category'].length : 1;
565
          for (let z = 0; z < length2; z++) {
566
            category = Array.isArray(context['category']) ? context['category'][z] : context['category'];
567
            if (category.hasOwnProperty("concept")) {
568
              let categoryConcept;
569
              let length1 = Array.isArray(category['concept']) ? category['concept'].length : 1;
570
              for (let j = 0; j < length1; j++) {
571
                categoryConcept = Array.isArray(category['concept']) ? category['concept'][j] : category['concept'];
572
                
573
                contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
574
                contexts[position]['labelContext'] = context.label;
575
                contexts[position]['labelCategory'] = category.label;
576
                contexts[position]['labelConcept'] = categoryConcept.label;
577
                
578
                position++;
579
              }
580
            } else {
581
              contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
582
              contexts[position]['labelContext'] = context.label;
583
              contexts[position]['labelCategory'] = category.label;
584
              contexts[position]['labelConcept'] = null;
585
              position++;
586
            }
587
          }
588
        } else {
589
          contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
590
          contexts[position]['labelContext'] = context.label;
591
          contexts[position]['labelCategory'] = null;
592
          contexts[position]['labelConcept'] = null;
593
          contexts[position]['new'] = false;
594
          position++;
595
        }
596
      }
597
    }
598
    return contexts;
599
  }
600
  
601
  parseTypes(types: string[], uniqueTypes: Set<string>, instance: any) {
602
    if (instance && instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
603
      if (!uniqueTypes.has(instance['instancetype'].classname)) {
604
        types.push(instance['instancetype'].classname);
605
        uniqueTypes.add(instance['instancetype'].classname);
606
      }
607
    }
608
  }
609
  
610
  parseLanguages(_languages: any) {
611
    var languages = new Array<string>();
612
    
613
    if (!Array.isArray(_languages)) {
614
      if (_languages.classname != "Undetermined" && _languages.classname) {
615
        languages.push(_languages.classname);
616
      }
617
    } else {
618
      for (let i = 0; i < _languages.length; i++) {
619
        if (_languages[i].classname != "Undetermined" && _languages[i].classname) {
620
          languages.push(_languages[i].classname);
621
        }
622
      }
623
    }
624
    return languages;
625
  }
626
  
627
  parseCountries(_countries: any) {
628
    var countries = new Array<string>();
629
    
630
    if (!Array.isArray(_countries)) {
631
      if (_countries.classname != "Undetermined" && _countries.classname) {
632
        countries.push(_countries.classname);
633
      }
634
    } else {
635
      for (let i = 0; i < countries.length; i++) {
636
        if (_countries[i].classname != "Undetermined" && _countries[i].classname) {
637
          countries.push(_countries[i].classname);
638
        }
639
      }
640
    }
641
    return countries;
642
  }
643
  
644
  parseProgrammingLanguages(_pLanguages) {
645
    var pLanguages = new Array<string>();
646
    
647
    if (!Array.isArray(_pLanguages)) {
648
      if (_pLanguages.classname != "Undetermined" && _pLanguages.classname) {
649
        pLanguages.push(_pLanguages.classname);
650
      }
651
    } else {
652
      for (let i = 0; i < _pLanguages.length; i++) {
653
        if (_pLanguages[i].classname != "Undetermined" && _pLanguages[i].classname) {
654
          pLanguages.push(_pLanguages[i].classname);
655
        }
656
      }
657
    }
658
    return pLanguages;
659
  }
660
  
661
  parseReferences(citations: any): Reference[] {
662
    let references: Reference[] = [];
663
    citations = Array.isArray(citations) ? citations : [citations];
664
    citations.forEach(citation => {
665
      let reference: Reference = {name: null, ids: []};
666
      if(citation.rawText) {
667
        reference.name = citation.rawText;
668
      }
669
      if(citation.id) {
670
        let ids: any[] = Array.isArray(citation.id) ? citation.id : [citation.id];
671
        ids.forEach(id => {
672
          reference.ids.push({
673
            type: id.type,
674
            value: id.value,
675
            trust: id.confidenceLevel
676
          });
677
        });
678
      }
679
      references[citation.position - 1] = reference;
680
    });
681
    return references;
682
  }
683
  static parseRelCanonicalId(record, type){
684
    try{
685
      if(record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"] && record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
686
        for(let child of record["result"]["metadata"]["oaf:entity"][("oaf:"+type)]["children"][type]){
687
          return child["objidentifier"];
688
        }
689
      }
690
    }catch(e){
691
      // console.error(e);
692
    }
693
    return  record["result"]["header"]["dri:objIdentifier"];
694

    
695
  }
696
}
(5-5/17)