export class ParsingFunctions { constructor () {} public ngOnDestroy() {} public parseFundingByProjects(fundedByProjects: { "id": string, "acronym": string, "title": string, "funderShortname": string, "funderName": string, "funding": string, "code": string, "provenanceAction": string, "inline": boolean }[], relation: any, provenanceActionVocabulary: any): { "id": string, "acronym": string, "title": string, "funderShortname": string, "funderName": string, "funding": string, "code": string, "provenanceAction": string, "inline": boolean }[] { if(fundedByProjects == undefined) { fundedByProjects = new Array<{"id": string, "acronym": string, "title": string, "funderShortname": string, "funderName": string, "funding": string, "code": string, "provenanceAction": string, "inline": boolean }>(); } let fundedByProject: { "id": string, "acronym": string, "title": string, "funderShortname": string, "funderName": string, "funding": string, "code": string, "provenanceAction": string, "inline": boolean } = { "id": "", "acronym": "", "title": "", "funderShortname": "", "funderName": "", "funding": "", "code": "", "provenanceAction": "", "inline": false }; if(relation.title != 'unidentified') { fundedByProject['id'] = relation['to'].content; fundedByProject['acronym'] = relation.acronym; fundedByProject['title'] = relation.title; fundedByProject['code'] = relation.code; if(provenanceActionVocabulary != null && relation.provenanceaction in provenanceActionVocabulary) { fundedByProject['provenanceAction'] = provenanceActionVocabulary[relation.provenanceaction]; } } else { fundedByProject['id'] = ""; fundedByProject['acronym'] = ""; fundedByProject['title'] = ""; fundedByProject['code'] = ""; fundedByProject['provenanceAction'] = ""; } if(relation.hasOwnProperty("funding")) { let funding: {"funderName": string, "funderShortname": string, "stream": string}; funding = this.parseFundingTrees(relation.funding); if(funding.funderName) { fundedByProject['funderName'] = funding.funderName; } if(funding.funderShortname) { fundedByProject['funderShortname'] = funding.funderShortname; } if(funding.stream) { fundedByProject['funding'] = funding.stream; } } fundedByProjects.push(fundedByProject); return fundedByProjects; } // publication & research data : for fundedByProjects | project landing : for funding public parseFundingTrees(fundingTree: any): {"funderName": string, "funderShortname": string, "stream": string} { let funding: {"funderName": string, "funderShortname": string, "stream": string} = {"funderName": "", "funderShortname": "", "stream": ""}; let length = Array.isArray(fundingTree) ? fundingTree.length : 1; for(let i=0; i/*, title: { "name": string, "url": string, "accessMode": string}*/) { if( publisher && identifiers != null && identifiers.has('doi')) { if( hostedBy_collectedFrom == null) { hostedBy_collectedFrom = new Array<{"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}>(); } let available: {"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}; available = {"downloadName": "", "downloadUrl": null, "collectedName": "", "collectedId": "", "accessMode": null, "bestAccessMode": null, "type": "", "year": ""}; if(journal && journal.journal) { available.downloadName = publisher + "/ "+journal['journal']; } else { available.downloadName = publisher; } let url = "https://dx.doi.org/"+identifiers.get("doi")[0]; available.downloadUrl = new Array(); available.accessMode = new Array(); available.downloadUrl.push(url); /* if(title != undefined && title['url'] == "") { title['url'] = url; } */ hostedBy_collectedFrom.push(available); } return hostedBy_collectedFrom; } // publication & dataset landing : for downloadFrom parseDownloadFrom(downloadFrom: Map, instance: any, url: string) { let key: string = instance['hostedby'].name; if(key) { this.addUrlAndAccessMode(downloadFrom, instance, key, url); } } // publication & dataset landing : for publishedIn parsePublishedIn(publishedIn: Map, instance: any, result: any, url: string, counter: number): number { if(result != null && result.hasOwnProperty("source")) { let key: string; if(Array.isArray(result.source)) { if(counter==result.source.length) { counter--; } key = result['source'][counter]; } else { key = result['source']; } if(key) { this.addUrlAndAccessMode(publishedIn, instance, key, url); counter++; } } return counter; } // publication & dataset landing : for downloadFrom and publishedIn addUrlAndAccessMode(mapStructure: Map, instance: any, key: string, url: string) { if(!mapStructure.has(key)) { mapStructure.set(key, {"url": null, "accessMode": null, "bestAccessMode": null}); } if(mapStructure.get(key)['url'] == null) { mapStructure.get(key)['url'] = new Array(); } if(url) { mapStructure.get(key)['url'].push(url); } if(mapStructure.get(key)['accessMode'] == null) { mapStructure.get(key)['accessMode'] = new Array(); } if(instance.hasOwnProperty("accessright")) { if(url) { mapStructure.get(key)['accessMode'].push(instance['accessright'].classid); } if(this.changeBestAccessMode(mapStructure.get(key)['bestAccessMode'], instance['accessright'])) { mapStructure.get(key)['bestAccessMode'] = instance['accessright'].classid; } } else if(url) { mapStructure.get(key)['accessMode'].push(""); } } parseHostedBy_collectedFrom(hostedBy_collectedFrom: { "downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string }[], instance: any, data: any, url: string, counter: number/*, title: { "name": string, "url": string, "accessMode": string}*/, accessMode: string): number { let available: {"downloadName": string, "downloadUrl": string[], "collectedName": string, "collectedId": string, "accessMode": string[], "bestAccessMode": string, "type": string, "year":string}; available = {"downloadName": "", "downloadUrl": null, "collectedName": "", "collectedId": "", "accessMode": null, "bestAccessMode": null, "type": "", "year": ""}; if(instance['hostedby'].name && instance['hostedby'].name != "other resources" && instance['hostedby'].name != "Unknown Repository") { available.downloadName = instance['hostedby'].name; } else { if(data != null && data.hasOwnProperty("source")) { let downloadName: string; if(Array.isArray(data.source)) { if(counter==data.source.length) { counter--; } downloadName = data['source'][counter]; } else { downloadName = data['source']; } if(downloadName) { counter++; available.downloadName = downloadName; } } } if(available.downloadName) { if(instance.hasOwnProperty("collectedfrom")) { available.collectedId = instance['collectedfrom'].id; available.collectedName = instance['collectedfrom'].name; } if(instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) { available.type = instance['instancetype'].classname; } if(instance.hasOwnProperty("dateofacceptance")) { var date:string = (instance.dateofacceptance)+""; // transform to string in case it is an integer available.year = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date; } available.accessMode = new Array(); available.downloadUrl = new Array(); available['downloadUrl'].push(url); if(instance.hasOwnProperty("accessright")) { if(url) { available['accessMode'].push(instance['accessright'].classid); } if(this.changeBestAccessMode(available.bestAccessMode, instance['accessright'])) { available.bestAccessMode = instance['accessright'].classid; /* if(title != undefined) { if(this.changeBestAccessMode(title['accessMode'], instance['accessright'])) { title['accessMode'] = instance['accessright'].classid; title['url'] = url; } } */ if(this.changeBestAccessMode(accessMode, instance['accessright'])) { accessMode = instance['accessright'].classid; } } /* if(title != undefined) { if(!title['url']) { title['url'] = url; } } */ } else if(url) { available['accessMode'].push(""); } hostedBy_collectedFrom.push(available); } return counter; } // publication & dataset landing : for downloadFrom and publishedIn changeBestAccessMode(currentAccessMode: string, accessMode: any): boolean { if(!accessMode) { return false; } accessMode = accessMode.classid; switch (currentAccessMode) { case null: if(accessMode != "UNKNOWN") { return true; } return false; case "CLOSED": if( accessMode == "OPEN" || accessMode == "OPEN SOURCE" || accessMode == "EMBARGO" || accessMode == "RESTRICTED") { return true; } return false; case "RESTRICTED": if( accessMode == "OPEN" || accessMode == "OPEN SOURCE" || accessMode == "EMBARGO") { return true; } return false; case "EMBARGO": if( accessMode == "OPEN" || accessMode == "OPEN SOURCE") { return true; } return false; case "OPEN SOURCE": if( accessMode == "OPEN") { return true; } return false; } return false; } // publication & dataset & software & orp landing : for relatedResearchResults parseRelatedResearchResults(relatedResearchResults: Map, relation: any, provenanceAction: string) : Map { if(relatedResearchResults == undefined) { relatedResearchResults = new Map(); } if(!relatedResearchResults.has(provenanceAction)) { relatedResearchResults.set(provenanceAction, new Array<{ "name": string, "id": string, "date": string, "percentage": number, "class": string }>()); } relatedResearchResults.get(provenanceAction).push(this.parseRelatedOrSimilarResearchResult(relation, "trust")); return relatedResearchResults; } // publication & dataset & software & orp landing : for supplementaryResearchResults parseSupplementaryResearchResults(supplementaryResearchResults: { "name": string, "id": string, "date": string, "percentage": number, "class": string}[], relation: any) : { "name": string, "id": string, "date": string, "percentage": number, "class": string }[] { if(supplementaryResearchResults == undefined) { supplementaryResearchResults = new Array<{"name": string, "id": string, "date": string, "percentage": number, "class": string}>(); } supplementaryResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust")); return supplementaryResearchResults; } // publication & dataset & software & orp landing : for supplementedByResearchResults parseSupplementedByResearchResults(supplementedByResearchResults: { "name": string, "id": string, "date": string, "percentage": number, "class": string}[], relation: any) : { "name": string, "id": string, "date": string, "percentage": number, "class": string }[] { if(supplementedByResearchResults == undefined) { supplementedByResearchResults = new Array<{"name": string, "id": string, "date": string, "percentage": number, "class": string}>(); } supplementedByResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "trust")); return supplementedByResearchResults; } // publication & dataset & software & orp landing : for similarResearchResults parseSimilarResearchResults(similarResearchResults: { "name": string, "id": string, "date": string, "percentage": number, "class": string}[], relation: any) : { "name": string, "id": string, "date": string, "percentage": number, "class": string }[] { if(similarResearchResults == undefined) { similarResearchResults = new Array<{"name": string, "id": string, "date": string, "percentage": number, "class": string}>(); } similarResearchResults.push(this.parseRelatedOrSimilarResearchResult(relation, "similarity")); return similarResearchResults; } // publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults parseRelatedOrSimilarResearchResult(relation: any, percentageName: string): {"name": string, "id": string, "date": string, "percentage": number, "class": string} { let researchResult: {"name": string, "id": string, "date": string, "percentage": number, "class": string} = {"name": "", "id": "", "date": "", "percentage": null, "class": ""} if(relation['resulttype'].classname == "publication") { researchResult['class'] = "publication"; } else if(relation['resulttype'].classname == "dataset") { researchResult['class'] = "dataset"; } else if(relation['resulttype'].classname == "software") { researchResult['class'] = "software"; } else if(relation['resulttype'].classname == "other") { researchResult['class'] = "other"; } researchResult['id'] = relation['to'].content; let titleName = Array.isArray(relation['title']) ? relation['title'][0].content : relation['title'].content; researchResult['name'] = titleName; if(relation.hasOwnProperty("dateofacceptance")) { var date:string = ((Array.isArray(relation.dateofacceptance))?(relation.dateofacceptance[0]):(relation.dateofacceptance))+""; // transform to string in case it is an integer researchResult['date'] = (date && (date).indexOf('-') !== -1)?date.split('-')[0]:date; } //researchResult['date'] = relation.dateofacceptance.substring(0,4);; researchResult['percentage'] = Math.round(relation[percentageName]*100); return researchResult; } sortByPercentage(results: { "name": string, "id": string, "date": string, "percentage": number, "class": string}[]) : { "name": string, "id": string, "date": string, "percentage": number, "class": string}[] { if(results) { return results.sort(function(a, b){return b["percentage"] - a["percentage"]}); } return results; } // publication & dataset landing : for identifiers parseIdentifiers(pid: any): Map { let identifiers = new Map(); if(pid.hasOwnProperty("classname") && pid['classname'] != "") { if(pid.classname == "doi" || pid.classname == "pmc" || pid.classname == "handle") { if(!identifiers.has(pid.classname)) { identifiers.set(pid.classname, new Array()); } identifiers.get(pid.classname).push(pid.content); } } else { for(let i=0; i()); } identifiers.get(pid[i].classname).push(pid[i].content); } } } return identifiers; } // publication & dataset landing : for subjects and otherSubjects and classifiedSubjects parseAllSubjects(_subjects: any): [string[], Map, Map] { let subjects: string[]; let otherSubjects: Map; let classifiedSubjects: Map; let subject; let length = Array.isArray(_subjects) ? _subjects.length : 1; for(let i=0; i(); } if(!classifiedSubjects.has(subject.classname)) { classifiedSubjects.set(subject.classname, new Array()); } classifiedSubjects.get(subject.classname).push(subject.content); } else { if(subject.classid == "keyword") { if(subjects == undefined) { subjects = new Array(); } subjects.push(subject.content); } else { if(otherSubjects == undefined) { otherSubjects = new Map(); } if(!otherSubjects.has(subject.classname)) { otherSubjects.set(subject.classname, new Array()); } otherSubjects.get(subject.classname).push(subject.content); } } } } return [subjects, otherSubjects, classifiedSubjects]; } parseContexts(_contexts: any): {"labelContext": string, "labelCategory": string, "labelConcept": string, inline:boolean}[] { let contexts = new Array<{"labelContext": string, "labelCategory": string, "labelConcept": string, inline:boolean}>(); let position = 0; let labels = ""; let context; let length = Array.isArray(_contexts) ? _contexts.length : 1; for(let i=0; i, instance: any) { if(instance.hasOwnProperty("instancetype") && instance['instancetype'].classname) { if(!uniqueTypes.has(instance['instancetype'].classname)) { types.push(instance['instancetype'].classname); uniqueTypes.add(instance['instancetype'].classname); } } } parseLanguages(_languages: any) { var languages = new Array(); if(!Array.isArray(_languages)) { if(_languages.classname != "Undetermined" && _languages.classname) { languages.push(_languages.classname); } } else { for(let i=0; i<_languages.length; i++) { if(_languages[i].classname != "Undetermined" && _languages[i].classname) { languages.push(_languages[i].classname); } } } return languages; } parseCountries(_countries: any) { var countries = new Array(); if(!Array.isArray(_countries)) { if(_countries.classname != "Undetermined" && _countries.classname) { countries.push(_countries.classname); } } else { for(let i=0; i(); if(!Array.isArray(_pLanguages)) { if(_pLanguages.classname != "Undetermined" && _pLanguages.classname) { pLanguages.push(_pLanguages.classname); } } else { for(let i=0; i<_pLanguages.length; i++) { if(_pLanguages[i].classname != "Undetermined" && _pLanguages[i].classname) { pLanguages.push(_pLanguages[i].classname); } } } return pLanguages; } parseReferences(citations: any): {"name": string, "url": string}[] { let references = new Array<{"name": string, "url": string}>(); let citation; let length = Array.isArray(citations) ? citations.length : 1; for(let i=0; i