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" ;
2021-07-14 13:19:57 +02:00
import { Injectable } from '@angular/core' ;
2021-11-09 22:04:01 +01:00
import { properties } from "../../../../environments/environment" ;
2017-12-19 13:53:46 +01:00
2021-07-14 13:19:57 +02:00
@Injectable ( {
providedIn : 'root'
} )
2017-12-19 13:53:46 +01:00
export class ParsingFunctions {
2021-09-23 16:49:41 +02:00
public notebookInSubjects : boolean = false ;
2021-09-27 11:14:17 +02:00
private notebookKeyword : string = "eosc jupyter notebook" ;
2021-09-29 13:34:03 +02:00
private notebook_label : string = "EOSC" ;
private notebook_value : string = "EOSC Jupyter Notebook" ;
2021-09-23 16:49:41 +02:00
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' ;
2021-11-09 22:04:01 +01:00
private instanceWithDoiExists : boolean = false ;
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" : "" ,
2021-05-13 17:48:01 +02:00
"funding" : "" , "code" : "" , "provenanceAction" : "" , "validated" : false
2020-03-16 14:09:46 +01:00
} ;
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 ;
2021-05-13 17:48:01 +02:00
if ( relation . validated && relation . validated . date ) {
fundedByProject [ 'validated' ] = true ;
}
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}*/ ) {
2021-11-09 22:04:01 +01:00
if ( ! this . instanceWithDoiExists && publisher && identifiers != null && identifiers . has ( 'doi' ) ) {
2020-03-16 14:09:46 +01:00
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 = {
2022-01-07 11:01:22 +01:00
downloadNames : [ ] ,
downloadUrl : "" ,
collectedNamesAndIds : null ,
accessRight : "" ,
types : [ ] ,
years : [ ] ,
accessRightIcon : ""
2020-03-16 14:09:46 +01:00
} ;
2022-01-07 11:01:22 +01:00
2020-03-16 14:09:46 +01:00
if ( journal && journal . journal ) {
2022-01-07 11:01:22 +01:00
available . downloadNames . push ( publisher + "/ " + journal [ 'journal' ] ) ;
2017-12-19 13:53:46 +01:00
} else {
2022-01-07 11:01:22 +01:00
available . downloadNames . push ( publisher ) ;
2017-12-19 13:53:46 +01:00
}
2020-07-01 14:11:57 +02:00
2022-01-07 11:01:22 +01:00
available . downloadUrl = properties . doiURL + identifiers . get ( "doi" ) [ 0 ] ; ;
available . accessRightIcon = 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 ( "" ) ;
}
}
2022-01-07 11:01:22 +01:00
2020-03-16 14:09:46 +01:00
parseHostedBy_collectedFrom ( hostedBy_collectedFrom : HostedByCollectedFrom [ ] ,
2022-01-07 11:01:22 +01:00
instance : any , url : string , globalAccessRight : string ) {
if ( ! url ) {
return ;
}
2020-03-16 14:09:46 +01:00
let available : HostedByCollectedFrom = {
2022-01-07 11:01:22 +01:00
"downloadNames" : [ ] ,
2020-03-16 14:09:46 +01:00
"downloadUrl" : null ,
2022-01-07 11:01:22 +01:00
"collectedNamesAndIds" : new Map ( ) ,
"accessRight" : null ,
"accessRightIcon" : "" ,
"types" : [ ] ,
"years" : [ ]
2020-03-16 14:09:46 +01:00
} ;
2020-07-01 14:11:57 +02:00
2022-01-07 11:01:22 +01:00
if ( instance . hasOwnProperty ( "hostedby" ) ) {
let downloadNames : Set < string > = new Set ( ) ;
let length = Array . isArray ( instance [ 'hostedby' ] ) ? instance [ 'hostedby' ] . length : 1 ;
for ( let i = 0 ; i < length ; i ++ ) {
let hostedBy = Array . isArray ( instance [ 'hostedby' ] ) ? instance [ 'hostedby' ] [ i ] : instance [ 'hostedby' ] ;
if ( hostedBy . name && hostedBy . name != "other resources" && hostedBy . name != "Unknown Repository" ) {
downloadNames . add ( hostedBy . name ) ;
}
2020-03-16 14:09:46 +01:00
}
2022-01-07 11:01:22 +01:00
available . downloadNames = Array . from ( downloadNames ) ;
if ( available . downloadNames . length == 0 ) {
available . downloadNames . push ( url . substring ( 0 , 30 ) + '...' ) ; // substring(from, to);
2020-03-16 14:09:46 +01:00
}
2022-01-07 11:01:22 +01:00
}
if ( instance . hasOwnProperty ( "collectedfrom" ) ) {
let length = Array . isArray ( instance [ 'collectedfrom' ] ) ? instance [ 'collectedfrom' ] . length : 1 ;
for ( let i = 0 ; i < length ; i ++ ) {
let collectedFrom = Array . isArray ( instance [ 'collectedfrom' ] ) ? instance [ 'collectedfrom' ] [ i ] : instance [ 'collectedfrom' ] ;
if ( collectedFrom . name && collectedFrom . id ) {
available . collectedNamesAndIds . set ( collectedFrom . name , collectedFrom . id ) ;
}
2021-11-09 22:04:01 +01:00
}
2022-01-07 11:01:22 +01:00
}
if ( instance . hasOwnProperty ( "instancetype" ) ) {
let types : Set < string > = new Set ( ) ;
let length = Array . isArray ( instance [ 'instancetype' ] ) ? instance [ 'instancetype' ] . length : 1 ;
for ( let i = 0 ; i < length ; i ++ ) {
let instanceType = Array . isArray ( instance [ 'instancetype' ] ) ? instance [ 'instancetype' ] [ i ] : instance [ 'instancetype' ] ;
if ( instanceType . classname && instanceType . classname . toLowerCase ( ) !== "unknown" ) {
types . add ( instanceType . classname ) ;
2020-03-16 14:09:46 +01:00
}
2022-01-07 11:01:22 +01:00
}
available . types = Array . from ( types ) ;
}
if ( instance . hasOwnProperty ( "dateofacceptance" ) ) {
let years : Set < string > = new Set ( ) ;
let length = Array . isArray ( instance [ 'dateofacceptance' ] ) ? instance [ 'dateofacceptance' ] . length : 1 ;
for ( let i = 0 ; i < length ; i ++ ) {
let dateOfAcceptance = Array . isArray ( instance [ 'dateofacceptance' ] ) ? instance [ 'dateofacceptance' ] [ i ] : instance [ 'dateofacceptance' ] ;
let date : string = ( dateOfAcceptance ) + "" ; // transform to string in case it is an integer
years . add ( ( date && ( date ) . indexOf ( '-' ) !== - 1 ) ? date . split ( '-' ) [ 0 ] : date ) ;
}
available . years = Array . from ( years ) ;
}
available [ 'downloadUrl' ] = url ;
if ( url . includes ( "doi.org/" ) ) {
this . instanceWithDoiExists = true ;
}
if ( instance . hasOwnProperty ( "accessright" ) ) {
let length = Array . isArray ( instance [ 'accessright' ] ) ? instance [ 'accessright' ] . length : 1 ;
for ( let i = 0 ; i < length ; i ++ ) {
let accessRight = Array . isArray ( instance [ 'accessright' ] ) ? instance [ 'accessright' ] [ i ] : instance [ 'accessright' ] ;
if ( this . changeBestAccessMode ( available . accessRight , accessRight ) ) {
available . accessRight = accessRight . classname ;
if ( this . changeBestAccessMode ( globalAccessRight , accessRight ) ) {
globalAccessRight = accessRight . classname ;
2020-03-16 14:09:46 +01:00
}
}
}
2020-07-01 14:11:57 +02:00
2022-01-07 11:01:22 +01:00
}
if ( available . accessRight ) {
if ( available . accessRight . toLowerCase ( ) . indexOf ( 'open' ) !== - 1 ) {
available . accessRightIcon = this . open ;
} else if ( available . accessRight . toLowerCase ( ) . indexOf ( 'not available' ) !== - 1 ) {
available . accessRightIcon = this . unknown ;
2020-07-01 14:11:57 +02:00
} else {
2022-01-07 11:01:22 +01:00
available . accessRightIcon = this . closed ;
2020-07-01 14:11:57 +02:00
}
2022-01-07 11:01:22 +01:00
} else {
available . accessRightIcon = this . unknown ;
2020-03-16 14:09:46 +01:00
}
2022-01-07 11:01:22 +01:00
hostedBy_collectedFrom . push ( available ) ;
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
2020-07-13 13:48:22 +02:00
if ( pid . hasOwnProperty ( "classid" ) && pid [ 'classid' ] != "" ) {
if ( pid . classid == "doi" || pid . classid == "pmc" || pid . classid == "handle" || pid . classid == "pmid" ) {
if ( ! identifiers . has ( pid . classid ) ) {
identifiers . set ( pid . classid , new Array < string > ( ) ) ;
2017-12-19 13:53:46 +01:00
}
2021-06-15 14:54:40 +02:00
identifiers . get ( pid . classid ) . push ( pid . content + "" ) ;
2017-12-19 13:53:46 +01:00
}
} else {
2020-03-16 14:09:46 +01:00
for ( let i = 0 ; i < pid . length ; i ++ ) {
2020-07-13 13:48:22 +02:00
if ( pid [ i ] . classid == "doi" || pid [ i ] . classid == "pmc" || pid [ i ] . classid == "handle" || pid [ i ] . classid == "pmid" ) {
if ( ! identifiers . has ( pid [ i ] . classid ) ) {
identifiers . set ( pid [ i ] . classid , new Array < string > ( ) ) ;
2017-12-19 13:53:46 +01:00
}
2021-06-15 14:54:40 +02:00
identifiers . get ( pid [ i ] . classid ) . push ( pid [ i ] . content + "" ) ;
2017-12-19 13:53:46 +01:00
}
}
}
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" ) {
2021-10-08 09:37:40 +02:00
let content : string = subject . content + "" ;
// console.log("keyword subject: "+content);
2021-09-27 11:14:17 +02:00
if ( content && content . toLowerCase ( ) . includes ( this . notebookKeyword ) ) {
// console.log("included in keyword subject: "+content);
2021-10-08 09:37:40 +02:00
// console.log("included");
2021-09-23 16:49:41 +02:00
this . notebookInSubjects = true ;
2021-09-29 13:34:03 +02:00
if ( classifiedSubjects == undefined ) {
classifiedSubjects = new Map < string , string [ ] > ( ) ;
}
if ( ! classifiedSubjects . has ( subject . classname ) ) {
classifiedSubjects . set ( this . notebook_label , new Array < string > ( ) ) ;
}
classifiedSubjects . get ( this . notebook_label ) . push ( this . notebook_value ) ;
} else {
if ( subjects == undefined ) {
subjects = new Array < string > ( ) ;
}
subjects . push ( content ) ;
2021-09-23 16:49:41 +02:00
}
2017-12-19 13:53:46 +01:00
} else {
2021-10-08 09:37:40 +02:00
let content : string = subject . content + "" ;
2021-10-26 14:32:32 +02:00
let classname : string = subject . classname + "" ;
2021-10-08 09:37:40 +02:00
// console.log("other subject: "+classname + ": " +content);
2021-09-27 11:14:17 +02:00
if ( ( content && content . toLowerCase ( ) . includes ( this . notebookKeyword ) ||
( classname && classname . toLowerCase ( ) . includes ( this . notebookKeyword ) ) ) ) {
// console.log("included in other subject: "+classname + ": "+content);
2021-10-08 09:37:40 +02:00
// console.log("included");
2021-09-27 11:14:17 +02:00
2021-09-23 16:49:41 +02:00
this . notebookInSubjects = true ;
2021-09-29 13:34:03 +02:00
if ( classifiedSubjects == undefined ) {
classifiedSubjects = new Map < string , string [ ] > ( ) ;
}
if ( ! classifiedSubjects . has ( subject . classname ) ) {
classifiedSubjects . set ( this . notebook_label , new Array < string > ( ) ) ;
}
classifiedSubjects . get ( this . notebook_label ) . push ( this . notebook_value ) ;
} else {
if ( otherSubjects == undefined ) {
otherSubjects = new Map < string , string [ ] > ( ) ;
}
if ( ! otherSubjects . has ( subject . classname ) ) {
otherSubjects . set ( subject . classname , new Array < string > ( ) ) ;
}
otherSubjects . get ( classname ) . push ( content ) ;
2021-09-23 16:49:41 +02:00
}
2017-12-19 13:53:46 +01:00
}
}
}
}
return [ subjects , otherSubjects , classifiedSubjects ] ;
}
2020-03-16 14:09:46 +01:00
parseContexts ( _contexts : any ) : {
2021-04-01 17:09:48 +02:00
"labelContext" : string , "idContext" : string ,
"labelCategory" : string , "idCategory" : string ,
2021-05-13 17:21:46 +02:00
"labelConcept" : string , "idConcept" : string
2020-03-16 14:09:46 +01:00
} [ ] {
let contexts = new Array < {
2021-04-01 17:09:48 +02:00
"labelContext" : string , "idContext" : string ,
"labelCategory" : string , "idCategory" : string ,
2021-05-13 17:21:46 +02:00
"labelConcept" : string , "idConcept" : string
2020-03-16 14:09:46 +01:00
} > ( ) ;
2021-10-11 13:02:22 +02:00
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 ++ ) {
2021-10-11 13:02:22 +02:00
let numOfCategories : number = 0 ; // count categories with label
2017-12-19 13:53:46 +01:00
context = Array . isArray ( _contexts ) ? _contexts [ i ] : _contexts ;
2020-03-16 14:09:46 +01:00
2021-10-11 13:02:22 +02:00
if ( context . label && context . hasOwnProperty ( "type" ) && ( context [ 'type' ] == "community" || context [ 'type' ] == "ri" ) ) {
2020-03-16 14:09:46 +01:00
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 ++ ) {
2021-10-11 13:02:22 +02:00
let numOfConcepts : number = 0 ; // count category concepts with label
2019-08-30 15:39:54 +02:00
category = Array . isArray ( context [ 'category' ] ) ? context [ 'category' ] [ z ] : context [ 'category' ] ;
2021-10-11 13:02:22 +02:00
if ( category . label && category . hasOwnProperty ( "concept" ) ) {
2019-08-30 15:39:54 +02:00
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' ] ;
2021-04-01 17:09:48 +02:00
2021-10-11 13:02:22 +02:00
// initalize if there is concept label or this is the last concept of the category and there were no concepts
// otherwise we could have multiple entries for the same category but without concepts
if ( categoryConcept . label || ( numOfConcepts == 0 && j == ( length1 - 1 ) ) ) {
contexts [ position ] = {
"labelContext" : "" , "idContext" : "" ,
"labelCategory" : "" , "idCategory" : "" ,
"labelConcept" : "" , "idConcept" : ""
} ;
contexts [ position ] [ 'labelContext' ] = context . label ;
contexts [ position ] [ 'idContext' ] = context . id ;
contexts [ position ] [ 'labelCategory' ] = category . label ;
contexts [ position ] [ 'idCategory' ] = category . id ;
contexts [ position ] [ 'labelConcept' ] = categoryConcept . label ? categoryConcept.label : null ;
contexts [ position ] [ 'idConcept' ] = categoryConcept . label ? categoryConcept.id : null ;
position ++ ;
numOfConcepts ++ ;
}
2019-08-30 15:39:54 +02:00
}
2021-10-11 13:02:22 +02:00
} else if ( category . label || ( numOfCategories == 0 && z == ( length2 - 1 ) ) ) {
2021-04-01 17:09:48 +02:00
contexts [ position ] = { "labelContext" : "" , "idContext" : "" ,
"labelCategory" : "" , "idCategory" : "" ,
2021-05-13 17:21:46 +02:00
"labelConcept" : "" , "idConcept" : "" } ;
2017-12-19 13:53:46 +01:00
contexts [ position ] [ 'labelContext' ] = context . label ;
2021-04-01 17:09:48 +02:00
contexts [ position ] [ 'idContext' ] = context . id ;
2021-10-11 13:02:22 +02:00
contexts [ position ] [ 'labelCategory' ] = category . label ? category.label : null ;
contexts [ position ] [ 'idCategory' ] = category . label ? category.id : null ;
2019-08-30 15:39:54 +02:00
contexts [ position ] [ 'labelConcept' ] = null ;
2021-04-01 17:09:48 +02:00
contexts [ position ] [ 'idConcept' ] = null ;
2017-12-19 13:53:46 +01:00
position ++ ;
2021-10-11 13:02:22 +02:00
numOfCategories ++ ;
2017-12-19 13:53:46 +01:00
}
}
2019-09-15 20:11:00 +02:00
} else {
2021-04-01 17:09:48 +02:00
contexts [ position ] = { "labelContext" : "" , "idContext" : "" ,
"labelCategory" : "" , "idCategory" : "" ,
2021-05-13 17:21:46 +02:00
"labelConcept" : "" , "idConcept" : "" } ;
2019-09-15 20:11:00 +02:00
contexts [ position ] [ 'labelContext' ] = context . label ;
2021-04-01 17:09:48 +02:00
contexts [ position ] [ 'idContext' ] = context . id ;
2019-09-15 20:11:00 +02:00
contexts [ position ] [ 'labelCategory' ] = null ;
2021-04-01 17:09:48 +02:00
contexts [ position ] [ 'idCategory' ] = null ;
2019-09-15 20:11:00 +02:00
contexts [ position ] [ 'labelConcept' ] = null ;
2021-04-01 17:09:48 +02:00
contexts [ position ] [ 'idConcept' ] = null ;
2019-09-15 20:11:00 +02:00
contexts [ position ] [ 'new' ] = false ;
position ++ ;
2017-12-19 13:53:46 +01:00
}
}
}
return contexts ;
}
2021-04-02 11:17:00 +02:00
public static getEnermapsConceptId ( contexts : any ) : string {
2021-06-16 10:19:16 +02:00
let enermapsconcepts = contexts . filter ( c = > { return c . idCategory == "enermaps::selection" && c . idConcept } ) ;
return enermapsconcepts && enermapsconcepts . length > 0 ? enermapsconcepts [ 0 ] . idConcept . split ( "enermaps::selection::" ) [ 1 ] : null ;
// return "hotmaps_heat_tot_curr_density"
2021-04-02 11:17:00 +02:00
}
2017-12-19 13:53:46 +01:00
parseTypes ( types : string [ ] , uniqueTypes : Set < string > , instance : any ) {
2020-08-06 09:24:44 +02:00
if ( instance && instance . hasOwnProperty ( "instancetype" ) && instance [ 'instancetype' ] . classname ) {
2020-03-16 14:09:46 +01:00
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 > ( ) ;
2021-04-01 17:09:48 +02:00
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 ;
}
2020-08-19 13:01:22 +02:00
static parseRelCanonicalId ( record , type ) {
try {
if ( record [ "result" ] [ "metadata" ] [ "oaf:entity" ] [ ( "oaf:" + type ) ] [ "children" ] && record [ "result" ] [ "metadata" ] [ "oaf:entity" ] [ ( "oaf:" + type ) ] [ "children" ] [ type ] ) {
for ( let child of record [ "result" ] [ "metadata" ] [ "oaf:entity" ] [ ( "oaf:" + type ) ] [ "children" ] [ type ] ) {
return child [ "objidentifier" ] ;
}
}
} catch ( e ) {
// console.error(e);
}
return record [ "result" ] [ "header" ] [ "dri:objIdentifier" ] ;
}
2017-12-19 13:53:46 +01:00
}