2020-03-16 14:09:46 +01:00
import { HostedByCollectedFrom , Journal , Project , RelationResult } from "../../utils/result-preview/result-preview" ;
2020-03-17 18:48:02 +01:00
import { Reference } from "../../utils/entities/resultLandingInfo" ;
2017-12-19 13:53:46 +01:00
export class ParsingFunctions {
2020-07-01 14:11:57 +02:00
public open = 'assets/common-assets/unlock.svg' ;
public closed = 'assets/common-assets/lock.svg' ;
public unknown = 'assets/common-assets/question.svg' ;
2020-03-16 14:09:46 +01:00
constructor ( ) {
}
public ngOnDestroy() {
}
public parseFundingByProjects ( fundedByProjects : Project [ ] , relation : any ,
provenanceActionVocabulary : any ) : Project [ ] {
if ( fundedByProjects == undefined ) {
fundedByProjects = [ ] ;
}
let fundedByProject : Project = {
"id" : "" , "acronym" : "" , "title" : "" ,
"funderShortname" : "" , "funderName" : "" ,
"funding" : "" , "code" : "" , "provenanceAction" : "" , "inline" : false
} ;
if ( relation . title != 'unidentified' ) {
2017-12-19 13:53:46 +01:00
fundedByProject [ 'id' ] = relation [ 'to' ] . content ;
fundedByProject [ 'acronym' ] = relation . acronym ;
fundedByProject [ 'title' ] = relation . title ;
fundedByProject [ 'code' ] = relation . code ;
2020-03-16 14:09:46 +01:00
if ( provenanceActionVocabulary != null && relation . provenanceaction in provenanceActionVocabulary ) {
2019-10-09 15:28:23 +02:00
fundedByProject [ 'provenanceAction' ] = provenanceActionVocabulary [ relation . provenanceaction ] ;
2017-12-19 13:53:46 +01:00
}
} else {
fundedByProject [ 'id' ] = "" ;
fundedByProject [ 'acronym' ] = "" ;
fundedByProject [ 'title' ] = "" ;
fundedByProject [ 'code' ] = "" ;
fundedByProject [ 'provenanceAction' ] = "" ;
}
2020-03-16 14:09:46 +01:00
if ( relation . hasOwnProperty ( "funding" ) ) {
let funding : { "funderName" : string , "funderShortname" : string , "stream" : string } ;
2017-12-19 13:53:46 +01:00
funding = this . parseFundingTrees ( relation . funding ) ;
2020-03-16 14:09:46 +01:00
if ( funding . funderName ) {
2017-12-19 13:53:46 +01:00
fundedByProject [ 'funderName' ] = funding . funderName ;
}
2020-03-16 14:09:46 +01:00
if ( funding . funderShortname ) {
2017-12-19 13:53:46 +01:00
fundedByProject [ 'funderShortname' ] = funding . funderShortname ;
}
2020-03-16 14:09:46 +01:00
if ( funding . stream ) {
2017-12-19 13:53:46 +01:00
fundedByProject [ 'funding' ] = funding . stream ;
}
}
fundedByProjects . push ( fundedByProject ) ;
return fundedByProjects ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & research data : for fundedByProjects | project landing : for funding
2020-03-16 14:09:46 +01:00
public parseFundingTrees ( fundingTree : any ) : { "funderName" : string , "funderShortname" : string , "stream" : string } {
let funding : { "funderName" : string , "funderShortname" : string , "stream" : string } = {
"funderName" : "" ,
"funderShortname" : "" ,
"stream" : ""
} ;
2017-12-19 13:53:46 +01:00
let length = Array . isArray ( fundingTree ) ? fundingTree.length : 1 ;
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < length ; i ++ ) {
2017-12-19 13:53:46 +01:00
let fundingData = Array . isArray ( fundingTree ) ? fundingTree [ i ] : fundingTree ;
2020-03-16 14:09:46 +01:00
if ( fundingData . hasOwnProperty ( "funder" ) ) {
2017-12-19 13:53:46 +01:00
funding . funderShortname = fundingData [ 'funder' ] . shortname ;
funding . funderName = fundingData [ 'funder' ] . name ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel0 ( fundingData , funding . stream ) ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel1 ( fundingData , funding . stream ) ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel2 ( fundingData , funding . stream ) ;
}
return funding ;
}
2020-03-16 14:09:46 +01:00
addFundingLevel0 ( parent : string , fundingStream : string ) : string {
if ( parent . hasOwnProperty ( "funding_level_0" ) ) {
2017-12-19 13:53:46 +01:00
let level0 = parent [ 'funding_level_0' ] ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " ; " : "" ;
fundingStream += level0 . name ;
}
return fundingStream ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
addFundingLevel1 ( parent : string , fundingStream : string ) : string {
2020-03-16 14:09:46 +01:00
if ( parent . hasOwnProperty ( "funding_level_1" ) ) {
2017-12-19 13:53:46 +01:00
let level1 = parent [ 'funding_level_1' ] ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// For projects' parsing
2020-03-16 14:09:46 +01:00
if ( level1 . hasOwnProperty ( "parent" ) ) {
2017-12-19 13:53:46 +01:00
fundingStream = this . addFundingLevel0 ( level1 . parent , fundingStream ) ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " | " : "" ;
fundingStream += level1 . name ;
}
return fundingStream ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
addFundingLevel2 ( parent : string , fundingStream : string ) : string {
2020-03-16 14:09:46 +01:00
if ( parent . hasOwnProperty ( "funding_level_2" ) ) {
2017-12-19 13:53:46 +01:00
let level2 = parent [ 'funding_level_2' ] ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// For projects' parsing
2020-03-16 14:09:46 +01:00
if ( level2 . hasOwnProperty ( "parent" ) ) {
2017-12-19 13:53:46 +01:00
fundingStream = this . addFundingLevel1 ( level2 . parent , fundingStream ) ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " | " : "" ;
fundingStream += level2 . name ;
}
return fundingStream ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for collectedFrom
2020-03-16 14:09:46 +01:00
parseCollectedFrom ( collectedFrom : { "name" : string , "id" : string } [ ] ,
2017-12-19 13:53:46 +01:00
_collectedFrom : any ) {
let length : number = collectedFrom . length ;
collectedFrom [ length ] = { "name" : "" , "id" : "" } ;
collectedFrom [ length ] [ 'name' ] = _collectedFrom . name ;
collectedFrom [ length ] [ 'id' ] = _collectedFrom . id ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for downloadFrom
2020-03-16 14:09:46 +01:00
addPublisherToHostedBy_collectedFrom ( hostedBy_collectedFrom : HostedByCollectedFrom [ ] ,
publisher : string , journal : Journal ,
identifiers : Map < string , string [ ] > /*, title: { "name": string, "url": string, "accessMode": string}*/ ) {
if ( publisher && identifiers != null && identifiers . has ( 'doi' ) ) {
if ( hostedBy_collectedFrom == null ) {
hostedBy_collectedFrom = [ ] ;
2017-12-19 13:53:46 +01:00
}
2020-03-16 14:09:46 +01:00
let available : HostedByCollectedFrom = {
downloadName : "" ,
downloadUrl : null ,
collectedName : "" ,
collectedId : "" ,
accessMode : null ,
bestAccessMode : null ,
type : "" ,
2020-07-01 14:11:57 +02:00
year : "" ,
icon : ""
2020-03-16 14:09:46 +01:00
} ;
if ( journal && journal . journal ) {
available . downloadName = publisher + "/ " + journal [ 'journal' ] ;
2017-12-19 13:53:46 +01:00
} else {
available . downloadName = publisher ;
}
2020-03-16 14:09:46 +01:00
let url = "https://dx.doi.org/" + identifiers . get ( "doi" ) [ 0 ] ;
2017-12-19 13:53:46 +01:00
available . downloadUrl = new Array < string > ( ) ;
available . accessMode = new Array < string > ( ) ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
available . downloadUrl . push ( url ) ;
2020-07-01 14:11:57 +02:00
available . icon = this . unknown ;
2020-03-16 14:09:46 +01:00
/ *
if ( title != undefined && title [ 'url' ] == "" ) {
title [ 'url' ] = url ;
}
* /
2017-12-19 13:53:46 +01:00
hostedBy_collectedFrom . push ( available ) ;
}
return hostedBy_collectedFrom ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for downloadFrom
2020-03-16 14:09:46 +01:00
parseDownloadFrom ( downloadFrom : Map < string , { " url " : string [ ] , " accessMode " : string [ ] , " bestAccessMode " : string } > , instance : any , url : string ) {
2017-12-19 13:53:46 +01:00
let key : string = instance [ 'hostedby' ] . name ;
2020-03-16 14:09:46 +01:00
if ( key ) {
2017-12-19 13:53:46 +01:00
this . addUrlAndAccessMode ( downloadFrom , instance , key , url ) ;
}
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for publishedIn
2020-03-16 14:09:46 +01:00
parsePublishedIn ( publishedIn : Map < string , { " url " : string [ ] , " accessMode " : string [ ] , " bestAccessMode " : string } > , instance : any , result : any , url : string , counter : number ) : number {
if ( result != null && result . hasOwnProperty ( "source" ) ) {
2017-12-19 13:53:46 +01:00
let key : string ;
2020-03-16 14:09:46 +01:00
if ( Array . isArray ( result . source ) ) {
if ( counter == result . source . length ) {
2017-12-19 13:53:46 +01:00
counter -- ;
}
key = result [ 'source' ] [ counter ] ;
} else {
key = result [ 'source' ] ;
}
2020-03-16 14:09:46 +01:00
if ( key ) {
2017-12-19 13:53:46 +01:00
this . addUrlAndAccessMode ( publishedIn , instance , key , url ) ;
counter ++ ;
}
}
return counter ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for downloadFrom and publishedIn
2020-03-16 14:09:46 +01:00
addUrlAndAccessMode ( mapStructure : Map < string , { " url " : string [ ] , " accessMode " : string [ ] , " bestAccessMode " : string } > , instance : any , key : string , url : string ) {
if ( ! mapStructure . has ( key ) ) {
2017-12-19 13:53:46 +01:00
mapStructure . set ( key , { "url" : null , "accessMode" : null , "bestAccessMode" : null } ) ;
}
2020-03-16 14:09:46 +01:00
if ( mapStructure . get ( key ) [ 'url' ] == null ) {
2017-12-19 13:53:46 +01:00
mapStructure . get ( key ) [ 'url' ] = new Array < string > ( ) ;
}
2020-03-16 14:09:46 +01:00
if ( url ) {
2017-12-19 13:53:46 +01:00
mapStructure . get ( key ) [ 'url' ] . push ( url ) ;
}
2020-03-16 14:09:46 +01:00
if ( mapStructure . get ( key ) [ 'accessMode' ] == null ) {
2017-12-19 13:53:46 +01:00
mapStructure . get ( key ) [ 'accessMode' ] = new Array < string > ( ) ;
}
2020-03-16 14:09:46 +01:00
if ( instance . hasOwnProperty ( "accessright" ) ) {
if ( url ) {
mapStructure . get ( key ) [ 'accessMode' ] . push ( instance [ 'accessright' ] . classname ) ;
2017-12-19 13:53:46 +01:00
}
2020-03-16 14:09:46 +01:00
if ( this . changeBestAccessMode ( mapStructure . get ( key ) [ 'bestAccessMode' ] , instance [ 'accessright' ] ) ) {
mapStructure . get ( key ) [ 'bestAccessMode' ] = instance [ 'accessright' ] . classname ;
2017-12-19 13:53:46 +01:00
}
2020-03-16 14:09:46 +01:00
} else if ( url ) {
2017-12-19 13:53:46 +01:00
mapStructure . get ( key ) [ 'accessMode' ] . push ( "" ) ;
}
}
2020-03-16 14:09:46 +01:00
parseHostedBy_collectedFrom ( hostedBy_collectedFrom : HostedByCollectedFrom [ ] ,
2018-06-28 16:52:45 +02:00
instance : any , data : any , url : string , counter : number / * ,
title : { "name" : string , "url" : string , "accessMode" : string } * / , a c c e s s M o d e : s t r i n g ) : n u m b e r {
2020-03-16 14:09:46 +01:00
let available : HostedByCollectedFrom = {
"downloadName" : "" ,
"downloadUrl" : null ,
"collectedName" : "" ,
"collectedId" : "" ,
"accessMode" : null ,
"bestAccessMode" : null ,
"type" : "" ,
2020-07-01 14:11:57 +02:00
"year" : "" ,
"icon" : ""
2020-03-16 14:09:46 +01:00
} ;
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 -- ;
2018-06-28 16:52:45 +02:00
}
2020-03-16 14:09:46 +01:00
downloadName = data [ 'source' ] [ counter ] ;
} else {
downloadName = data [ 'source' ] ;
}
if ( downloadName ) {
counter ++ ;
available . downloadName = downloadName ;
}
}
2020-07-01 14:11:57 +02:00
2020-03-16 14:09:46 +01:00
}
2020-07-01 14:11:57 +02:00
if ( ! available . downloadName ) {
available . downloadName = url . substring ( 0 , 30 ) + '...' ; // substring(from, to);
}
2020-03-16 14:09:46 +01:00
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 < string > ( ) ;
available . downloadUrl = new Array < string > ( ) ;
available [ 'downloadUrl' ] . push ( url ) ;
if ( instance . hasOwnProperty ( "accessright" ) ) {
if ( url ) {
available [ 'accessMode' ] . push ( instance [ 'accessright' ] . classname ) ;
}
if ( this . changeBestAccessMode ( available . bestAccessMode , instance [ 'accessright' ] ) ) {
available . bestAccessMode = instance [ 'accessright' ] . classname ;
/ *
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' ] . classname ;
}
}
/ *
if ( title != undefined ) {
if ( ! title [ 'url' ] ) {
title [ 'url' ] = url ;
}
}
* /
} else if ( url ) {
available [ 'accessMode' ] . push ( "" ) ;
}
2020-07-01 14:11:57 +02:00
if ( available . bestAccessMode ) {
if ( available . bestAccessMode . toLowerCase ( ) . indexOf ( 'open' ) !== - 1 ) {
available . icon = this . open ;
} else if ( available . bestAccessMode . toLowerCase ( ) . indexOf ( 'not available' ) !== - 1 ) {
available . icon = this . unknown ;
} else {
available . icon = this . closed ;
}
} else {
available . icon = this . unknown ;
}
2020-03-16 14:09:46 +01:00
hostedBy_collectedFrom . push ( available ) ;
}
return counter ;
2017-12-19 13:53:46 +01:00
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for downloadFrom and publishedIn
changeBestAccessMode ( currentAccessMode : string , accessMode : any ) : boolean {
2020-03-16 14:09:46 +01:00
if ( ! accessMode ) {
2017-12-19 13:53:46 +01:00
return false ;
}
accessMode = accessMode . classid ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
switch ( currentAccessMode ) {
case null :
2020-03-16 14:09:46 +01:00
if ( accessMode != "UNKNOWN" ) {
2018-06-28 16:52:45 +02:00
return true ;
}
return false ;
2017-12-19 13:53:46 +01:00
case "CLOSED" :
2020-03-16 14:09:46 +01:00
if ( accessMode == "OPEN" ||
accessMode == "OPEN SOURCE" ||
accessMode == "EMBARGO" ||
accessMode == "RESTRICTED" ) {
return true ;
2017-12-19 13:53:46 +01:00
}
return false ;
case "RESTRICTED" :
2020-03-16 14:09:46 +01:00
if ( accessMode == "OPEN" ||
accessMode == "OPEN SOURCE" ||
accessMode == "EMBARGO" ) {
return true ;
2017-12-19 13:53:46 +01:00
}
return false ;
case "EMBARGO" :
2020-03-16 14:09:46 +01:00
if ( accessMode == "OPEN" ||
accessMode == "OPEN SOURCE" ) {
2017-12-19 13:53:46 +01:00
return true ;
2018-06-28 16:52:45 +02:00
}
return false ;
case "OPEN SOURCE" :
2020-03-16 14:09:46 +01:00
if ( accessMode == "OPEN" ) {
2018-06-28 16:52:45 +02:00
return true ;
}
return false ;
2017-12-19 13:53:46 +01:00
}
return false ;
}
2020-03-16 14:09:46 +01:00
2018-07-26 18:38:59 +02:00
// publication & dataset & software & orp landing : for relatedResearchResults
2020-03-16 14:09:46 +01:00
parseRelatedResearchResults ( relatedResearchResults : RelationResult [ ] , relation : any , provenanceAction : string ) :
RelationResult [ ] {
if ( relatedResearchResults == undefined ) {
relatedResearchResults = [ ]
2017-12-19 13:53:46 +01:00
}
2020-03-16 14:09:46 +01:00
relatedResearchResults . push ( this . parseRelatedOrSimilarResearchResult ( relation , "trust" , provenanceAction ) ) ;
2017-12-19 13:53:46 +01:00
return relatedResearchResults ;
}
2020-03-16 14:09:46 +01:00
2019-10-17 15:24:09 +02:00
// publication & dataset & software & orp landing : for supplementaryResearchResults
2020-03-16 14:09:46 +01:00
parseSupplementaryResearchResults ( supplementaryResearchResults : RelationResult [ ] , relation : any ) : RelationResult [ ] {
if ( supplementaryResearchResults == undefined ) {
supplementaryResearchResults = [ ] ;
2019-10-17 15:24:09 +02:00
}
supplementaryResearchResults . push ( this . parseRelatedOrSimilarResearchResult ( relation , "trust" ) ) ;
return supplementaryResearchResults ;
}
2020-03-16 14:09:46 +01:00
2019-10-17 15:24:09 +02:00
// publication & dataset & software & orp landing : for supplementedByResearchResults
2020-03-16 14:09:46 +01:00
parseSupplementedByResearchResults ( supplementedByResearchResults : RelationResult [ ] , relation : any ) : RelationResult [ ] {
if ( supplementedByResearchResults == undefined ) {
supplementedByResearchResults = [ ] ;
2019-10-17 15:24:09 +02:00
}
supplementedByResearchResults . push ( this . parseRelatedOrSimilarResearchResult ( relation , "trust" ) ) ;
return supplementedByResearchResults ;
}
2020-03-16 14:09:46 +01:00
2019-10-17 15:24:09 +02:00
// publication & dataset & software & orp landing : for similarResearchResults
2020-03-16 14:09:46 +01:00
parseSimilarResearchResults ( similarResearchResults : RelationResult [ ] , relation : any ) : RelationResult [ ] {
if ( similarResearchResults == undefined ) {
similarResearchResults = [ ] ;
2017-12-19 13:53:46 +01:00
}
2018-05-18 17:56:15 +02:00
similarResearchResults . push ( this . parseRelatedOrSimilarResearchResult ( relation , "similarity" ) ) ;
2017-12-19 13:53:46 +01:00
return similarResearchResults ;
}
2020-03-16 14:09:46 +01:00
2018-07-26 18:38:59 +02:00
// publication & dataset & software & orp landing : for relatedResearchResults and similarResearchResults
2020-03-16 14:09:46 +01:00
parseRelatedOrSimilarResearchResult ( relation : any , percentageName : string , provenanceAction : string = null ) : RelationResult {
let researchResult : RelationResult = {
name : "" ,
id : "" ,
date : "" ,
percentage : null ,
class : "" ,
provenanceAction : provenanceAction
} ;
2020-04-15 16:31:01 +02:00
if ( relation [ 'resulttype' ] ) {
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" ;
}
2017-12-19 13:53:46 +01:00
}
researchResult [ 'id' ] = relation [ 'to' ] . content ;
2020-04-15 16:31:01 +02:00
let titleName = Array . isArray ( relation [ 'title' ] ) ? relation [ 'title' ] [ 0 ] . content : ( relation [ 'title' ] ? relation [ 'title' ] . content :null ) ;
2017-12-19 13:53:46 +01:00
researchResult [ 'name' ] = titleName ;
2020-04-15 16:31:01 +02:00
if ( ! researchResult [ 'name' ] ) {
researchResult [ 'name' ] = "[no title available]" ;
}
2020-03-16 14:09:46 +01:00
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 ;
2018-06-28 16:52:45 +02:00
}
2017-12-19 13:53:46 +01:00
//researchResult['date'] = relation.dateofacceptance.substring(0,4);;
2020-03-16 14:09:46 +01:00
researchResult [ 'percentage' ] = Math . round ( relation [ percentageName ] * 100 ) ;
2017-12-19 13:53:46 +01:00
return researchResult ;
}
2020-03-16 14:09:46 +01:00
sortByPercentage ( results : RelationResult [ ] ) : RelationResult [ ] {
if ( results ) {
return results . sort ( function ( a , b ) {
return b [ "percentage" ] - a [ "percentage" ]
} ) ;
2018-05-21 14:31:19 +02:00
}
return results ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for identifiers
parseIdentifiers ( pid : any ) : Map < string , string [ ] > {
let identifiers = new Map < string , string [ ] > ( ) ;
2020-03-16 14:09:46 +01:00
if ( pid . hasOwnProperty ( "classname" ) && pid [ 'classname' ] != "" ) {
2020-04-27 10:14:05 +02:00
if ( pid . classname == "doi" || pid . classname == "pmc" || pid . classname == "handle" || pid . classname == "pmid" ) {
2020-03-16 14:09:46 +01:00
if ( ! identifiers . has ( pid . classname ) ) {
2017-12-19 13:53:46 +01:00
identifiers . set ( pid . classname , new Array < string > ( ) ) ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
identifiers . get ( pid . classname ) . push ( pid . content ) ;
}
} else {
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < pid . length ; i ++ ) {
2020-04-27 10:14:05 +02:00
if ( pid [ i ] . classname == "doi" || pid [ i ] . classname == "pmc" || pid [ i ] . classname == "handle" || pid [ i ] . classname == "pmid" ) {
2020-03-16 14:09:46 +01:00
if ( ! identifiers . has ( pid [ i ] . classname ) ) {
2017-12-19 13:53:46 +01:00
identifiers . set ( pid [ i ] . classname , new Array < string > ( ) ) ;
}
identifiers . get ( pid [ i ] . classname ) . push ( pid [ i ] . content ) ;
}
}
}
return identifiers ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
parseAllSubjects ( _subjects : any ) : [ string [ ] , Map < string , string [ ] > , Map < string , string [ ] > ] {
let subjects : string [ ] ;
let otherSubjects : Map < string , string [ ] > ;
let classifiedSubjects : Map < string , string [ ] > ;
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
let subject ;
let length = Array . isArray ( _subjects ) ? _subjects.length : 1 ;
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < length ; i ++ ) {
2017-12-19 13:53:46 +01:00
subject = Array . isArray ( _subjects ) ? _subjects [ i ] : _subjects ;
2020-03-16 14:09:46 +01:00
if ( subject . classid != "" ) {
if ( subject . inferred && subject . inferred == true ) {
if ( classifiedSubjects == undefined ) {
2017-12-19 13:53:46 +01:00
classifiedSubjects = new Map < string , string [ ] > ( ) ;
}
2020-03-16 14:09:46 +01:00
if ( ! classifiedSubjects . has ( subject . classname ) ) {
2017-12-19 13:53:46 +01:00
classifiedSubjects . set ( subject . classname , new Array < string > ( ) ) ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
classifiedSubjects . get ( subject . classname ) . push ( subject . content ) ;
} else {
2020-03-16 14:09:46 +01:00
if ( subject . classid == "keyword" ) {
if ( subjects == undefined ) {
2017-12-19 13:53:46 +01:00
subjects = new Array < string > ( ) ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
subjects . push ( subject . content ) ;
} else {
2020-03-16 14:09:46 +01:00
if ( otherSubjects == undefined ) {
2017-12-19 13:53:46 +01:00
otherSubjects = new Map < string , string [ ] > ( ) ;
}
2020-03-16 14:09:46 +01:00
if ( ! otherSubjects . has ( subject . classname ) ) {
2017-12-19 13:53:46 +01:00
otherSubjects . set ( subject . classname , new Array < string > ( ) ) ;
}
otherSubjects . get ( subject . classname ) . push ( subject . content ) ;
}
}
}
}
return [ subjects , otherSubjects , classifiedSubjects ] ;
}
2020-03-16 14:09:46 +01:00
parseContexts ( _contexts : any ) : {
"labelContext" : string , "labelCategory" : string ,
"labelConcept" : string , inline : boolean
} [ ] {
let contexts = new Array < {
"labelContext" : string , "labelCategory" : string ,
"labelConcept" : string , inline : boolean
} > ( ) ;
2017-12-19 13:53:46 +01:00
let position = 0 ;
let labels = "" ;
let context ;
let length = Array . isArray ( _contexts ) ? _contexts.length : 1 ;
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < length ; i ++ ) {
2017-12-19 13:53:46 +01:00
context = Array . isArray ( _contexts ) ? _contexts [ i ] : _contexts ;
2020-03-16 14:09:46 +01:00
if ( context . hasOwnProperty ( "type" ) && ( context [ 'type' ] == "community" || context [ 'type' ] == "ri" ) ) {
if ( context . hasOwnProperty ( "category" ) ) {
2019-08-30 15:39:54 +02:00
let category ;
let length2 = Array . isArray ( context [ 'category' ] ) ? context [ 'category' ] . length : 1 ;
for ( let z = 0 ; z < length2 ; z ++ ) {
category = Array . isArray ( context [ 'category' ] ) ? context [ 'category' ] [ z ] : context [ 'category' ] ;
if ( category . hasOwnProperty ( "concept" ) ) {
let categoryConcept ;
let length1 = Array . isArray ( category [ 'concept' ] ) ? category [ 'concept' ] . length : 1 ;
for ( let j = 0 ; j < length1 ; j ++ ) {
categoryConcept = Array . isArray ( category [ 'concept' ] ) ? category [ 'concept' ] [ j ] : category [ 'concept' ] ;
2020-03-16 14:09:46 +01:00
2019-08-30 15:39:54 +02:00
contexts [ position ] = { "labelContext" : "" , "labelCategory" : "" , "labelConcept" : "" , inline : false } ;
contexts [ position ] [ 'labelContext' ] = context . label ;
contexts [ position ] [ 'labelCategory' ] = category . label ;
contexts [ position ] [ 'labelConcept' ] = categoryConcept . label ;
2020-03-16 14:09:46 +01:00
2019-08-30 15:39:54 +02:00
position ++ ;
}
} else {
contexts [ position ] = { "labelContext" : "" , "labelCategory" : "" , "labelConcept" : "" , inline : false } ;
2017-12-19 13:53:46 +01:00
contexts [ position ] [ 'labelContext' ] = context . label ;
2019-08-30 15:39:54 +02:00
contexts [ position ] [ 'labelCategory' ] = category . label ;
contexts [ position ] [ 'labelConcept' ] = null ;
2017-12-19 13:53:46 +01:00
position ++ ;
}
}
2019-09-15 20:11:00 +02:00
} else {
contexts [ position ] = { "labelContext" : "" , "labelCategory" : "" , "labelConcept" : "" , inline : false } ;
contexts [ position ] [ 'labelContext' ] = context . label ;
contexts [ position ] [ 'labelCategory' ] = null ;
contexts [ position ] [ 'labelConcept' ] = null ;
contexts [ position ] [ 'new' ] = false ;
position ++ ;
2017-12-19 13:53:46 +01:00
}
}
}
return contexts ;
}
2020-03-16 14:09:46 +01:00
2017-12-19 13:53:46 +01:00
parseTypes ( types : string [ ] , uniqueTypes : Set < string > , instance : any ) {
2020-03-16 14:09:46 +01:00
if ( instance . hasOwnProperty ( "instancetype" ) && instance [ 'instancetype' ] . classname ) {
if ( ! uniqueTypes . has ( instance [ 'instancetype' ] . classname ) ) {
2017-12-19 13:53:46 +01:00
types . push ( instance [ 'instancetype' ] . classname ) ;
uniqueTypes . add ( instance [ 'instancetype' ] . classname ) ;
}
}
}
2020-03-16 14:09:46 +01:00
2018-02-13 15:52:23 +01:00
parseLanguages ( _languages : any ) {
var languages = new Array < string > ( ) ;
2020-03-16 14:09:46 +01:00
if ( ! Array . isArray ( _languages ) ) {
if ( _languages . classname != "Undetermined" && _languages . classname ) {
2018-02-13 15:52:23 +01:00
languages . push ( _languages . classname ) ;
}
} else {
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < _languages . length ; i ++ ) {
if ( _languages [ i ] . classname != "Undetermined" && _languages [ i ] . classname ) {
2018-02-13 15:52:23 +01:00
languages . push ( _languages [ i ] . classname ) ;
}
}
}
return languages ;
}
2020-03-16 14:09:46 +01:00
2018-06-28 16:52:45 +02:00
parseCountries ( _countries : any ) {
var countries = new Array < string > ( ) ;
2020-03-16 14:09:46 +01:00
if ( ! Array . isArray ( _countries ) ) {
if ( _countries . classname != "Undetermined" && _countries . classname ) {
2018-06-28 16:52:45 +02:00
countries . push ( _countries . classname ) ;
}
} else {
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < countries . length ; i ++ ) {
if ( _countries [ i ] . classname != "Undetermined" && _countries [ i ] . classname ) {
2018-06-28 16:52:45 +02:00
countries . push ( _countries [ i ] . classname ) ;
}
}
}
return countries ;
}
2020-03-16 14:09:46 +01:00
2018-06-28 16:52:45 +02:00
parseProgrammingLanguages ( _pLanguages ) {
var pLanguages = new Array < string > ( ) ;
2020-03-16 14:09:46 +01:00
if ( ! Array . isArray ( _pLanguages ) ) {
if ( _pLanguages . classname != "Undetermined" && _pLanguages . classname ) {
2018-06-28 16:52:45 +02:00
pLanguages . push ( _pLanguages . classname ) ;
}
} else {
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < _pLanguages . length ; i ++ ) {
if ( _pLanguages [ i ] . classname != "Undetermined" && _pLanguages [ i ] . classname ) {
2018-06-28 16:52:45 +02:00
pLanguages . push ( _pLanguages [ i ] . classname ) ;
}
}
}
return pLanguages ;
}
2020-03-16 14:09:46 +01:00
2020-03-17 18:48:02 +01:00
parseReferences ( citations : any ) : Reference [ ] {
let references : Reference [ ] = [ ] ;
citations = Array . isArray ( citations ) ? citations : [ citations ] ;
citations . forEach ( citation = > {
let reference : Reference = { name : null , ids : [ ] } ;
if ( citation . rawText ) {
reference . name = citation . rawText ;
2019-02-26 13:06:21 +01:00
}
2020-03-17 18:48:02 +01:00
if ( citation . id ) {
let ids : any [ ] = Array . isArray ( citation . id ) ? citation . id : [ citation . id ] ;
ids . forEach ( id = > {
reference . ids . push ( {
type : id . type ,
value : id.value ,
trust : id.confidenceLevel
} ) ;
} ) ;
}
references [ citation . position - 1 ] = reference ;
} ) ;
2019-02-26 13:06:21 +01:00
return references ;
}
2017-12-19 13:53:46 +01:00
}