2024-07-01 22:35:47 +02:00
import {
HostedByCollectedFrom ,
Project ,
RelationDatasource ,
RelationResult
} from "../../utils/result-preview/result-preview" ;
2023-11-08 15:57:56 +01:00
import { Context , Measure , Metric , MetricPerDatasource , 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 {
2022-05-12 13:05:54 +02:00
public eoscSubjects = [
2023-12-12 10:59:25 +01:00
{ label : 'EOSC::Jupyter Notebook' , link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'search.marketplace.eosc-portal.eu/search/service?q=*&fq=eosc_if:%22Jupyter%20Notebook%22' , value : 'Jupyter Notebook' } ,
{ label : 'EOSC::RO-crate' , link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'search.marketplace.eosc-portal.eu/search/service?q=*&fq=eosc_if:%22RO%5C-crate%22' , value : 'RO-crate' } ,
{ label : 'EOSC::Galaxy Workflow' , link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'search.marketplace.eosc-portal.eu/search/service?q=*&fq=eosc_if:%22Galaxy%20Workflow%22' , value : 'Galaxy Workflow' } ,
{ label : 'EOSC::Twitter Data' , link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'search.marketplace.eosc-portal.eu/search/service?q=*&fq=eosc_if:%22Twitter%20Data%22' , value : 'Twitter Data' } ,
{ label : 'EOSC::Data Cube' , link : 'https://' + ( properties . environment != 'production' ? 'beta.' : '' ) + 'search.marketplace.eosc-portal.eu/search/service?q=*&fq=eosc_if:%22Data%20Cube%22' , value : 'Data Cube' }
2022-05-12 13:05:54 +02: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" : "" ,
2024-05-29 12:05:04 +02:00
"funderShortname" : "" , "funderName" : "" , "funderJurisdiction" : "" ,
2021-05-13 17:48:01 +02:00
"funding" : "" , "code" : "" , "provenanceAction" : "" , "validated" : false
2020-03-16 14:09:46 +01:00
} ;
2024-03-04 12:14:09 +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" ) ) {
2024-05-29 12:05:04 +02:00
let 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 ;
}
2024-05-29 12:05:04 +02:00
if ( funding . funderJurisdiction ) {
fundedByProject [ 'funderJurisdiction' ] = funding . funderJurisdiction ;
}
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
2024-05-29 12:05:04 +02:00
public parseFundingTrees ( fundingTree : any ) : any {
let funding : { "funderName" : string , "funderShortname" : string , "funderJurisdiction" : string , "stream" : string } = {
2020-03-16 14:09:46 +01:00
"funderName" : "" ,
"funderShortname" : "" ,
2024-05-29 12:05:04 +02:00
"funderJurisdiction" : "" ,
2020-03-16 14:09:46 +01:00
"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 ;
2024-05-29 12:05:04 +02:00
funding . funderJurisdiction = fundingData [ 'funder' ] . jurisdiction ;
2017-12-19 13:53:46 +01:00
}
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" : [ ] ,
2023-10-11 11:46:10 +02:00
"license" : "" ,
2023-12-20 22:55:00 +01:00
"fulltext" : "" ,
"peerReviewed" : null
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-10-11 11:46:10 +02:00
if ( instance . hasOwnProperty ( "fulltext" ) ) {
available . fulltext = instance [ 'fulltext' ] ;
}
2023-12-20 22:55:00 +01:00
if ( instance . hasOwnProperty ( "refereed" ) && instance . refereed . classname == "peerReviewed" ) {
available . peerReviewed = true ;
}
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 ) {
2023-10-11 11:46:10 +02:00
let retValue : number = 0 ;
2023-02-16 15:33:40 +01:00
let firstAccessRight : string = ( a . accessRight ? a . accessRight . toLowerCase ( ) : null ) ;
let secondAccessRight : string = ( b . accessRight ? b . accessRight . toLowerCase ( ) : null ) ;
2023-10-11 11:46:10 +02:00
if ( firstAccessRight !== secondAccessRight ) {
2023-02-16 15:33:40 +01:00
if ( firstAccessRight === 'open access' ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === 'open access' ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
2023-02-16 15:33:40 +01:00
} else if ( firstAccessRight === "open source" ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === "open source" ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
2023-02-16 15:33:40 +01:00
} else if ( firstAccessRight === "embargo" ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === "embargo" ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
2023-02-16 15:33:40 +01:00
} else if ( firstAccessRight === "restricted" ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === "restricted" ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
2023-02-16 15:33:40 +01:00
} else if ( firstAccessRight === "closed access" ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === "closed access" ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
2023-02-16 15:33:40 +01:00
} else if ( firstAccessRight === "not available" ) {
2023-10-11 11:46:10 +02:00
retValue = - 1 ;
2023-02-16 15:33:40 +01:00
} else if ( secondAccessRight === "not available" ) {
2023-10-11 11:46:10 +02:00
retValue = 1 ;
}
}
if ( retValue == 0 ) {
let firstFulltext : string = ( a . fulltext ? a.fulltext : null ) ;
let secondFulltext : string = ( b . fulltext ? b.fulltext : null ) ;
if ( firstFulltext && ! secondFulltext ) {
return - 1 ;
} else if ( ! firstFulltext && secondFulltext ) {
2023-02-16 15:33:40 +01:00
return 1 ;
}
2023-10-11 11:46:10 +02:00
} else {
return retValue ;
2023-02-16 15:33:40 +01:00
}
2023-10-11 11:46:10 +02:00
2023-02-16 15:33:40 +01:00
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 ;
}
2024-07-01 22:35:47 +02:00
// publication & dataset & software & orp landing : for relatedResearchResults
parseDatasources ( datasources : RelationDatasource [ ] , relation , provenanceAction : string , relationName : string ) : RelationDatasource [ ] {
let datasource : RelationDatasource = {
name : "" ,
id : "" ,
percentage : null ,
percentageName : null ,
class : "" ,
provenanceAction : provenanceAction ,
relationName : relationName ,
openaireCompatibility : ""
} ;
datasource [ 'id' ] = relation [ 'to' ] . content ;
if ( relation [ "officialname" ] )
datasource . name = relation . officialname ;
else {
datasource [ 'name' ] = "[no title available]" ;
}
let percentageName : string ;
if ( relation . trust ) {
percentageName = "trust" ;
} else if ( relation . similarity ) {
percentageName = "similarity" ;
}
if ( percentageName ) {
datasource [ 'percentage' ] = Math . round ( relation [ percentageName ] * 100 ) ;
datasource [ 'percentageName' ] = percentageName ;
}
// type
if ( relation . hasOwnProperty ( 'datasourcetype' ) && relation [ 'datasourcetype' ] . hasOwnProperty ( "classname" ) ) {
datasource . class = relation [ 'datasourcetype' ] . classname ;
}
// compatibility
if ( relation . hasOwnProperty ( "openairecompatibility" ) ) {
datasource . openaireCompatibility = relation [ 'openairecompatibility' ] . classname ;
}
if ( datasource . class !== "service" || properties . adminToolsPortalType == "eosc" ) {
if ( datasources == undefined ) {
datasources = [ ] ;
}
datasources . push ( datasource ) ;
}
return datasources ;
}
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' ] != "" ) {
2023-10-06 11:22:00 +02:00
if ( pid . classid == "doi" || pid . classid == "pmc" || pid . classid == "handle" || pid . classid == "pmid" || pid . classid == "re3data"
2024-03-04 12:14:09 +01:00
|| pid . classid == "swhid"
|| pid . classid == "ROR" || pid . classid == "ISNI" || pid . classid == "Wikidata" || pid . classid == "FundRef" ) {
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 ++ ) {
2023-10-06 11:22:00 +02:00
if ( pid [ i ] . classid == "doi" || pid [ i ] . classid == "pmc" || pid [ i ] . classid == "handle" || pid [ i ] . classid == "pmid" || pid [ i ] . classid == "re3data"
2024-03-04 12:14:09 +01:00
|| pid [ i ] . classid == "swhid"
|| pid [ i ] . classid == "ROR" || pid [ i ] . classid == "ISNI" || pid [ i ] . classid == "Wikidata" || pid [ i ] . classid == "FundRef" ) {
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 ;
}
2024-04-24 15:06:45 +02: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 [ ] ;
2024-04-24 15:06:45 +02:00
2022-05-31 17:08:05 +02:00
let setOfEoscSubjects : Set < string > = new Set ( ) ;
2024-04-24 15:06:45 +02:00
2017-12-19 13:53:46 +01:00
let subject ;
let length = Array . isArray ( _subjects ) ? _subjects.length : 1 ;
2024-04-24 15:06:45 +02: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 [ ] > ( ) ;
}
2024-04-24 15:06:45 +02: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 > ( ) ) ;
}
2024-04-24 15:06:45 +02:00
if ( properties . environment == "production" ) {
classifiedSubjects . get ( subject . classname ) . push ( content ) ;
} else {
classifiedSubjects . get ( subject . classname ) . push ( subject . classid + ": " + content ) ;
}
2022-09-30 13:51:00 +02:00
// }
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
}
}
}
2024-04-24 15:06:45 +02:00
2024-04-24 15:35:13 +02:00
if ( properties . environment != "production" && classifiedSubjects != null ) {
2024-05-20 14:17:26 +02:00
if ( subjects == undefined ) {
subjects = new Array < string > ( ) ;
}
2024-04-24 15:06:45 +02:00
for ( let classified of classifiedSubjects . keys ( ) ) {
subjects = subjects . concat ( classifiedSubjects . get ( classified ) ) ;
}
classifiedSubjects = null ;
}
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 [ ] = [ ] ;
2023-11-08 15:57:56 +01:00
let countsPerDatasource : MetricPerDatasource [ ] = [ ] ;
2023-02-17 18:40:05 +01:00
let measure : Measure = { } ;
2023-11-08 15:57:56 +01:00
let datasourcePosition : Map < string , number > = new Map < string , number > ( ) ;
let views : number = 0 ;
let downloads : number = 0 ;
2023-02-17 18:40:05 +01:00
elements . forEach ( element = > {
if ( element . id == 'views' ) {
2023-11-08 15:57:56 +01:00
views += element . count ;
let datasourceId = element . datasource ;
if ( datasourceId ) {
if ( datasourcePosition . has ( element . datasource ) ) {
countsPerDatasource [ datasourcePosition . get ( element . datasource ) ] . views = element . count ;
} else {
datasourcePosition . set ( element . datasource , countsPerDatasource . length ) ;
2023-11-27 17:10:37 +01:00
countsPerDatasource . push ( { "datasourceId" : element . datasource . split ( "||" ) [ 0 ] , "datasourceName" : element . datasource . split ( "||" ) [ 1 ] , "views" : element . count , "downloads" : 0 } )
2023-11-08 15:57:56 +01:00
}
}
// measure.views = element.count;
2023-02-16 15:33:40 +01:00
}
2023-02-17 18:40:05 +01:00
if ( element . id == 'downloads' ) {
2023-11-08 15:57:56 +01:00
downloads += element . count ;
let datasourceId = element . datasource ;
if ( datasourceId ) {
if ( datasourcePosition . has ( element . datasource ) ) {
countsPerDatasource [ datasourcePosition . get ( element . datasource ) ] . downloads = element . count ;
} else {
datasourcePosition . set ( element . datasource , countsPerDatasource . length ) ;
2023-11-27 17:10:37 +01:00
countsPerDatasource . push ( { "datasourceId" : element . datasource . split ( "||" ) [ 0 ] , "datasourceName" : element . datasource . split ( "||" ) [ 1 ] , "views" : 0 , "downloads" : element . count } )
2023-11-08 15:57:56 +01:00
}
}
// measure.downloads = element.count;
2023-02-16 15:33:40 +01:00
}
2023-10-25 10:51:44 +02:00
if ( element . id == 'influence_alt' || element . id == 'citation_count' ) {
2023-02-17 18:40:05 +01:00
bip . push ( { name : 'citations' , icon : 'cite' , value : element.score , order : 2 } ) ;
2023-11-08 15:57:56 +01:00
// measure.citations = element.score;
2023-02-17 18:40:05 +01:00
}
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%' ;
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-11-08 15:57:56 +01:00
// measure.popularity = metric.value;
2023-02-17 18:40:05 +01:00
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%' ;
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-11-08 15:57:56 +01:00
// measure.influence = metric.value;
2023-02-17 18:40:05 +01:00
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%' ;
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-11-08 15:57:56 +01:00
// measure.impulse = metric.value;
2023-02-17 18:40:05 +01:00
bip . push ( metric ) ;
2023-02-16 15:33:40 +01:00
}
} ) ;
2023-11-08 15:57:56 +01:00
if ( views > 0 ) {
counts . push ( { name : 'views' , icon : 'visibility' , value : views , order : 0 } ) ;
}
if ( downloads > 0 ) {
counts . push ( { name : 'downloads' , icon : 'download' , value : downloads , order : 1 } ) ;
}
if ( countsPerDatasource && countsPerDatasource . length > 0 ) {
measure . countsPerDatasource = countsPerDatasource ;
}
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
}