1
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
2
|
|
3
|
export class ParsingFunctions {
|
4
|
|
5
|
constructor () {}
|
6
|
|
7
|
public ngOnDestroy() {}
|
8
|
|
9
|
public parseFundingByProjects(fundedByProjects: { "id": string, "acronym": string, "title": string,
|
10
|
"funderShortname": string, "funderName": string,
|
11
|
"funding": string, "code": string,
|
12
|
"provenanceAction": string, "inline": boolean
|
13
|
}[],
|
14
|
relation: any, projectsProvenanceVocabulary: any):
|
15
|
{ "id": string, "acronym": string, "title": string,
|
16
|
"funderShortname": string, "funderName": string,
|
17
|
"funding": string, "code": string,
|
18
|
"provenanceAction": string, "inline": boolean
|
19
|
}[] {
|
20
|
if(fundedByProjects == undefined) {
|
21
|
fundedByProjects = new Array<{"id": string, "acronym": string, "title": string,
|
22
|
"funderShortname": string, "funderName": string,
|
23
|
"funding": string, "code": string,
|
24
|
"provenanceAction": string, "inline": boolean
|
25
|
}>();
|
26
|
}
|
27
|
|
28
|
let fundedByProject: { "id": string, "acronym": string, "title": string,
|
29
|
"funderShortname": string, "funderName": string,
|
30
|
"funding": string, "code": string,
|
31
|
"provenanceAction": string, "inline": boolean
|
32
|
} = { "id": "", "acronym": "", "title": "",
|
33
|
"funderShortname": "", "funderName": "",
|
34
|
"funding": "", "code": "", "provenanceAction": "", "inline": false
|
35
|
};
|
36
|
|
37
|
if(relation.title != 'unidentified') {
|
38
|
fundedByProject['id'] = relation['to'].content;
|
39
|
fundedByProject['acronym'] = relation.acronym;
|
40
|
fundedByProject['title'] = relation.title;
|
41
|
fundedByProject['code'] = relation.code;
|
42
|
|
43
|
if(relation.provenanceaction in projectsProvenanceVocabulary) {
|
44
|
fundedByProject['provenanceAction'] = projectsProvenanceVocabulary[relation.provenanceaction];
|
45
|
}
|
46
|
} else {
|
47
|
fundedByProject['id'] = "";
|
48
|
fundedByProject['acronym'] = "";
|
49
|
fundedByProject['title'] = "";
|
50
|
fundedByProject['code'] = "";
|
51
|
fundedByProject['provenanceAction'] = "";
|
52
|
}
|
53
|
|
54
|
if(relation.hasOwnProperty("funding")) {
|
55
|
let funding: {"funderName": string, "funderShortname": string, "stream": string};
|
56
|
funding = this.parseFundingTrees(relation.funding);
|
57
|
|
58
|
if(funding.funderName) {
|
59
|
fundedByProject['funderName'] = funding.funderName;
|
60
|
}
|
61
|
if(funding.funderShortname) {
|
62
|
fundedByProject['funderShortname'] = funding.funderShortname;
|
63
|
}
|
64
|
if(funding.stream) {
|
65
|
fundedByProject['funding'] = funding.stream;
|
66
|
}
|
67
|
}
|
68
|
fundedByProjects.push(fundedByProject);
|
69
|
return fundedByProjects;
|
70
|
}
|
71
|
|
72
|
// publication & research data : for fundedByProjects | project landing : for funding
|
73
|
public parseFundingTrees(fundingTree: any): {"funderName": string, "funderShortname": string, "stream": string} {
|
74
|
let funding: {"funderName": string, "funderShortname": string, "stream": string} = {"funderName": "", "funderShortname": "", "stream": ""};
|
75
|
let length = Array.isArray(fundingTree) ? fundingTree.length : 1;
|
76
|
|
77
|
for(let i=0; i<length; i++) {
|
78
|
let fundingData = Array.isArray(fundingTree) ? fundingTree[i] : fundingTree;
|
79
|
|
80
|
if(fundingData.hasOwnProperty("funder")) {
|
81
|
funding.funderShortname = fundingData['funder'].shortname;
|
82
|
funding.funderName = fundingData['funder'].name;
|
83
|
}
|
84
|
|
85
|
funding.stream = this.addFundingLevel0(fundingData, funding.stream);
|
86
|
|
87
|
funding.stream = this.addFundingLevel1(fundingData, funding.stream);
|
88
|
|
89
|
funding.stream = this.addFundingLevel2(fundingData, funding.stream);
|
90
|
}
|
91
|
return funding;
|
92
|
}
|
93
|
|
94
|
addFundingLevel0(parent: string, fundingStream: string) : string {
|
95
|
if(parent.hasOwnProperty("funding_level_0")) {
|
96
|
let level0 = parent['funding_level_0'];
|
97
|
|
98
|
fundingStream += (fundingStream) ? " ; " : "";
|
99
|
fundingStream += level0.name;
|
100
|
}
|
101
|
return fundingStream;
|
102
|
}
|
103
|
|
104
|
addFundingLevel1(parent: string, fundingStream: string): string {
|
105
|
if(parent.hasOwnProperty("funding_level_1")) {
|
106
|
let level1 = parent['funding_level_1'];
|
107
|
|
108
|
// For projects' parsing
|
109
|
if(level1.hasOwnProperty("parent")) {
|
110
|
fundingStream = this.addFundingLevel0(level1.parent, fundingStream);
|
111
|
}
|
112
|
|
113
|
fundingStream += (fundingStream) ? " | " : "";
|
114
|
fundingStream += level1.name;
|
115
|
}
|
116
|
return fundingStream;
|
117
|
}
|
118
|
|
119
|
addFundingLevel2(parent: string, fundingStream: string): string {
|
120
|
if(parent.hasOwnProperty("funding_level_2")) {
|
121
|
let level2 = parent['funding_level_2'];
|
122
|
|
123
|
// For projects' parsing
|
124
|
if(level2.hasOwnProperty("parent")) {
|
125
|
fundingStream = this.addFundingLevel1(level2.parent, fundingStream);
|
126
|
}
|
127
|
|
128
|
fundingStream += (fundingStream) ? " | " : "";
|
129
|
fundingStream += level2.name;
|
130
|
}
|
131
|
return fundingStream;
|
132
|
}
|
133
|
|
134
|
// publication & dataset landing : for collectedFrom
|
135
|
parseCollectedFrom(_collectedFrom: any): {"name": string, "id": string}[] {
|
136
|
let collectedFrom = new Array<{"name": string, "id": string}>();
|
137
|
|
138
|
let collected;
|
139
|
let length = Array.isArray(_collectedFrom) ? _collectedFrom.length : 1;
|
140
|
for(let i=0; i<length; i++) {
|
141
|
collected = Array.isArray(_collectedFrom) ? _collectedFrom[i] : _collectedFrom;
|
142
|
collectedFrom[i] = {"name": "", "id": ""};
|
143
|
collectedFrom[i]['name'] = collected.name;
|
144
|
collectedFrom[i]['id'] = collected.id;
|
145
|
}
|
146
|
|
147
|
return collectedFrom;
|
148
|
}
|
149
|
|
150
|
// publication & dataset landing : for downloadFrom
|
151
|
addPublisherToDownloadFrom( downloadFrom: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>,
|
152
|
publisher: string, journal:{"journal": string, "issn": string, "lissn": string},
|
153
|
identifiers: Map<string, string[]>, title: { "name": string, "url": string, "accessMode": string}) {
|
154
|
if( publisher && identifiers != null && identifiers.has('doi')) {
|
155
|
if( downloadFrom == null) {
|
156
|
downloadFrom = new Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>();
|
157
|
}
|
158
|
|
159
|
let key: string;
|
160
|
if(journal && journal.journal) {
|
161
|
key = publisher + "/ "+journal['journal'];
|
162
|
} else {
|
163
|
key = publisher;
|
164
|
}
|
165
|
downloadFrom.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
|
166
|
|
167
|
let url = OpenaireProperties.getDoiURL()+identifiers.get("doi")[0];
|
168
|
|
169
|
downloadFrom.get(key)['url'] = new Array<string>();
|
170
|
downloadFrom.get(key)['accessMode'] = new Array<string>();
|
171
|
|
172
|
downloadFrom.get(key)['url'][0] = url;
|
173
|
downloadFrom.get(key)['accessMode'][0] = "";
|
174
|
|
175
|
if(title != undefined && title['url'] == "") {
|
176
|
title['url'] = url;
|
177
|
}
|
178
|
}
|
179
|
return downloadFrom;
|
180
|
}
|
181
|
|
182
|
// publication & dataset landing : for downloadFrom
|
183
|
parseDownloadFrom(downloadFrom: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, url: string)
|
184
|
{
|
185
|
let key: string = instance['hostedby'].name;
|
186
|
|
187
|
if(key) {
|
188
|
this.addUrlAndAccessMode(downloadFrom, instance, key, url);
|
189
|
}
|
190
|
}
|
191
|
|
192
|
// publication & dataset landing : for publishedIn
|
193
|
parsePublishedIn(publishedIn: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, result: any, url: string, counter: number): number {
|
194
|
if(result != null && result.hasOwnProperty("source")) {
|
195
|
let key: string;
|
196
|
if(Array.isArray(result.source)) {
|
197
|
if(counter==result.source.length) {
|
198
|
counter--;
|
199
|
}
|
200
|
key = result['source'][counter];
|
201
|
} else {
|
202
|
key = result['source'];
|
203
|
}
|
204
|
|
205
|
if(key) {
|
206
|
this.addUrlAndAccessMode(publishedIn, instance, key, url);
|
207
|
counter++;
|
208
|
}
|
209
|
}
|
210
|
return counter;
|
211
|
}
|
212
|
|
213
|
// publication & dataset landing : for downloadFrom and publishedIn
|
214
|
addUrlAndAccessMode(mapStructure: Map<string, {"url": string[], "accessMode": string[], "bestAccessMode": string}>, instance: any, key: string, url: string) {
|
215
|
if(!mapStructure.has(key)) {
|
216
|
mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null});
|
217
|
}
|
218
|
|
219
|
if(mapStructure.get(key)['url'] == null) {
|
220
|
mapStructure.get(key)['url'] = new Array<string>();
|
221
|
}
|
222
|
|
223
|
if(url) {
|
224
|
mapStructure.get(key)['url'].push(url);
|
225
|
}
|
226
|
|
227
|
if(mapStructure.get(key)['accessMode'] == null) {
|
228
|
mapStructure.get(key)['accessMode'] = new Array<string>();
|
229
|
}
|
230
|
|
231
|
if(instance.hasOwnProperty("licence")) {
|
232
|
if(url) {
|
233
|
mapStructure.get(key)['accessMode'].push(instance['licence'].classid);
|
234
|
}
|
235
|
|
236
|
if(this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['licence'])) {
|
237
|
mapStructure.get(key)['bestAccessMode'] = instance['licence'].classid;
|
238
|
}
|
239
|
} else if(url) {
|
240
|
mapStructure.get(key)['accessMode'].push("");
|
241
|
}
|
242
|
}
|
243
|
|
244
|
// publication & dataset landing : for downloadFrom and publishedIn
|
245
|
changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean {
|
246
|
if(!accessMode) {
|
247
|
return false;
|
248
|
}
|
249
|
accessMode = accessMode.classid;
|
250
|
|
251
|
switch (currentAccessMode) {
|
252
|
case null:
|
253
|
return true;
|
254
|
case "CLOSED":
|
255
|
if( accessMode == "OPEN" ||
|
256
|
accessMode == "EMBARGO" ||
|
257
|
accessMode == "RESTRICTED") {
|
258
|
return true;
|
259
|
}
|
260
|
return false;
|
261
|
case "RESTRICTED":
|
262
|
if( accessMode == "OPEN" ||
|
263
|
accessMode == "EMBARGO") {
|
264
|
return true;
|
265
|
}
|
266
|
return false;
|
267
|
case "EMBARGO":
|
268
|
if(accessMode == "OPEN") {
|
269
|
return true;
|
270
|
}
|
271
|
return false;
|
272
|
}
|
273
|
return false;
|
274
|
}
|
275
|
|
276
|
// publication & dataset landing : for relatedResearchResults
|
277
|
parseRelatedResearchResults(relatedResearchResults_1: Map<string, { "name": string, "id": string, "date": string,
|
278
|
"trust": number, "class": string}[]>, relation: any, provenanceAction: string) :
|
279
|
Map<string, { "name": string, "id": string, "date": string,
|
280
|
"trust": number, "class": string}[]> {
|
281
|
|
282
|
// if(relatedResearchResults == undefined) {
|
283
|
let relatedResearchResults = new Map<string, {"name": string, "id": string, "date": string,
|
284
|
"trust": number, "class": string }[]>();
|
285
|
// }
|
286
|
|
287
|
if(!relatedResearchResults.has(provenanceAction)) {
|
288
|
relatedResearchResults.set(provenanceAction,
|
289
|
new Array<{ "name": string, "id": string, "date": string,
|
290
|
"trust": number, "class": string }>());
|
291
|
}
|
292
|
relatedResearchResults.get(provenanceAction).push(this.parseRelatedOrSimilarResearchResult(relation));
|
293
|
|
294
|
return relatedResearchResults;
|
295
|
}
|
296
|
|
297
|
// publication & dataset landing : for similarResearchResults
|
298
|
parseSimilarResearchResults(similarResearchResults: { "name": string, "id": string, "date": string,
|
299
|
"trust": number, "class": string}[], relation: any) :
|
300
|
{ "name": string, "id": string, "date": string, "trust": number, "class": string }[] {
|
301
|
if(similarResearchResults == undefined) {
|
302
|
similarResearchResults = new Array<{"name": string, "id": string, "date": string,
|
303
|
"trust": number, "class": string}>();
|
304
|
}
|
305
|
similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation));
|
306
|
return similarResearchResults;
|
307
|
}
|
308
|
|
309
|
// publication & dataset landing : for relatedResearchResults and similarResearchResults
|
310
|
parseRelatedOrSimilarResearchResult(relation: any): {"name": string, "id": string, "date": string, "trust": number, "class": string} {
|
311
|
let researchResult: {"name": string, "id": string, "date": string, "trust": number, "class": string}
|
312
|
= {"name": "", "id": "", "date": "", "trust": null, "class": ""}
|
313
|
|
314
|
if(relation['resulttype'].classname == "publication") {
|
315
|
researchResult['class'] = "publication";
|
316
|
} else if(relation['resulttype'].classname == "dataset") {
|
317
|
researchResult['class'] = "dataset";
|
318
|
} else {
|
319
|
researchResult['class'] = "software";
|
320
|
}
|
321
|
|
322
|
researchResult['id'] = relation['to'].content;
|
323
|
let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : relation['title'].content;
|
324
|
researchResult['name'] = titleName;
|
325
|
var date:string = ((Array.isArray(relation.dateofacceptance))?(relation.dateofacceptance[0]):(relation.dateofacceptance))+""; // transform to string in case it is an integer
|
326
|
researchResult['date'] = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date;
|
327
|
//researchResult['date'] = relation.dateofacceptance.substring(0,4);;
|
328
|
researchResult['trust'] = Math.round(relation.trust*100);
|
329
|
return researchResult;
|
330
|
}
|
331
|
|
332
|
// publication & dataset landing : for identifiers
|
333
|
parseIdentifiers(pid: any): Map<string, string[]> {
|
334
|
let identifiers = new Map<string, string[]>();
|
335
|
|
336
|
if(pid.hasOwnProperty("classname") && pid['classname'] != "") {
|
337
|
if(pid.classname == "doi" || pid.classname == "pmc" || pid.classname == "handle") {
|
338
|
if(!identifiers.has(pid.classname)) {
|
339
|
identifiers.set(pid.classname, new Array<string>());
|
340
|
}
|
341
|
|
342
|
identifiers.get(pid.classname).push(pid.content);
|
343
|
}
|
344
|
} else {
|
345
|
for(let i=0; i<pid.length; i++) {
|
346
|
if(pid[i].classname == "doi" || pid[i].classname == "pmc" || pid[i].classname == "handle") {
|
347
|
if(!identifiers.has(pid[i].classname)) {
|
348
|
identifiers.set(pid[i].classname, new Array<string>());
|
349
|
}
|
350
|
identifiers.get(pid[i].classname).push(pid[i].content);
|
351
|
}
|
352
|
}
|
353
|
}
|
354
|
return identifiers;
|
355
|
}
|
356
|
|
357
|
// publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
|
358
|
parseAllSubjects(_subjects: any): [string[], Map<string, string[]>, Map<string, string[]>] {
|
359
|
let subjects: string[];
|
360
|
let otherSubjects: Map<string, string[]>;
|
361
|
let classifiedSubjects: Map<string, string[]>;
|
362
|
|
363
|
let subject;
|
364
|
let length = Array.isArray(_subjects) ? _subjects.length : 1;
|
365
|
|
366
|
for(let i=0; i<length; i++) {
|
367
|
subject = Array.isArray(_subjects) ? _subjects[i] : _subjects;
|
368
|
if(subject.classid != "") {
|
369
|
if(subject.inferred && subject.inferred == true) {
|
370
|
if(classifiedSubjects == undefined) {
|
371
|
classifiedSubjects = new Map<string, string[]>();
|
372
|
}
|
373
|
|
374
|
if(!classifiedSubjects.has(subject.classname)) {
|
375
|
classifiedSubjects.set(subject.classname, new Array<string>());
|
376
|
}
|
377
|
|
378
|
classifiedSubjects.get(subject.classname).push(subject.content);
|
379
|
} else {
|
380
|
if(subject.classid == "keyword") {
|
381
|
if(subjects == undefined) {
|
382
|
subjects = new Array<string>();
|
383
|
}
|
384
|
|
385
|
subjects.push(subject.content);
|
386
|
} else {
|
387
|
if(otherSubjects == undefined) {
|
388
|
otherSubjects = new Map<string, string[]>();
|
389
|
}
|
390
|
|
391
|
if(!otherSubjects.has(subject.classname)) {
|
392
|
otherSubjects.set(subject.classname, new Array<string>());
|
393
|
}
|
394
|
otherSubjects.get(subject.classname).push(subject.content);
|
395
|
}
|
396
|
}
|
397
|
}
|
398
|
}
|
399
|
return [subjects, otherSubjects, classifiedSubjects];
|
400
|
}
|
401
|
|
402
|
parseContexts(_contexts: any): {"labelContext": string, "labelCategory": string,
|
403
|
"labelConcept": string, inline:boolean}[] {
|
404
|
let contexts = new Array<{"labelContext": string, "labelCategory": string,
|
405
|
"labelConcept": string, inline:boolean}>();
|
406
|
|
407
|
let position = 0;
|
408
|
let labels = "";
|
409
|
let context;
|
410
|
let length = Array.isArray(_contexts) ? _contexts.length : 1;
|
411
|
for(let i=0; i<length; i++) {
|
412
|
context = Array.isArray(_contexts) ? _contexts[i] : _contexts;
|
413
|
|
414
|
if(context.hasOwnProperty("type") && context['type'] == "community") {
|
415
|
if(context.hasOwnProperty("category")) {
|
416
|
if(context['category'].hasOwnProperty("concept")) {
|
417
|
let categoryConcept;
|
418
|
let length1 = Array.isArray(context['category']['concept']) ? context['category']['concept'].length : 1;
|
419
|
for(let j=0; j<length1; j++) {
|
420
|
categoryConcept = Array.isArray(context['category']['concept']) ? context['category']['concept'][j] : context['category']['concept'];
|
421
|
|
422
|
contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false };
|
423
|
contexts[position]['labelContext'] = context.label;
|
424
|
contexts[position]['labelCategory'] = context['category'].label;
|
425
|
contexts[position]['labelConcept'] = categoryConcept.label;
|
426
|
|
427
|
position++;
|
428
|
}
|
429
|
} else {
|
430
|
contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
|
431
|
contexts[position]['labelContext'] = context.label;
|
432
|
contexts[position]['labelCategory'] = context['category'].label;
|
433
|
contexts[position]['labelConcept'] = null;
|
434
|
}
|
435
|
} else {
|
436
|
contexts[position] = {"labelContext": "", "labelCategory": "", "labelConcept": "", inline: false};
|
437
|
contexts[position]['labelContext'] = context.label;
|
438
|
contexts[position]['labelCategory'] = null;
|
439
|
contexts[position]['labelConcept'] = null;
|
440
|
contexts[position]['new'] = false;
|
441
|
}
|
442
|
}
|
443
|
}
|
444
|
return contexts;
|
445
|
}
|
446
|
|
447
|
parseTypes(types: string[], uniqueTypes: Set<string>, instance: any) {
|
448
|
if(instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) {
|
449
|
if(!uniqueTypes.has(instance['instancetype'].classname)) {
|
450
|
types.push(instance['instancetype'].classname);
|
451
|
uniqueTypes.add(instance['instancetype'].classname);
|
452
|
}
|
453
|
}
|
454
|
}
|
455
|
}
|