2021-07-14 13:19:57 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Citation, Dataset, Identifier, License, Organization, Person} from '../model/jsonld-document';
|
|
|
|
import * as _ from 'lodash';
|
|
|
|
import {properties} from '../../../../../environments/environment';
|
2018-05-17 10:29:22 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class OpenAireJsonldConverterService {
|
|
|
|
|
2020-07-15 15:59:09 +02:00
|
|
|
constructor() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-10 17:14:48 +02:00
|
|
|
createHome(name, URL, logoURL, description:string, searchActionRoute ): any {
|
2020-07-15 15:59:09 +02:00
|
|
|
const organization = {};
|
|
|
|
organization["@context"] = "http://schema.org";
|
2020-08-10 17:14:48 +02:00
|
|
|
organization["@id"] = URL+"/#organization";
|
2020-07-15 15:59:09 +02:00
|
|
|
organization["@type"] = "Organization";
|
|
|
|
organization["name"] = name;
|
2020-08-10 17:14:48 +02:00
|
|
|
organization["url"] = URL;
|
2020-08-11 14:39:55 +02:00
|
|
|
if(logoURL && logoURL.length > 0 ) {
|
|
|
|
organization["logo"] = logoURL;
|
|
|
|
}
|
2020-07-15 15:59:09 +02:00
|
|
|
if(description){
|
|
|
|
organization["description"] = description;
|
|
|
|
}
|
2020-09-18 09:57:42 +02:00
|
|
|
if((properties.domain.indexOf("connect.openaire.eu")!=-1 || properties.domain.indexOf("explore.openaire.eu")!=-1|| properties.domain.indexOf("monitor.openaire.eu")!=-1) && properties.baseLink == "/") {
|
2020-08-10 17:14:48 +02:00
|
|
|
const sameAs = ["https://www.openaire.eu",
|
|
|
|
"https://www.facebook.com/groups/openaire/",
|
|
|
|
"https://www.twitter.com/OpenAIRE_eu",
|
|
|
|
"https://www.linkedin.com/groups/OpenAIRE-3893548",
|
|
|
|
"https://www.slideshare.net/OpenAIRE_eu",
|
|
|
|
"https://www.youtube.com/channel/UChFYqizc-S6asNjQSoWuwjw"];
|
|
|
|
organization["sameAs"] = sameAs;
|
|
|
|
}
|
|
|
|
if(searchActionRoute) {
|
|
|
|
return [organization, this.createDefaultSearchPage(name, URL,logoURL,description,searchActionRoute)];
|
|
|
|
}
|
|
|
|
return organization;
|
|
|
|
}
|
|
|
|
createDefaultSearchPage(name, URL, logoURL, description:string, searchRoute ){
|
|
|
|
const searchPage = {};
|
2020-07-15 15:59:09 +02:00
|
|
|
searchPage["@context"] = "http://schema.org";
|
2020-08-10 17:14:48 +02:00
|
|
|
searchPage["@id"] = URL + "/#search";
|
2020-07-15 15:59:09 +02:00
|
|
|
searchPage["@type"] = "Website";
|
|
|
|
searchPage["name"] = name;
|
2020-08-10 17:14:48 +02:00
|
|
|
searchPage["url"] = URL + searchRoute;
|
2021-06-04 10:18:01 +02:00
|
|
|
/* no valid property for Website
|
2020-09-18 15:26:15 +02:00
|
|
|
if(logoURL && logoURL.length > 0 ) {
|
|
|
|
searchPage["logo"] = logoURL;
|
2021-06-04 10:18:01 +02:00
|
|
|
}*/
|
2020-08-10 17:14:48 +02:00
|
|
|
if (description) {
|
2020-07-21 14:41:08 +02:00
|
|
|
searchPage["description"] = description;
|
|
|
|
}
|
2020-08-10 17:14:48 +02:00
|
|
|
const action = {};
|
|
|
|
action["@type"] = "SearchAction";
|
|
|
|
action["@id"] = URL + "/#search-action";
|
|
|
|
action["target"] = URL+ searchRoute + "?fv0={search_term_string}&f0=q";
|
|
|
|
action["query-input"] = "required name=search_term_string";
|
2018-11-12 16:36:20 +01:00
|
|
|
|
2020-07-15 15:59:09 +02:00
|
|
|
searchPage["potentialAction"] = action;
|
2020-08-10 17:14:48 +02:00
|
|
|
return searchPage;
|
2018-11-12 16:36:20 +01:00
|
|
|
}
|
2020-07-15 15:59:09 +02:00
|
|
|
createSimplePage(name, URL, description:string = null): any {
|
2018-11-13 14:01:38 +01:00
|
|
|
const buffer = {};
|
|
|
|
buffer["@context"] = "http://schema.org";
|
2018-11-14 11:38:53 +01:00
|
|
|
buffer["@type"] = "WebPage";
|
|
|
|
buffer["name"] = name;
|
|
|
|
buffer["url"] = URL;
|
2020-07-15 15:59:09 +02:00
|
|
|
if(description){
|
|
|
|
buffer["description"] = description;
|
2020-07-21 14:41:08 +02:00
|
|
|
}else{
|
|
|
|
buffer["description"] = name;
|
|
|
|
}
|
|
|
|
buffer["@id"] = URL;
|
2018-11-14 11:38:53 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
2020-08-10 17:14:48 +02:00
|
|
|
createSearchPage(name, URL, logoURL, searchAction:boolean = true, description:string = null, searchActionRoute = null): any {
|
2018-11-14 11:38:53 +01:00
|
|
|
const buffer = {};
|
|
|
|
buffer["@context"] = "http://schema.org";
|
|
|
|
buffer["@type"] = "SearchResultsPage";
|
2018-11-13 14:01:38 +01:00
|
|
|
buffer["name"] = name;
|
2020-07-15 15:59:09 +02:00
|
|
|
if(description){
|
|
|
|
buffer["description"] = description;
|
|
|
|
}
|
2018-11-13 14:01:38 +01:00
|
|
|
buffer["url"] = URL;
|
2020-07-15 15:59:09 +02:00
|
|
|
buffer["@id"] = URL;
|
2018-11-13 14:01:38 +01:00
|
|
|
buffer["logo"] = logoURL;
|
2020-09-18 09:57:42 +02:00
|
|
|
buffer["isPartOf"] = properties.domain+ properties.baseLink +"/#search";
|
2020-08-10 17:14:48 +02:00
|
|
|
if(searchAction){
|
|
|
|
return [buffer,this.createDefaultSearchPage(name, URL,logoURL,description,searchActionRoute) ]
|
|
|
|
}
|
2018-11-13 14:01:38 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
2018-11-12 16:36:20 +01:00
|
|
|
convertResult(result: any, URL): Dataset {
|
|
|
|
const doc = new Dataset();
|
2018-05-17 10:29:22 +02:00
|
|
|
|
|
|
|
doc.title = this.getTitle(result);
|
2018-11-13 14:01:38 +01:00
|
|
|
doc.headline = doc.title;
|
|
|
|
if(this.getSubTitle(result)){
|
|
|
|
doc.alternativeHeadline = this.getSubTitle(result);
|
|
|
|
}
|
|
|
|
doc.issn = this.getISSN(result);
|
2018-05-17 10:29:22 +02:00
|
|
|
doc.description = this.getDescription(result);
|
|
|
|
doc.identifier = this.getIdentifier(result);
|
2020-07-21 14:41:08 +02:00
|
|
|
doc.id = URL;
|
2018-07-06 14:13:37 +02:00
|
|
|
doc.url = URL;
|
2018-05-17 10:29:22 +02:00
|
|
|
doc.sameAs = this.getSameAs(result);
|
|
|
|
doc.creator = this.getCreator(result);
|
|
|
|
doc.dateCreated = this.getDateCreated(result);
|
|
|
|
doc.citation = this.getCitation(result);
|
|
|
|
doc.license = this.getLicense(result);
|
|
|
|
doc.keyword = this.getKeyword(result);
|
2018-11-12 16:36:20 +01:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2020-07-21 14:41:08 +02:00
|
|
|
convertProject(project: any, URL): Organization {
|
2018-11-12 16:36:20 +01:00
|
|
|
const doc = new Organization();
|
2020-03-16 14:09:46 +01:00
|
|
|
doc.title = (project.title)?project.title:project.acronym;
|
2018-11-12 16:36:20 +01:00
|
|
|
doc.identifier = new Array<Identifier>();
|
2020-03-16 14:09:46 +01:00
|
|
|
doc.identifier.push({id:project.funding.code, schema: "grantid"});
|
2020-07-21 14:41:08 +02:00
|
|
|
let funder = new Organization();
|
2020-09-18 09:57:42 +02:00
|
|
|
funder.id = properties.domain + properties.baseLink+"#funder-"+project.funding.funderShortName;
|
2020-07-21 14:41:08 +02:00
|
|
|
funder.title = project.funding.funderName;
|
2018-11-12 16:36:20 +01:00
|
|
|
doc.funder = funder;
|
|
|
|
doc.url = URL;
|
2020-07-21 14:41:08 +02:00
|
|
|
doc.id = URL;
|
|
|
|
doc["description"] = [];
|
2020-09-15 12:01:19 +02:00
|
|
|
doc["description"].push(project.description?project.description: ("project" + (project.title?"," + project.title:"") + (project.funding && project.funding.funderName?", funder: " + project.funding.funderName:"") + (project.acronym?"," + project.acronym:"")));
|
2020-03-16 14:09:46 +01:00
|
|
|
doc.sameAs =[project.url];
|
2018-05-17 10:29:22 +02:00
|
|
|
return doc;
|
2018-11-12 16:36:20 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 14:41:08 +02:00
|
|
|
convertOrganization(organization: any, URL, description:string = null): Organization {
|
2018-11-12 16:36:20 +01:00
|
|
|
const doc = new Organization();
|
|
|
|
|
|
|
|
doc.title = organization.title.name ;
|
|
|
|
doc.legalName = organization.name;
|
|
|
|
doc.areaServed = organization.country;
|
|
|
|
doc.url = URL;
|
2020-07-21 14:41:08 +02:00
|
|
|
doc.id = URL;
|
|
|
|
doc["description"] = [];
|
|
|
|
doc["description"].push(((organization.title.name?organization.title.name:"") + " - " + (organization.name?organization.name:"")));
|
2018-11-12 16:36:20 +01:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertDatasource(datasource: any, URL, otherUrl): Organization {
|
|
|
|
const doc = new Organization();
|
|
|
|
|
2020-07-21 14:41:08 +02:00
|
|
|
doc.title = datasource.title.name?datasource.title.name:datasource.officialName;
|
2020-03-16 14:09:46 +01:00
|
|
|
//doc.identifier = datasource.contractNum;
|
2018-11-12 16:36:20 +01:00
|
|
|
doc.legalName = datasource.officialName;
|
|
|
|
if(datasource.countries && datasource.countries.length > 0){
|
|
|
|
doc.areaServed = datasource.countries[0];
|
|
|
|
}
|
|
|
|
doc.url = URL;
|
2020-07-21 14:41:08 +02:00
|
|
|
doc.id = URL;
|
|
|
|
doc["description"] = [];
|
|
|
|
doc["description"].push(datasource.description?datasource.description:datasource.title.name?datasource.title.name:datasource.officialName);
|
|
|
|
|
2018-11-12 16:36:20 +01:00
|
|
|
if(datasource.oaiPmhURL || otherUrl || datasource.title.url){
|
|
|
|
doc.sameAs = [];
|
|
|
|
if(otherUrl){
|
|
|
|
doc.sameAs.push(otherUrl);
|
|
|
|
}
|
|
|
|
if(datasource.oaiPmhURL){
|
|
|
|
doc.sameAs.push(datasource.oaiPmhURL);
|
|
|
|
|
|
|
|
}
|
|
|
|
if(datasource.title.url){
|
|
|
|
doc.sameAs.push(datasource.title.url);
|
|
|
|
}
|
2018-05-17 10:29:22 +02:00
|
|
|
}
|
2018-11-12 16:36:20 +01:00
|
|
|
return doc;
|
|
|
|
}
|
2018-05-17 10:29:22 +02:00
|
|
|
|
|
|
|
private getTitle(result: any): String[] {
|
2018-11-13 14:01:38 +01:00
|
|
|
const title = _.get(result, "result.metadata.oaf:entity.oaf:result.title", null);
|
2021-02-20 10:20:05 +01:00
|
|
|
let return_title;
|
2018-11-13 14:01:38 +01:00
|
|
|
if(title && Array.isArray(title) ){
|
2021-02-20 10:20:05 +01:00
|
|
|
for(let i=0; i<title.length; i++) {
|
|
|
|
if(title[i] && title[i].content) {
|
|
|
|
if(!return_title || title[i].classid == "main title") {
|
|
|
|
return_title = String(title[i].content);
|
|
|
|
}
|
|
|
|
if(title[i].classid == "main title") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!return_title) {
|
|
|
|
return_title = "";
|
|
|
|
}
|
|
|
|
return return_title;
|
|
|
|
// return (title[0] && title[0].content)?title[0].content:"";
|
2018-11-13 14:01:38 +01:00
|
|
|
}else{
|
2020-05-14 16:38:50 +02:00
|
|
|
return (title && title.content)?title.content:"";
|
2018-11-13 14:01:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private getSubTitle(result: any): String[] {
|
|
|
|
const title = _.get(result, "result.metadata.oaf:entity.oaf:result.title", null);
|
|
|
|
if(title && Array.isArray(title) ){
|
|
|
|
if(title[1] && title[1].classid == "subtitle") {
|
|
|
|
return title[1].content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
private getISSN(result: any): String[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.journal.issn", null);
|
2018-05-17 10:29:22 +02:00
|
|
|
if (!item) return null;
|
|
|
|
return [item as String];
|
|
|
|
}
|
|
|
|
private getDescription(result: any): String[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.description", null);
|
2020-07-15 15:59:09 +02:00
|
|
|
if (!item) return this.getTitle(result);
|
2020-09-16 15:27:13 +02:00
|
|
|
let descr = Array.isArray(item) ? item[0]+ "":item + ""; // +"" to make string: if description is number descr.substring returns error
|
2020-08-14 13:12:34 +02:00
|
|
|
return [descr?(descr.substring(0,4997)+(descr.substring(0,4997).length == 4997?'...':'')):"" as String];
|
2018-05-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private getDateCreated(result: any): String[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.dateofacceptance", null);
|
|
|
|
if (!item) return null;
|
|
|
|
return [item as String];
|
|
|
|
}
|
|
|
|
|
|
|
|
private getLicense(result: any): License[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.bestaccessright", null);
|
|
|
|
if (!item) return null;
|
|
|
|
if (!_.has(item, "classid")) return null;
|
|
|
|
if (!_.has(item, "classname")) return null;
|
|
|
|
if (!_.has(item, "schemeid")) return null;
|
|
|
|
|
|
|
|
return [{
|
|
|
|
title: [_.get(item, "classname")],
|
|
|
|
identifier: [{
|
|
|
|
id: _.get(item, "classid"),
|
|
|
|
schema: _.get(item, "schemeid")
|
|
|
|
}]
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
private getIdentifier(result: any): Identifier[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.pid", null);
|
|
|
|
if (!item) return null;
|
|
|
|
const array = new Array<Identifier>();
|
|
|
|
if (Array.isArray(item)) {
|
|
|
|
const itemArray = item as Array<any>;
|
|
|
|
for (var i = 0; i < itemArray.length; i += 1) {
|
|
|
|
const val = this.getSingleIdentifier(itemArray[i]);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const val = this.getSingleIdentifier(item);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getSingleIdentifier(item: any): Identifier {
|
|
|
|
if (!_.has(item, "classname")) return null;
|
|
|
|
if (!_.has(item, "content")) return null;
|
|
|
|
return {
|
|
|
|
schema: _.get(item, "classname"),
|
|
|
|
id: _.get(item, "content")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private getSameAs(result: any): String[] {
|
|
|
|
const instances = _.get(result, "result.metadata.oaf:entity.oaf:result.children.instance", null);
|
|
|
|
if (!instances) return null;
|
|
|
|
if (!Array.isArray(instances)) return null;
|
|
|
|
|
|
|
|
const array = new Array<String>();
|
|
|
|
|
|
|
|
const instanceArray = instances as Array<any>;
|
|
|
|
for (var i = 0; i < instanceArray.length; i += 1) {
|
|
|
|
const webresources = _.get(instanceArray[i], "webresource", null);
|
|
|
|
if (!webresources) continue;
|
|
|
|
if (Array.isArray(webresources)) {
|
|
|
|
const webresourceArray = webresources as Array<any>;
|
|
|
|
for (var q = 0; q < webresourceArray.length; q += 1) {
|
|
|
|
const url = _.get(webresourceArray[q], "url", null);
|
|
|
|
if (!url) continue;
|
|
|
|
array.push(url as String);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const url = _.get(webresources, "url", null);
|
|
|
|
if (!url) continue;
|
|
|
|
array.push(url as String);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getKeyword(result: any): String[] {
|
|
|
|
const subjects = _.get(result, "result.metadata.oaf:entity.oaf:result.subject", null);
|
|
|
|
if (!subjects) return null;
|
|
|
|
if (!Array.isArray(subjects)) return null;
|
|
|
|
|
|
|
|
const array = new Array<String>();
|
|
|
|
|
|
|
|
const subjectArray = subjects as Array<any>;
|
|
|
|
for (var i = 0; i < subjectArray.length; i += 1) {
|
|
|
|
const classid = _.get(subjectArray[i], "classid", null);
|
|
|
|
if (classid !== "keyword") continue;
|
|
|
|
|
|
|
|
const sub = _.get(subjectArray[i], "content", null);
|
|
|
|
if (!sub) return null;
|
|
|
|
|
|
|
|
array.push(sub as String);
|
|
|
|
}
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getCreator(result: any): Person[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.oaf:result.creator", null);
|
|
|
|
if (!item) return null;
|
|
|
|
const array = new Array<Person>();
|
|
|
|
if (Array.isArray(item)) {
|
|
|
|
const itemArray = item as Array<any>;
|
|
|
|
for (var i = 0; i < itemArray.length; i += 1) {
|
|
|
|
const val = this.getSinglePerson(itemArray[i]);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const val = this.getSinglePerson(item);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getSinglePerson(item: any): Person {
|
|
|
|
if (!_.has(item, "surname") && !_.has(item, "name") && !_.has(item, "content")) return null;
|
|
|
|
return {
|
|
|
|
familyName: _.get(item, "surname", null),
|
|
|
|
givenName: _.get(item, "name", null),
|
|
|
|
name: _.get(item, "content", null)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private getCitation(result: any): Citation[] {
|
|
|
|
const item = _.get(result, "result.metadata.oaf:entity.extraInfo.citations.citation", null);
|
|
|
|
if (!item) return null;
|
|
|
|
const array = new Array<Citation>();
|
|
|
|
if (Array.isArray(item)) {
|
|
|
|
const itemArray = item as Array<any>;
|
|
|
|
for (var i = 0; i < itemArray.length; i += 1) {
|
|
|
|
const val = this.getSingleCitation(itemArray[i]);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const val = this.getSingleCitation(item);
|
|
|
|
if (val) array.push(val);
|
|
|
|
}
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private getSingleCitation(item: any): Citation {
|
|
|
|
if (!_.has(item, "rawText")) return null;
|
|
|
|
if (!_.has(item, "id")) return null;
|
|
|
|
|
|
|
|
const array = new Array<Identifier>();
|
|
|
|
|
|
|
|
const ids = _.get(item, "id", null);
|
|
|
|
if (Array.isArray(ids)) {
|
|
|
|
const idsArray = ids as Array<any>;
|
|
|
|
|
|
|
|
for (var i = 0; i < idsArray.length; i += 1) {
|
|
|
|
const type = _.get(idsArray[i], "type", null);
|
|
|
|
const value = _.get(idsArray[i], "value", null);
|
|
|
|
if (!type || !value) continue;
|
|
|
|
array.push({
|
|
|
|
id: value,
|
|
|
|
schema: type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const type = _.get(ids, "type", null);
|
|
|
|
const value = _.get(ids, "value", null);
|
|
|
|
if (type && value) {
|
|
|
|
array.push({
|
|
|
|
id: value,
|
|
|
|
schema: type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array.length == 0) return null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: [_.get(item, "rawText")],
|
|
|
|
identifier: array
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|