2023-02-17 18:40:05 +01:00
import { HostedByCollectedFrom , Project , RelationResult } from "../../utils/result-preview/result-preview" ;
import { Context , Measure , Metric , 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" ;
2022-02-14 16:04:09 +01:00
import { StringUtils } from "../../utils/string-utils.class" ;
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 {
2023-02-16 15:33:40 +01:00
public eoscSubjects = [
{
label : 'EOSC::Jupyter Notebook' ,
link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AJupyter+Notebook' ,
value : 'Jupyter Notebook'
} ,
{
label : 'EOSC::RO-crate' ,
link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'marketplace.eosc-portal.eu/datasources/eosc.psnc.6f0470e3bb9203ec3a7553f3a72a7a1f?q=ROHub' ,
value : 'RO-crate'
} ,
{
label : 'EOSC::Galaxy Workflow' ,
link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3AGalaxy+Workflow' ,
value : 'Galaxy Workflow'
} ,
{
label : 'EOSC::Twitter Data' ,
link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'marketplace.eosc-portal.eu/services?tag=EOSC%3A%3ATwitter+Data' ,
value : 'Twitter Data'
}
]
2023-02-17 18:40:05 +01:00
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" ;
2023-02-17 18:40:05 +01:00
2023-01-23 15:19:00 +01:00
public open = 'open_access' ;
public closed = 'closed_access' ;
2023-05-08 09:53:38 +02:00
public unknown = 'unknown_access' ;
2021-11-09 22:04:01 +01:00
private instanceWithDoiExists : boolean = false ;
2023-02-17 18:40:05 +01:00
2020-03-16 14:09:46 +01:00
constructor ( ) {
}
2023-02-17 18:40:05 +01:00
2020-03-16 14:09:46 +01:00
public ngOnDestroy() {
}
2023-02-17 18:40:05 +01:00
2022-09-06 15:28:51 +02:00
public parseFundingByProjects ( fundedByProjects : Project [ ] , relation : any ) : Project [ ] {
2020-03-16 14:09:46 +01:00
if ( fundedByProjects == undefined ) {
fundedByProjects = [ ] ;
}
2023-02-17 18:40:05 +01:00
2020-03-16 14:09:46 +01:00
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
} ;
2023-02-17 18:40:05 +01:00
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 ;
2023-02-16 15:33:40 +01:00
if ( relation . validated && relation . validated . date ) {
2021-05-13 17:48:01 +02:00
fundedByProject [ 'validated' ] = true ;
}
2023-02-16 15:33:40 +01:00
fundedByProject [ 'provenanceAction' ] = relation . provenanceaction ;
2017-12-19 13:53:46 +01:00
} else {
fundedByProject [ 'id' ] = "" ;
fundedByProject [ 'acronym' ] = "" ;
fundedByProject [ 'title' ] = "" ;
fundedByProject [ 'code' ] = "" ;
fundedByProject [ 'provenanceAction' ] = "" ;
}
2023-02-17 18:40:05 +01:00
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 ) ;
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +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 ;
2023-02-17 18:40:05 +01:00
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 ;
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel0 ( fundingData , funding . stream ) ;
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel1 ( fundingData , funding . stream ) ;
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
funding . stream = this . addFundingLevel2 ( fundingData , funding . stream ) ;
}
return funding ;
}
2023-02-17 18:40:05 +01:00
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' ] ;
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " ; " : "" ;
fundingStream += level0 . name ;
}
return fundingStream ;
}
2023-02-17 18:40:05 +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' ] ;
2023-02-17 18:40:05 +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 ) ;
}
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " | " : "" ;
fundingStream += level1 . name ;
}
return fundingStream ;
}
2023-02-17 18:40:05 +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' ] ;
2023-02-17 18:40:05 +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 ) ;
}
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
fundingStream += ( fundingStream ) ? " | " : "" ;
fundingStream += level2 . name ;
}
return fundingStream ;
}
2023-02-17 18:40:05 +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 ;
}
2023-02-17 18:40:05 +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 [ ] ,
2023-02-16 15:33:40 +01:00
publisher : string , journal : string ,
2020-03-16 14:09:46 +01:00
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
} ;
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
if ( 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
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
available . downloadUrl = properties . doiURL + identifiers . get ( "doi" ) [ 0 ] ;
2023-05-08 09:53:38 +02:00
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 ;
}
2023-02-17 18:40:05 +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 ;
2023-02-17 18:40:05 +01:00
2020-03-16 14:09:46 +01:00
if ( key ) {
2017-12-19 13:53:46 +01:00
this . addUrlAndAccessMode ( downloadFrom , instance , key , url ) ;
}
}
2023-02-17 18:40:05 +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' ] ;
}
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +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 } ) ;
}
2023-02-17 18:40:05 +01:00
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 > ( ) ;
}
2023-02-17 18:40:05 +01:00
2020-03-16 14:09:46 +01:00
if ( url ) {
2017-12-19 13:53:46 +01:00
mapStructure . get ( key ) [ 'url' ] . push ( url ) ;
}
2023-02-17 18:40:05 +01:00
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 > ( ) ;
}
2023-02-17 18:40:05 +01:00
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
}
2023-02-17 18:40:05 +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 ( "" ) ;
}
}
2023-02-17 18:40:05 +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 ) {
2023-02-16 15:33:40 +01:00
if ( ! url ) {
2022-01-07 11:01:22 +01:00
return ;
}
2023-02-17 18:40:05 +01:00
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" : [ ] ,
2022-06-09 15:45:39 +02:00
"years" : [ ] ,
"license" : ""
2020-03-16 14:09:46 +01:00
} ;
2023-05-08 09:53:38 +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" ) {
2022-09-16 15:12:58 +02:00
downloadNames . add ( String ( hostedBy . name ) ) ;
2022-01-07 11:01:22 +01:00
}
2020-03-16 14:09:46 +01:00
}
2022-01-07 11:01:22 +01:00
available . downloadNames = Array . from ( downloadNames ) ;
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
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
}
2023-02-17 18:40:05 +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' ] ;
2023-02-16 15:33:40 +01:00
if ( collectedFrom . name && collectedFrom . id ) {
2022-09-16 15:12:58 +02:00
available . collectedNamesAndIds . set ( String ( collectedFrom . name ) , collectedFrom . id ) ;
2022-01-07 11:01:22 +01:00
}
2021-11-09 22:04:01 +01:00
}
2022-01-07 11:01:22 +01:00
}
2023-02-17 18:40:05 +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' ] ;
2023-02-16 15:33:40 +01:00
if ( instanceType . classname && instanceType . classname . toLowerCase ( ) !== "unknown" ) {
2022-01-07 11:01:22 +01:00
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 ) ;
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
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 ) ;
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
available [ 'downloadUrl' ] = url ;
2023-02-16 15:33:40 +01:00
if ( url . includes ( "doi.org/" ) ) {
2022-01-07 11:01:22 +01:00
this . instanceWithDoiExists = true ;
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
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' ] ;
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
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
}
}
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
}
2023-05-08 09:53:38 +02:00
2022-01-07 11:01:22 +01:00
if ( available . accessRight ) {
if ( available . accessRight . toLowerCase ( ) . indexOf ( 'open' ) !== - 1 ) {
available . accessRightIcon = this . open ;
2023-05-08 09:53:38 +02:00
}
else if ( available . accessRight . toLowerCase ( ) . indexOf ( 'not available' ) !== - 1 ) {
available . accessRightIcon = this . unknown ;
}
2023-03-31 12:28:35 +02:00
else {
2022-01-07 11:01:22 +01:00
available . accessRightIcon = this . closed ;
2020-07-01 14:11:57 +02:00
}
2023-05-08 09:53:38 +02:00
} else {
available . accessRightIcon = this . unknown ;
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
if ( instance . hasOwnProperty ( "license" ) ) {
2022-06-09 15:45:39 +02:00
available . license = Array . isArray ( instance [ 'license' ] ) ? instance [ 'license' ] [ 0 ] : instance [ 'license' ] ;
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:01:22 +01:00
hostedBy_collectedFrom . push ( available ) ;
2017-12-19 13:53:46 +01:00
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
compareHostedByCollectedFrom ( a : HostedByCollectedFrom , b : HostedByCollectedFrom ) {
let firstAccessRight : string = ( a . accessRight ? a . accessRight . toLowerCase ( ) : null ) ;
let secondAccessRight : string = ( b . accessRight ? b . accessRight . toLowerCase ( ) : null ) ;
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
if ( firstAccessRight === secondAccessRight ) {
return 0 ;
} else {
if ( firstAccessRight === 'open access' ) {
return - 1 ;
} else if ( secondAccessRight === 'open access' ) {
return 1 ;
} else if ( firstAccessRight === "open source" ) {
return - 1 ;
} else if ( secondAccessRight === "open source" ) {
return 1 ;
} else if ( firstAccessRight === "embargo" ) {
return - 1 ;
} else if ( secondAccessRight === "embargo" ) {
return 1 ;
} else if ( firstAccessRight === "restricted" ) {
return - 1 ;
} else if ( secondAccessRight === "restricted" ) {
return 1 ;
} else if ( firstAccessRight === "closed access" ) {
return - 1 ;
} else if ( secondAccessRight === "closed access" ) {
return 1 ;
} else if ( firstAccessRight === "not available" ) {
return - 1 ;
} else if ( secondAccessRight === "not available" ) {
return 1 ;
}
}
return 0 ;
}
2023-02-17 18:40:05 +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 ;
2023-02-17 18:40:05 +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" ||
2023-02-17 18:40:05 +01:00
accessMode == "OPEN SOURCE" ||
accessMode == "EMBARGO" ||
accessMode == "RESTRICTED" ) {
2020-03-16 14:09:46 +01:00
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" ||
2023-02-17 18:40:05 +01:00
accessMode == "OPEN SOURCE" ||
accessMode == "EMBARGO" ) {
2020-03-16 14:09:46 +01:00
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" ||
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +01:00
2018-07-26 18:38:59 +02:00
// publication & dataset & software & orp landing : for relatedResearchResults
2022-08-03 17:21:14 +02:00
parseResults ( researchResults : RelationResult [ ] , relation , provenanceAction : string , relationName : string ) : RelationResult [ ] {
2022-01-07 11:16:23 +01:00
if ( researchResults == undefined ) {
researchResults = [ ] ;
}
2023-02-17 18:40:05 +01:00
2022-01-07 11:16:23 +01:00
let researchResult : RelationResult = {
name : "" ,
id : "" ,
date : "" ,
percentage : null ,
percentageName : null ,
class : "" ,
provenanceAction : provenanceAction ,
2022-08-03 17:21:14 +02:00
relationName : relationName
2022-01-07 11:16:23 +01:00
} ;
2023-02-17 18:40:05 +01:00
2022-08-03 17:21:14 +02:00
// researchResult.relationName = relation.to.class;
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
if ( relation [ 'resulttype' ] ) {
2022-01-07 11:16:23 +01:00
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 ;
2023-02-16 15:33:40 +01:00
if ( Array . isArray ( relation [ 'title' ] ) ) {
for ( let i = 0 ; i < relation [ 'title' ] . length ; i ++ ) {
if ( relation [ 'title' ] [ i ] && relation [ 'title' ] [ i ] . content ) {
if ( ! researchResult [ 'name' ] || relation [ 'title' ] [ i ] . classid == "main title" ) {
2022-09-15 15:28:25 +02:00
researchResult [ 'name' ] = String ( relation [ 'title' ] [ i ] . content ) ;
}
}
}
} else {
researchResult [ 'name' ] = ( relation [ 'title' ] && relation [ 'title' ] . content ) ? String ( relation [ 'title' ] . content ) : "" ;
}
2023-02-16 15:33:40 +01:00
if ( ! researchResult [ 'name' ] ) {
2022-01-07 11:16:23 +01:00
researchResult [ 'name' ] = "[no title available]" ;
}
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);;
let percentageName : string ;
2023-02-16 15:33:40 +01:00
if ( relation . trust ) {
2022-01-07 11:16:23 +01:00
percentageName = "trust" ;
2023-02-16 15:33:40 +01:00
} else if ( relation . similarity ) {
2022-01-07 11:16:23 +01:00
percentageName = "similarity" ;
}
2023-02-16 15:33:40 +01:00
if ( percentageName ) {
2022-01-07 11:16:23 +01:00
researchResult [ 'percentage' ] = Math . round ( relation [ percentageName ] * 100 ) ;
researchResult [ 'percentageName' ] = percentageName ;
}
researchResults . push ( researchResult ) ;
return researchResults ;
}
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +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 [ ] > ( ) ;
2023-02-17 18:40:05 +01:00
2020-07-13 13:48:22 +02:00
if ( pid . hasOwnProperty ( "classid" ) && pid [ 'classid' ] != "" ) {
2022-05-16 16:01:35 +02:00
if ( pid . classid == "doi" || pid . classid == "pmc" || pid . classid == "handle" || pid . classid == "pmid" || pid . classid == "re3data" ) {
2020-07-13 13:48:22 +02:00
if ( ! identifiers . has ( pid . classid ) ) {
identifiers . set ( pid . classid , new Array < string > ( ) ) ;
2017-12-19 13:53:46 +01:00
}
2023-02-16 15:33:40 +01: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 ++ ) {
2022-05-16 16:01:35 +02:00
if ( pid [ i ] . classid == "doi" || pid [ i ] . classid == "pmc" || pid [ i ] . classid == "handle" || pid [ i ] . classid == "pmid" || pid [ i ] . classid == "re3data" ) {
2020-07-13 13:48:22 +02:00
if ( ! identifiers . has ( pid [ i ] . classid ) ) {
identifiers . set ( pid [ i ] . classid , new Array < string > ( ) ) ;
2017-12-19 13:53:46 +01:00
}
2023-02-16 15:33:40 +01:00
identifiers . get ( pid [ i ] . classid ) . push ( pid [ i ] . content + "" ) ;
2017-12-19 13:53:46 +01:00
}
}
}
return identifiers ;
}
2023-02-17 18:40:05 +01:00
2022-08-30 10:35:42 +02:00
// publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
parseEoscSubjects ( _subjects : any ) : any [ ] {
let eoscSubjectsFound = [ ] ;
let setOfEoscSubjects : Set < string > = new Set ( ) ;
2023-02-17 18:40:05 +01:00
2022-08-30 10:35:42 +02:00
let subject ;
let length = Array . isArray ( _subjects ) ? _subjects.length : 1 ;
2023-02-17 18:40:05 +01:00
2022-08-30 10:35:42 +02:00
for ( let i = 0 ; i < length ; i ++ ) {
subject = Array . isArray ( _subjects ) ? _subjects [ i ] : _subjects ;
2023-02-16 15:33:40 +01:00
let content : string = subject . code + "" ;
2022-08-30 10:35:42 +02:00
let checkAndAddEoscSubjectResp = this . checkAndAddEoscSubject ( setOfEoscSubjects , eoscSubjectsFound , subject , content ) ;
let found : boolean = checkAndAddEoscSubjectResp [ "found" ] ;
2023-02-16 15:33:40 +01:00
if ( found ) {
2022-08-30 10:35:42 +02:00
setOfEoscSubjects = checkAndAddEoscSubjectResp [ "setOfEoscSubject" ] ;
eoscSubjectsFound = checkAndAddEoscSubjectResp [ "eoscSubjectsFound" ] ;
}
}
2023-02-17 18:40:05 +01:00
2022-08-30 10:35:42 +02:00
return eoscSubjectsFound ;
}
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
// publication & dataset landing : for subjects and otherSubjects and classifiedSubjects
2023-02-16 15:33:40 +01:00
parseAllSubjects ( _subjects : any , vocabulary : any ) : [ string [ ] , Map < string , string [ ] > , Map < string , string [ ] > , string [ ] , string [ ] , ] {
2022-09-30 13:51:00 +02:00
// let eoscSubjectsFound = [];
2017-12-19 13:53:46 +01:00
let subjects : string [ ] ;
let otherSubjects : Map < string , string [ ] > ;
let classifiedSubjects : Map < string , string [ ] > ;
2022-03-15 22:31:10 +01:00
let fos : string [ ] ;
let sdg : string [ ] ;
2023-02-17 18:40:05 +01:00
2022-05-31 17:08:05 +02:00
let setOfEoscSubjects : Set < string > = new Set ( ) ;
2023-02-17 18:40:05 +01:00
2017-12-19 13:53:46 +01:00
let subject ;
let length = Array . isArray ( _subjects ) ? _subjects.length : 1 ;
2023-02-17 18:40:05 +01:00
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 != "" ) {
2022-06-09 15:45:39 +02:00
if ( subject . classid == "keyword" ) {
2023-02-16 15:33:40 +01:00
let content : string = subject . content + "" ;
2022-09-30 13:51:00 +02:00
// let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content);
// let found: boolean = checkAndAddEoscSubjectResp["found"];
// if(found) {
// setOfEoscSubjects = checkAndAddEoscSubjectResp["setOfEoscSubject"];
// eoscSubjectsFound = checkAndAddEoscSubjectResp["eoscSubjectsFound"];
// } else {
if ( subjects == undefined ) {
subjects = new Array < string > ( ) ;
2022-06-09 15:45:39 +02:00
}
2022-09-30 13:51:00 +02:00
subjects . push ( content ) ;
// }
2022-06-09 15:45:39 +02:00
} else if ( ! vocabulary || vocabulary [ subject . classid ] || subject . classid === "SDG" || subject . classid === "FOS" ) {
2022-09-30 13:51:00 +02:00
// if (subject.inferred && subject.inferred == true) {
2023-02-16 15:33:40 +01:00
if ( subject . classid === "SDG" ) {
2022-03-15 22:31:10 +01:00
if ( sdg == undefined ) {
sdg = new Array < string > ( ) ;
}
2023-02-16 15:33:40 +01:00
sdg . push ( subject . content + "" ) ;
} else if ( subject . classid === "FOS" ) {
2022-03-15 22:31:10 +01:00
if ( fos == undefined ) {
fos = new Array < string > ( ) ;
}
2023-02-16 15:33:40 +01:00
fos . push ( subject . content + "" ) ;
2022-03-15 22:31:10 +01:00
} else {
if ( classifiedSubjects == undefined ) {
classifiedSubjects = new Map < string , string [ ] > ( ) ;
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
let content : string = subject . content + "" ;
2022-09-30 13:51:00 +02:00
// let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content);
// let found: boolean = checkAndAddEoscSubjectResp["found"];
// if(found) {
// setOfEoscSubjects = checkAndAddEoscSubjectResp["setOfEoscSubject"];
// eoscSubjectsFound = checkAndAddEoscSubjectResp["eoscSubjectsFound"];
// } else {
if ( ! classifiedSubjects . has ( subject . classname ) ) {
classifiedSubjects . set ( subject . classname , new Array < string > ( ) ) ;
}
classifiedSubjects . get ( subject . classname ) . push ( content ) ;
// }
2017-12-19 13:53:46 +01:00
}
} else {
2023-02-16 15:33:40 +01:00
let content : string = subject . content + "" ;
2022-09-30 13:51:00 +02:00
// let checkAndAddEoscSubjectResp = this.checkAndAddEoscSubject(setOfEoscSubjects, eoscSubjectsFound, subject, content);
// let found: boolean = checkAndAddEoscSubjectResp["found"];
// if(found) {
// setOfEoscSubjects = checkAndAddEoscSubjectResp["setOfEoscSubject"];
// eoscSubjectsFound = checkAndAddEoscSubjectResp["eoscSubjectsFound"];
// } else {
let classname : string = subject . classname + "" ;
if ( subjects == undefined ) {
subjects = new Array < string > ( ) ;
2017-12-19 13:53:46 +01:00
}
2022-09-30 13:51:00 +02:00
subjects . push ( content ) ;
// }
2017-12-19 13:53:46 +01:00
}
}
}
2022-09-30 13:51:00 +02:00
return [ subjects , otherSubjects , classifiedSubjects , fos , sdg ] ;
2017-12-19 13:53:46 +01:00
}
2023-02-17 18:40:05 +01:00
2022-08-30 10:35:42 +02:00
checkAndAddEoscSubject ( setOfEoscSubjects : Set < string > , eoscSubjectsFound , subject , content ) {
2022-05-31 17:08:05 +02:00
let found : boolean = false ;
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
if ( ! setOfEoscSubjects . has ( content ) ) {
2022-05-31 17:08:05 +02:00
// looping through our declared array
this . eoscSubjects . forEach ( item = > {
if ( content && content == item . label ) {
found = true ;
2022-06-01 14:29:19 +02:00
eoscSubjectsFound . push ( item ) ;
2022-05-31 17:08:05 +02:00
setOfEoscSubjects . add ( content ) ;
}
} ) ;
}
2022-08-30 10:35:42 +02:00
return { "found" : found , "setOfEoscSubject" : setOfEoscSubjects , "eoscSubjectsFound" : eoscSubjectsFound } ;
2022-05-31 17:08:05 +02:00
}
2023-02-17 18:40:05 +01:00
2022-04-12 14:01:45 +02:00
parseContexts ( _contexts : any ) : Context [ ] {
let contexts = new Array < Context > ( ) ;
2023-02-17 18:40:05 +01: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 ;
2023-02-17 18:40:05 +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' ] ;
2023-02-17 18:40:05 +01: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
2023-02-16 15:33:40 +01:00
if ( categoryConcept . label || ( numOfConcepts == 0 && j == ( length1 - 1 ) ) ) {
2021-10-11 13:02:22 +02:00
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 ;
2023-02-17 18:40:05 +01:00
2021-10-11 13:02:22 +02:00
position ++ ;
numOfConcepts ++ ;
}
2019-08-30 15:39:54 +02:00
}
2023-02-16 15:33:40 +01:00
} else if ( category . label || ( numOfCategories == 0 && z == ( length2 - 1 ) ) ) {
contexts [ position ] = {
"labelContext" : "" , "idContext" : "" ,
"labelCategory" : "" , "idCategory" : "" ,
"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 {
2023-02-16 15:33:40 +01:00
contexts [ position ] = {
"labelContext" : "" , "idContext" : "" ,
"labelCategory" : "" , "idCategory" : "" ,
"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 ;
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
public static getEnermapsConceptId ( contexts : any ) : string {
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 ;
2021-06-16 10:19:16 +02:00
// return "hotmaps_heat_tot_curr_density"
2021-04-02 11:17:00 +02:00
}
2023-02-17 18:40:05 +01: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 ) ;
}
}
}
2023-02-17 18:40:05 +01:00
2018-02-13 15:52:23 +01:00
parseLanguages ( _languages : any ) {
var languages = new Array < string > ( ) ;
2023-02-17 18:40:05 +01: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 ;
}
2023-02-17 18:40:05 +01:00
2018-06-28 16:52:45 +02:00
parseCountries ( _countries : any ) {
var countries = new Array < string > ( ) ;
2023-02-17 18:40:05 +01:00
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 {
2023-03-01 15:49:42 +01:00
for ( let i = 0 ; i < _countries . length ; i ++ ) {
2020-03-16 14:09:46 +01:00
if ( _countries [ i ] . classname != "Undetermined" && _countries [ i ] . classname ) {
2018-06-28 16:52:45 +02:00
countries . push ( _countries [ i ] . classname ) ;
}
}
}
return countries ;
}
2023-02-17 18:40:05 +01:00
2018-06-28 16:52:45 +02:00
parseProgrammingLanguages ( _pLanguages ) {
var pLanguages = new Array < string > ( ) ;
2023-02-17 18:40:05 +01:00
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 ;
}
2023-02-17 18:40:05 +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 : [ ] } ;
2023-02-16 15:33:40 +01:00
if ( citation . rawText ) {
2020-03-17 18:48:02 +01:00
reference . name = citation . rawText ;
2019-02-26 13:06:21 +01:00
}
2023-02-16 15:33:40 +01:00
if ( citation . id ) {
2020-03-17 18:48:02 +01:00
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 ;
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01: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 ] ) {
2020-08-19 13:01:22 +02:00
return child [ "objidentifier" ] ;
}
}
2023-02-16 15:33:40 +01:00
} catch ( e ) {
2020-08-19 13:01:22 +02:00
// console.error(e);
}
2023-02-16 15:33:40 +01:00
return record [ "result" ] [ "header" ] [ "dri:objIdentifier" ] ;
2023-02-17 18:40:05 +01:00
2020-08-19 13:01:22 +02:00
}
2023-02-17 18:40:05 +01:00
2023-02-16 15:33:40 +01:00
parseDescription ( description , stripHTML : boolean = false ) : string {
2022-02-14 16:04:09 +01:00
let abstracts = [ ] ;
2023-02-16 15:33:40 +01:00
if ( ! Array . isArray ( description ) ) {
2022-02-14 16:04:09 +01:00
abstracts = [ description ? String ( description ) : "" ] ;
} else {
2023-02-16 15:33:40 +01:00
abstracts = description . map ( x = > String ( x ) ) ;
}
try {
abstracts = abstracts . map ( x = > StringUtils . HTMLToString ( x ) ) ;
} catch ( e ) {
}
abstracts = abstracts . sort ( ( a , b ) = > b . length - a . length ) ;
if ( stripHTML ) {
return abstracts . join ( ' ' ) ;
} else {
return abstracts . length > 0 ? ( '<p>' + abstracts . join ( '</p> <p>' ) + '</p>' ) : abstracts . join ( ' ' ) ;
}
}
2023-02-17 18:40:05 +01:00
parseMeasures ( elements : any [ ] ) : Measure {
if ( elements && elements . length ) {
let bip : Metric [ ] = [ ] ;
let counts : Metric [ ] = [ ] ;
let measure : Measure = { } ;
elements . forEach ( element = > {
if ( element . id == 'views' ) {
counts . push ( { name : 'views' , icon : 'visibility' , value : element.count , order : 0 } ) ;
measure . views = element . count ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
if ( element . id == 'downloads' ) {
counts . push ( { name : 'downloads' , icon : 'download' , value : element.count , order : 1 } ) ;
measure . downloads = element . count ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
if ( element . id == 'influence_alt' ) {
bip . push ( { name : 'citations' , icon : 'cite' , value : element.score , order : 2 } ) ;
measure . citations = element . score ;
}
if ( element . id == 'popularity' ) {
let metric : Metric = { name : 'popularity' , icon : 'fire' , value : null , order : 3 } ;
if ( element . class == 'C1' ) {
metric . value = 'Top 0.01%' ;
} else if ( element . class == 'C2' ) {
metric . value = 'Top 0.1%' ;
} else if ( element . class == 'C3' ) {
metric . value = 'Top 1%' ;
} else if ( element . class == 'C4' ) {
metric . value = 'Top 10%' ;
} else if ( element . class == 'A' ) {
metric . value = 'Exceptional' ;
} else if ( element . class == 'B' ) {
metric . value = 'Substantial' ;
2023-02-16 15:33:40 +01:00
} else {
2023-02-17 18:40:05 +01:00
metric . value = 'Average' ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
measure . popularity = metric . value ;
bip . push ( metric ) ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
if ( element . id == 'influence' ) {
let metric : Metric = { name : 'influence' , icon : 'landmark' , value : null , order : 4 } ;
if ( element . class == 'C1' ) {
metric . value = 'Top 0.01%' ;
} else if ( element . class == 'C2' ) {
metric . value = 'Top 0.1%' ;
} else if ( element . class == 'C3' ) {
metric . value = 'Top 1%' ;
} else if ( element . class == 'C4' ) {
metric . value = 'Top 10%' ;
} else if ( element . class == 'A' ) {
metric . value = 'Exceptional' ;
} else if ( element . class == 'B' ) {
metric . value = 'Substantial' ;
2023-02-16 15:33:40 +01:00
} else {
2023-02-17 18:40:05 +01:00
metric . value = 'Average' ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
measure . influence = metric . value ;
bip . push ( metric ) ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
if ( element . id == 'impulse' ) {
let metric : Metric = { name : 'impulse' , icon : 'rocket' , value : null , order : 5 } ;
if ( element . class == 'C1' ) {
metric . value = 'Top 0.01%' ;
} else if ( element . class == 'C2' ) {
metric . value = 'Top 0.1%' ;
} else if ( element . class == 'C3' ) {
metric . value = 'Top 1%' ;
} else if ( element . class == 'C4' ) {
metric . value = 'Top 10%' ;
} else if ( element . class == 'A' ) {
metric . value = 'Exceptional' ;
} else if ( element . class == 'B' ) {
metric . value = 'Substantial' ;
2023-02-16 15:33:40 +01:00
} else {
2023-02-17 18:40:05 +01:00
metric . value = 'Average' ;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
measure . impulse = metric . value ;
bip . push ( metric ) ;
2023-02-16 15:33:40 +01:00
}
} ) ;
2023-02-17 18:40:05 +01:00
measure . bip = bip . sort ( ( a , b ) = > a . order - b . order ) ;
measure . counts = counts . sort ( ( a , b ) = > a . order - b . order ) ;
return measure ;
2023-02-16 15:33:40 +01:00
}
return null ;
2022-02-14 16:04:09 +01:00
}
2017-12-19 13:53:46 +01:00
}