Project

General

Profile

1

    
2
export class ParsingFunctions {
3

    
4
  constructor () {}
5

    
6
  public ngOnDestroy() {}
7

    
8
  public parseFundingByProjects(fundedByProjects: { "id": string, "acronym": string, "title": string,
9
                                                    "funderShortname": string, "funderName": string,
10
                                                    "funding": string, "code": string,
11
                                                    "provenanceAction": string, "inline": boolean
12
                                                  }[],
13
                                relation: any, projectsProvenanceVocabulary: any):
14
                            { "id": string, "acronym": string, "title": string,
15
                              "funderShortname": string, "funderName": string,
16
                              "funding": string, "code": string,
17
                              "provenanceAction": string, "inline": boolean
18
                            }[] {
19
    if(fundedByProjects == undefined) {
20
      fundedByProjects = new Array<{"id": string, "acronym": string, "title": string,
21
                                    "funderShortname": string, "funderName": string,
22
                                    "funding": string, "code": string,
23
                                    "provenanceAction": string, "inline": boolean
24
                                  }>();
25
    }
26

    
27
    let fundedByProject:  { "id": string, "acronym": string, "title": string,
28
                            "funderShortname": string, "funderName": string,
29
                            "funding": string, "code": string,
30
                            "provenanceAction": string, "inline": boolean
31
                          } = { "id": "", "acronym": "", "title": "",
32
                                "funderShortname": "", "funderName": "",
33
                                "funding": "", "code": "", "provenanceAction": "", "inline": false
34
                          };
35

    
36
    if(relation.title != 'unidentified') {
37
      fundedByProject['id'] = relation['to'].content;
38
      fundedByProject['acronym'] = relation.acronym;
39
      fundedByProject['title'] = relation.title;
40
      fundedByProject['code'] = relation.code;
41

    
42
      if(relation.provenanceaction in projectsProvenanceVocabulary) {
43
        fundedByProject['provenanceAction'] = projectsProvenanceVocabulary[relation.provenanceaction];
44
      }
45
    } else {
46
      fundedByProject['id'] = "";
47
      fundedByProject['acronym'] = "";
48
      fundedByProject['title'] = "";
49
      fundedByProject['code'] = "";
50
      fundedByProject['provenanceAction'] = "";
51
    }
52

    
53
    if(relation.hasOwnProperty("funding")) {
54
      let funding: {"funderName": string, "funderShortname": string, "stream": string};
55
      funding = this.parseFundingTrees(relation.funding);
56

    
57
      if(funding.funderName) {
58
        fundedByProject['funderName'] = funding.funderName;
59
      }
60
      if(funding.funderShortname) {
61
        fundedByProject['funderShortname'] = funding.funderShortname;
62
      }
63
      if(funding.stream) {
64
        fundedByProject['funding'] = funding.stream;
65
      }
66
    }
67
    fundedByProjects.push(fundedByProject);
68
    return fundedByProjects;
69
  }
70

    
71
  // publication & research data : for fundedByProjects | project landing : for funding
72
  public parseFundingTrees(fundingTree: any): {"funderName": string, "funderShortname": string, "stream": string} {
73
    let funding: {"funderName": string, "funderShortname": string, "stream": string} = {"funderName": "", "funderShortname": "", "stream": ""};
74
    let length = Array.isArray(fundingTree) ? fundingTree.length : 1;
75

    
76
    for(let i=0; i<length; i++) {
77
      let fundingData = Array.isArray(fundingTree) ? fundingTree[i] : fundingTree;
78

    
79
      if(fundingData.hasOwnProperty("funder")) {
80
        funding.funderShortname = fundingData['funder'].shortname;
81
        funding.funderName = fundingData['funder'].name;
82
      }
83

    
84
      funding.stream = this.addFundingLevel0(fundingData, funding.stream);
85

    
86
      funding.stream = this.addFundingLevel1(fundingData, funding.stream);
87

    
88
      funding.stream = this.addFundingLevel2(fundingData, funding.stream);
89
    }
90
    return funding;
91
  }
92

    
93
  addFundingLevel0(parent: string, fundingStream: string) : string {
94
    if(parent.hasOwnProperty("funding_level_0")) {
95
      let level0 = parent['funding_level_0'];
96

    
97
      fundingStream += (fundingStream) ? " ; " : "";
98
      fundingStream += level0.name;
99
    }
100
    return fundingStream;
101
  }
102

    
103
  addFundingLevel1(parent: string, fundingStream: string): string {
104
    if(parent.hasOwnProperty("funding_level_1")) {
105
      let level1 = parent['funding_level_1'];
106

    
107
      // For projects' parsing
108
      if(level1.hasOwnProperty("parent")) {
109
        fundingStream = this.addFundingLevel0(level1.parent, fundingStream);
110
      }
111

    
112
      fundingStream += (fundingStream) ? " | " : "";
113
      fundingStream += level1.name;
114
    }
115
    return fundingStream;
116
  }
117

    
118
  addFundingLevel2(parent: string, fundingStream: string): string {
119
    if(parent.hasOwnProperty("funding_level_2")) {
120
      let level2 = parent['funding_level_2'];
121

    
122
      // For projects' parsing
123
      if(level2.hasOwnProperty("parent")) {
124
        fundingStream = this.addFundingLevel1(level2.parent, fundingStream);
125
      }
126

    
127
      fundingStream += (fundingStream) ? " | " : "";
128
      fundingStream += level2.name;
129
    }
130
    return fundingStream;
131
  }
132

    
133
  // publication & dataset landing : for collectedFrom
134
  parseCollectedFrom( collectedFrom: {"name": string, "id": string}[],
135
                     _collectedFrom: any) {
136
    let length: number = collectedFrom.length;
137
    collectedFrom[length] = {"name": "", "id": ""};
138
    collectedFrom[length]['name'] = _collectedFrom.name;
139
    collectedFrom[length]['id'] = _collectedFrom.id;
140
  }
141

    
142
  // publication & dataset landing : for downloadFrom
143
  addPublisherToHostedBy_collectedFrom( hostedBy_collectedFrom: {"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}[],
144
                              publisher: string, journal:{"journal": string, "issn": string, "lissn": string},
145
                              identifiers: Map<string, string[]>/*, title: { "name": string, "url": string, "accessMode": string}*/) {
146
    if( publisher && identifiers != null && identifiers.has('doi')) {
147
      if( hostedBy_collectedFrom == null) {
148
        hostedBy_collectedFrom = new Array<{"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}>();
149
      }
150
      let available: {"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string};
151
      available = {"downloadName": "", "downloadUrl": null, "collectedName": "", "collectedId": "", "accessMode": null, "bestAccessMode": null, "type": "", "year": ""};
152

    
153
      if(journal && journal.journal) {
154
        available.downloadName = publisher + "/ "+journal['journal'];
155
      } else {
156
        available.downloadName = publisher;
157
      }
158

    
159
      let url = "https://dx.doi.org/"+identifiers.get("doi")[0];
160

    
161
      available.downloadUrl = new Array<string>();
162
      available.accessMode = new Array<string>();
163

    
164
      available.downloadUrl.push(url);
165
/*
166
      if(title != undefined && title['url'] == "") {
167
        title['url'] = url;
168
      }
169
*/
170
      hostedBy_collectedFrom.push(available);
171
    }
172
    return hostedBy_collectedFrom;
173
  }
174

    
175
  // publication & dataset landing : for downloadFrom
176
  parseDownloadFrom(downloadFrom: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, url: string)
177
  {
178
    let key: string = instance['hostedby'].name;
179

    
180
    if(key) {
181
      this.addUrlAndAccessMode(downloadFrom, instance, key, url);
182
    }
183
  }
184

    
185
  // publication & dataset landing : for publishedIn
186
  parsePublishedIn(publishedIn: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, result: any, url: string, counter: number): number {
187
    if(result != null && result.hasOwnProperty("source")) {
188
      let key: string;
189
      if(Array.isArray(result.source)) {
190
        if(counter==result.source.length) {
191
          counter--;
192
        }
193
        key = result['source'][counter];
194
      } else {
195
        key = result['source'];
196
      }
197

    
198
      if(key) {
199
        this.addUrlAndAccessMode(publishedIn, instance, key, url);
200
        counter++;
201
      }
202
    }
203
    return counter;
204
  }
205

    
206
  // publication & dataset landing : for downloadFrom and publishedIn
207
  addUrlAndAccessMode(mapStructure: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, key: string, url: string) {
208
    if(!mapStructure.has(key)) {
209
      mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
210
    }
211

    
212
    if(mapStructure.get(key)['url'] == null) {
213
      mapStructure.get(key)['url'] = new Array<string>();
214
    }
215

    
216
    if(url) {
217
      mapStructure.get(key)['url'].push(url);
218
    }
219

    
220
    if(mapStructure.get(key)['accessMode'] == null) {
221
      mapStructure.get(key)['accessMode'] = new Array<string>();
222
    }
223

    
224
    if(instance.hasOwnProperty("accessright")) {
225
      if(url) {
226
        mapStructure.get(key)['accessMode'].push(instance['accessright'].classid);
227
      }
228

    
229
      if(this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) {
230
        mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classid;
231
      }
232
    } else if(url) {
233
      mapStructure.get(key)['accessMode'].push("");
234
    }
235
  }
236

    
237

    
238
  parseHostedBy_collectedFrom(hostedBy_collectedFrom: { "downloadName": string, "downloadUrl": string[],
239
                                  "collectedName": string, "collectedId": string,
240
                                  "accessMode": string[], "bestAccessMode": string,
241
                                  "type": string, "year":string }[],
242
                              instance: any, data: any, url: string, counter: number/*,
243
                              title: { "name": string, "url": string, "accessMode": string}*/, accessMode: string): number {
244
     let available: {"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string};
245
     available = {"downloadName": "", "downloadUrl": null, "collectedName": "", "collectedId": "", "accessMode": null, "bestAccessMode": null, "type": "", "year": ""};
246

    
247
     if(instance['hostedby'].name && instance['hostedby'].name != "other resources" && instance['hostedby'].name != "Unknown Repository") {
248
       available.downloadName = instance['hostedby'].name;
249
     } else {
250
       if(data != null && data.hasOwnProperty("source")) {
251
         let downloadName: string;
252
         if(Array.isArray(data.source)) {
253

    
254
           if(counter==data.source.length) {
255
             counter--;
256
           }
257
           downloadName = data['source'][counter];
258
         } else {
259
           downloadName = data['source'];
260
         }
261
         if(downloadName) {
262
           counter++;
263
           available.downloadName = downloadName;
264
         }
265
       }
266

    
267
     }
268

    
269
     if(available.downloadName) {
270
       if(instance.hasOwnProperty("collectedfrom")) {
271
         available.collectedId = instance['collectedfrom'].id;
272
         available.collectedName = instance['collectedfrom'].name;
273
       }
274

    
275
       if(instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
276
         available.type = instance['instancetype'].classname;
277
       }
278

    
279
       if(instance.hasOwnProperty("dateofacceptance")) {
280
         var date:string = (instance.dateofacceptance)+""; // transform to string in case it is an integer
281
         available.year  = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
282
       }
283

    
284
       available.accessMode = new Array<string>();
285
       available.downloadUrl = new Array<string>();
286
       available['downloadUrl'].push(url);
287
       if(instance.hasOwnProperty("accessright")) {
288
         if(url) {
289
           available['accessMode'].push(instance['accessright'].classid);
290
         }
291

    
292
         if(this.changeBestAccessMode(available.bestAccessMode, instance['accessright'])) {
293
           available.bestAccessMode = instance['accessright'].classid;
294
/*
295
           if(title != undefined) {
296
             if(this.changeBestAccessMode(title['accessMode'], instance['accessright'])) {
297
               title['accessMode'] = instance['accessright'].classid;
298
               title['url'] = url;
299
             }
300
           }
301
*/
302
          if(this.changeBestAccessMode(accessMode, instance['accessright'])) {
303
            accessMode = instance['accessright'].classid;
304
          }
305
         }
306
/*
307
         if(title != undefined) {
308
           if(!title['url']) {
309
             title['url'] = url;
310
           }
311
         }
312
*/
313
       } else if(url) {
314
         available['accessMode'].push("");
315
       }
316

    
317
       hostedBy_collectedFrom.push(available);
318
     }
319

    
320
     return counter;
321
  }
322

    
323
  // publication & dataset landing : for downloadFrom and publishedIn
324
  changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean {
325
    if(!accessMode) {
326
      return false;
327
    }
328
    accessMode = accessMode.classid;
329

    
330
    switch (currentAccessMode) {
331
      case null:
332
        if(accessMode != "UNKNOWN") {
333
          return true;
334
        }
335
        return false;
336
      case "CLOSED":
337
        if( accessMode == "OPEN" ||
338
            accessMode == "OPEN SOURCE" ||
339
            accessMode == "EMBARGO" ||
340
            accessMode == "RESTRICTED") {
341
              return true;
342
        }
343
        return false;
344
      case "RESTRICTED":
345
        if( accessMode == "OPEN" ||
346
            accessMode == "OPEN SOURCE" ||
347
            accessMode == "EMBARGO") {
348
              return true;
349
        }
350
        return false;
351
      case "EMBARGO":
352
        if( accessMode == "OPEN" ||
353
            accessMode == "OPEN SOURCE") {
354
          return true;
355
        }
356
        return false;
357
      case "OPEN SOURCE":
358
        if( accessMode == "OPEN") {
359
          return true;
360
        }
361
        return false;
362
    }
363
    return false;
364
  }
365

    
366
  // publication & dataset & software & orp landing : for relatedResearchResults
367
  parseRelatedResearchResults(relatedResearchResults: Map<string, { "name": string, "id": string, "date": string,
368
                    "percentage": number, "class": string}[]>, relation: any, provenanceAction: string) :
369
                        Map<string, { "name": string, "id": string, "date": string,
370
                                      "percentage": number, "class": string}[]> {
371
    if(relatedResearchResults == undefined) {
372
      relatedResearchResults = new Map<string, {"name": string, "id": string, "date": string,
373
                                                "percentage": number, "class": string }[]>();
374
    }
375

    
376
    if(!relatedResearchResults.has(provenanceAction)) {
377
      relatedResearchResults.set(provenanceAction,
378
                        new Array<{ "name": string, "id": string, "date": string,
379
                                    "percentage": number, "class": string }>());
380
    }
381
    relatedResearchResults.get(provenanceAction).push(this.parseRelatedOrSimilarResearchResult(relation, "trust"));
382

    
383
    return relatedResearchResults;
384
  }
385

    
386
  // publication & dataset & software & orp landing : for similarResearchResults
387
  parseSimilarResearchResults(similarResearchResults: { "name": string, "id": string, "date": string,
388
                                                        "percentage": number, "class": string}[], relation: any) :
389
                { "name": string, "id": string, "date": string, "percentage": number, "class": string }[] {
390
    if(similarResearchResults == undefined) {
391
      similarResearchResults = new Array<{"name": string, "id": string, "date": string,
392
                                          "percentage": number, "class": string}>();
393
    }
394
    similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "similarity"));
395
    return similarResearchResults;
396
  }
397

    
398
  // publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults
399
  parseRelatedOrSimilarResearchResult(relation: any, percentageName: string): {"name": string, "id": string, "date": string, "percentage": number, "class": string} {
400
    let researchResult: {"name": string, "id": string, "date": string, "percentage": number, "class": string}
401
                              = {"name": "", "id": "", "date": "", "percentage": null, "class": ""}
402
    if(relation['resulttype'].classname == "publication") {
403
      researchResult['class'] = "publication";
404
    } else if(relation['resulttype'].classname == "dataset") {
405
      researchResult['class'] = "dataset";
406
    } else if(relation['resulttype'].classname == "software") {
407
      researchResult['class'] = "software";
408
    } else if(relation['resulttype'].classname == "other") {
409
      researchResult['class'] = "other";
410
    }
411

    
412
    researchResult['id'] = relation['to'].content;
413
    let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : relation['title'].content;
414
    researchResult['name'] = titleName;
415
    if(relation.hasOwnProperty("dateofacceptance")) {
416
      var date:string = ((Array.isArray(relation.dateofacceptance))?(relation.dateofacceptance[0]):(relation.dateofacceptance))+""; // transform to string in case it is an integer
417
      researchResult['date']  = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
418
    }
419
    //researchResult['date'] = relation.dateofacceptance.substring(0,4);;
420
    researchResult['percentage'] = Math.round(relation[percentageName]*100);
421
    return researchResult;
422
  }
423

    
424
  sortByPercentage(results: { "name": string, "id": string, "date": string, "percentage": number, "class": string}[]) : { "name": string, "id": string, "date": string, "percentage": number, "class": string}[] {
425
    if(results) {
426
       return results.sort(function(a, b){return b["percentage"] - a["percentage"]});
427
    }
428
    return results;
429
  }
430

    
431
  // publication & dataset landing : for identifiers
432
  parseIdentifiers(pid: any): Map<string, string[]> {
433
    let identifiers = new Map<string, string[]>();
434

    
435
    if(pid.hasOwnProperty("classname") && pid['classname'] != "") {
436
      if(pid.classname == "doi" || pid.classname == "pmc" || pid.classname == "handle") {
437
        if(!identifiers.has(pid.classname)) {
438
          identifiers.set(pid.classname, new Array<string>());
439
        }
440

    
441
        identifiers.get(pid.classname).push(pid.content);
442
      }
443
    } else {
444
      for(let i=0; i<pid.length; i++) {
445
        if(pid[i].classname == "doi" || pid[i].classname == "pmc" || pid[i].classname == "handle") {
446
          if(!identifiers.has(pid[i].classname)) {
447
            identifiers.set(pid[i].classname, new Array<string>());
448
          }
449
          identifiers.get(pid[i].classname).push(pid[i].content);
450
        }
451
      }
452
    }
453
    return identifiers;
454
  }
455

    
456
  // publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
457
  parseAllSubjects(_subjects: any): [string[], Map<string, string[]>, Map<string, string[]>] {
458
    let subjects: string[];
459
    let otherSubjects: Map<string, string[]>;
460
    let classifiedSubjects: Map<string, string[]>;
461

    
462
    let subject;
463
    let length = Array.isArray(_subjects) ? _subjects.length : 1;
464

    
465
    for(let i=0; i<length; i++) {
466
      subject = Array.isArray(_subjects) ? _subjects[i] : _subjects;
467
      if(subject.classid != "") {
468
        if(subject.inferred && subject.inferred == true) {
469
          if(classifiedSubjects == undefined) {
470
            classifiedSubjects = new Map<string, string[]>();
471
          }
472

    
473
          if(!classifiedSubjects.has(subject.classname)) {
474
            classifiedSubjects.set(subject.classname, new Array<string>());
475
          }
476

    
477
          classifiedSubjects.get(subject.classname).push(subject.content);
478
        } else {
479
          if(subject.classid == "keyword") {
480
            if(subjects == undefined) {
481
              subjects = new Array<string>();
482
            }
483

    
484
            subjects.push(subject.content);
485
          } else {
486
            if(otherSubjects == undefined) {
487
              otherSubjects = new Map<string, string[]>();
488
            }
489

    
490
            if(!otherSubjects.has(subject.classname)) {
491
              otherSubjects.set(subject.classname, new Array<string>());
492
            }
493
            otherSubjects.get(subject.classname).push(subject.content);
494
          }
495
        }
496
      }
497
    }
498
    return [subjects, otherSubjects, classifiedSubjects];
499
  }
500

    
501
  parseContexts(_contexts: any): {"labelContext": string, "labelCategory": string,
502
                                  "labelConcept": string, inline:boolean}[] {
503
    let contexts = new Array<{"labelContext": string, "labelCategory": string,
504
                              "labelConcept": string, inline:boolean}>();
505

    
506
    let position = 0;
507
    let labels = "";
508
    let context;
509
    let length = Array.isArray(_contexts) ? _contexts.length : 1;
510
    for(let i=0; i<length; i++) {
511
      context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
512

    
513
      if(context.hasOwnProperty("type") && (context['type'] == "community" || context['type'] == "ri")) {
514
        if(context.hasOwnProperty("category")) {
515
          if(context['category'].hasOwnProperty("concept")) {
516
            let categoryConcept;
517
            let length1 = Array.isArray(context['category']['concept']) ? context['category']['concept'].length : 1;
518
            for(let j=0; j<length1; j++) {
519
              categoryConcept = Array.isArray(context['category']['concept']) ? context['category']['concept'][j] : context['category']['concept'];
520

    
521
              contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false };
522
              contexts[position]['labelContext'] = context.label;
523
              contexts[position]['labelCategory'] = context['category'].label;
524
              contexts[position]['labelConcept'] = categoryConcept.label;
525

    
526
              position++;
527
            }
528
          } else {
529
            contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
530
            contexts[position]['labelContext'] = context.label;
531
            contexts[position]['labelCategory'] = context['category'].label;
532
            contexts[position]['labelConcept'] = null;
533
            position++;
534
          }
535
        } else {
536
          contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
537
          contexts[position]['labelContext'] = context.label;
538
          contexts[position]['labelCategory'] = null;
539
          contexts[position]['labelConcept'] = null;
540
          contexts[position]['new'] = false;
541
          position++;
542
        }
543
      }
544
    }
545
    return contexts;
546
  }
547

    
548
  parseTypes(types: string[], uniqueTypes: Set<string>, instance: any) {
549
    if(instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
550
      if(!uniqueTypes.has(instance['instancetype'].classname)) {
551
        types.push(instance['instancetype'].classname);
552
        uniqueTypes.add(instance['instancetype'].classname);
553
      }
554
    }
555
  }
556

    
557
  parseLanguages(_languages: any) {
558
    var languages = new Array<string>();
559

    
560
    if(!Array.isArray(_languages)) {
561
      if(_languages.classname != "Undetermined" && _languages.classname) {
562
        languages.push(_languages.classname);
563
      }
564
    } else {
565
      for(let i=0; i<_languages.length; i++) {
566
        if(_languages[i].classname != "Undetermined" && _languages[i].classname) {
567
          languages.push(_languages[i].classname);
568
        }
569
      }
570
    }
571
    return languages;
572
  }
573

    
574
  parseCountries(_countries: any) {
575
    var countries = new Array<string>();
576

    
577
    if(!Array.isArray(_countries)) {
578
      if(_countries.classname != "Undetermined" && _countries.classname) {
579
        countries.push(_countries.classname);
580
      }
581
    } else {
582
      for(let i=0; i<countries.length; i++) {
583
        if(_countries[i].classname != "Undetermined" && _countries[i].classname) {
584
          countries.push(_countries[i].classname);
585
        }
586
      }
587
    }
588
    return countries;
589
  }
590

    
591
  parseProgrammingLanguages(_pLanguages) {
592
    var pLanguages = new Array<string>();
593

    
594
    if(!Array.isArray(_pLanguages)) {
595
      if(_pLanguages.classname != "Undetermined" && _pLanguages.classname) {
596
        pLanguages.push(_pLanguages.classname);
597
      }
598
    } else {
599
      for(let i=0; i<_pLanguages.length; i++) {
600
        if(_pLanguages[i].classname != "Undetermined" && _pLanguages[i].classname) {
601
          pLanguages.push(_pLanguages[i].classname);
602
        }
603
      }
604
    }
605
    return pLanguages;
606
  }
607

    
608
  parseReferences(citations: any): {"name": string, "url": string}[] {
609
    let references = new Array<{"name": string, "url": string}>();
610

    
611
    let citation;
612
    let length = Array.isArray(citations) ? citations.length : 1;
613
    for(let i=0; i<length; i++) {
614
      citation = Array.isArray(citations) ? citations[i] : citations;
615

    
616
      let url;
617
      if(citation.hasOwnProperty("id")) {
618
        let citationId;
619
        let length1 = Array.isArray(citation['id']) ? citation['id'].length : 1;
620
        for(let j=0; j<length1; j++) {
621
          citationId = Array.isArray(citation['id']) ? citation['id'][j] : citation['id'];
622

    
623
          if(citationId.type == "pmid") {
624
            url = "http://www.ncbi.nlm.nih.gov/pubmed/"+citationId.value;
625
          }
626
        }
627
      }
628

    
629
      references[citation.position-1] = { "name": "", "url": ""};
630
      references[citation.position-1]['name'] = citation.rawText;
631
      references[citation.position-1]['url'] = url;
632
    }
633
    return references;
634
  }
635
}
(7-7/18)