explore-services/src/app/services/publication.service.ts

429 lines
20 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import {PublicationInfo} from '../entities/publicationInfo';
@Injectable()
export class PublicationService {
constructor(private http: Http) {}
publicationInfo: PublicationInfo;
getPublicationInfo (id: string):any {
console.info("getPublicationInfo in service");
//let url = 'http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/publications/'+id;
let url = 'http://scoobydoo.di.uoa.gr:8181/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2.0/api/publications/'+id;
return this.http.get(url)
.map(res => <any> res.json())
.do(res => console.info(res['result']['metadata']['oaf:entity']))
.do(res => console.info(res['result']['metadata']['oaf:entity']['oaf:result']['children']['instance']))
.map(res => [res['result']['metadata']['oaf:entity']['oaf:result'],
res['result']['metadata']['oaf:entity']['oaf:result']['title'],
res['result']['metadata']['oaf:entity']['oaf:result']['rels']['rel'],
res['result']['metadata']['oaf:entity']['oaf:result']['children'],
res['result']['metadata']['oaf:entity']['oaf:result']['pid'],
res['result']['metadata']['oaf:entity']['oaf:result']['journal'],
res['result']['metadata']['oaf:entity']['oaf:result']['language'],
res['result']['metadata']['oaf:entity']['oaf:result']['subject'],
res['result']['metadata']['oaf:entity']['oaf:result']['bestlicense'],
res['result']['metadata']['oaf:entity']['oaf:result']['collectedfrom'],
res['result']['metadata']['oaf:entity']['extraInfo']['citations']['citation']
])
.map(res => this.parsePublicationInfo(res));
}
private handleError (error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error || 'Server error');
}
parsePublicationInfo (data: any):any {
this.publicationInfo = new PublicationInfo();
if(data[0] != null) {
this.publicationInfo.date = data[0].dateofacceptance.substring(0,4);
this.publicationInfo.publisher = data[0].publisher;
this.publicationInfo.description = data[0].description;
}
if(data[1] != null) {
this.publicationInfo.title = data[1].content;
}
if(data[2] != null) {
let mydata;
let funding;
let counter = 0;
let length = data[2].length!=undefined ? data[2].length : 1;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[2][i] : data[2];
if(mydata.hasOwnProperty("to")) {
if(mydata['to'].class == "hasAuthor") {
if(this.publicationInfo.authors == undefined) {
this.publicationInfo.authors = new Array<string>();
}
this.publicationInfo.authors[mydata.ranking-1] = mydata.fullname;
} else if(mydata['to'].class == "isProducedBy") {
if(this.publicationInfo.fundedByProjects == undefined) {
this.publicationInfo.fundedByProjects = new Map<string, string[]>();
}
// this.publicationInfo.fundedByProjects.set(mydata.code, new Array<string>());
// this.publicationInfo.fundedByProjects.get(mydata.code)[0] = mydata.acronym;
// this.publicationInfo.fundedByProjects.get(mydata.code)[1] = mydata.title;
this.publicationInfo.fundedByProjects.set(mydata['to'].content, new Array<string>());
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[0] = mydata.acronym;
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[1] = mydata.title;
if(mydata.hasOwnProperty("funding")) {
if(mydata['funding'].hasOwnProperty("funder")) {
// this.publicationInfo.fundedByProjects.get(mydata.code)[2] = mydata['funding']['funder'].shortname;
// this.publicationInfo.fundedByProjects.get(mydata.code)[3] = mydata['funding']['funder'].name;
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[2] = mydata['funding']['funder'].shortname;
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[3] = mydata['funding']['funder'].name;
}
if(mydata['funding'].hasOwnProperty("funding_level_2")) {
funding = mydata['funding']['funding_level_2'].content;
} else if(mydata['funding'].hasOwnProperty("funding_level_1")) {
funding = mydata['funding']['funding_level_1'].content;
} else if(mydata['funding'].hasOwnProperty("funding_level_0")) {
funding = mydata['funding']['funding_level_0'].content;
}
if(funding != undefined) {
funding = funding.split("::");
// this.publicationInfo.fundedByProjects.get(mydata.code)[4] = funding[1];
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[4] = funding[1];
for(let i=2; i<funding.length; i++) {
// this.publicationInfo.fundedByProjects.get(mydata.code)[4] += " | " + funding[i];
this.publicationInfo.fundedByProjects.get(mydata['to'].content)[4] += " | " + funding[i];
}
}
}
} else if(mydata['to'].class == "isRelatedTo") {
if(this.publicationInfo.relatedResearchData == undefined) {
this.publicationInfo.relatedResearchData = new Map<string, string[]>();//Array<{}>();
}
let url = "https://beta.openaire.eu/search/publication?articleId="+mydata['to'].content;
this.publicationInfo.relatedResearchData.set(url, new Array<string>());
this.publicationInfo.relatedResearchData.get(url)[0] = mydata['title'].content;
this.publicationInfo.relatedResearchData.get(url)[1] = mydata.dateofacceptance.substring(0,4);
this.publicationInfo.relatedResearchData.get(url)[2] = Math.round(mydata.trust*100)+"%";
} else if(mydata['to'].class == "hasAmongTopNSimilarDocuments") {
if(this.publicationInfo.similarPublications == undefined) {
this.publicationInfo.similarPublications = new Map<string, string[]>();
}
let url = "https://beta.openaire.eu/search/publication?articleId="+mydata['to'].content;
this.publicationInfo.similarPublications.set(url, new Array<string>());
this.publicationInfo.similarPublications.get(url)[0] = mydata['title'].content;
this.publicationInfo.similarPublications.get(url)[1] = mydata.dateofacceptance.substring(0,4);
this.publicationInfo.similarPublications.get(url)[2] = Math.round(mydata.trust*100)+"%";
}
}
}
}
if(data[3] != null) {
if(data[3].hasOwnProperty("instance")) {
this.publicationInfo.downloadFrom = new Map<string, string[]>();
this.publicationInfo.types = new Array<string>();
let length = data[3]['instance'].length!=undefined ? data[3]['instance'].length : 1;
let types = new Set<string>();
let counter = 0;
let mydata;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[3]['instance'][i] : data[3]['instance'];
if(mydata.hasOwnProperty("instancetype")) {
if(!types.has(mydata['instancetype'].classname)) {
this.publicationInfo.types[counter] = mydata['instancetype'].classname;
types.add(mydata['instancetype'].classname);
counter++;
}
}
if(!this.publicationInfo.downloadFrom.has(mydata.id)) {
this.publicationInfo.downloadFrom.set(mydata.id, new Array<string>());
}
if(mydata.hasOwnProperty("licence")) {
this.publicationInfo.downloadFrom.get(mydata.id)[0] = mydata['licence'].classid;
}
if(mydata.hasOwnProperty("hostedby")) {
this.publicationInfo.downloadFrom.get(mydata.id)[1] = mydata['hostedby'].name;
}
if(mydata.hasOwnProperty("webresource")) {
this.publicationInfo.downloadFrom.get(mydata.id)[2] = mydata['webresource'].url;
}
}
}
if(data[3].hasOwnProperty("externalreference")) {
this.publicationInfo.bioentities = new Map<string, Map<string, string>>();
let length = data[3]['externalreference'].length!=undefined ? data[3]['externalreference'].length : 1;
let mydata;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[3]['externalreference'][i] : data[3]['externalreference'];
if(!this.publicationInfo.bioentities.has(mydata.sitename)) {
this.publicationInfo.bioentities.set(mydata.sitename, new Map<string, string>());
}
this.publicationInfo.bioentities.get(mydata.sitename).set(mydata.refidentifier, mydata.url);
}
}
}
if(data[4] != null) {
this.publicationInfo.identifiers = new Map<string, string>();
if(data[4].hasOwnProperty("classname")) {
this.publicationInfo.identifiers.set(data[4].classname, data[4].content);
} else {
for(let i=0; i<data[4].length; i++) {
this.publicationInfo.identifiers.set(data[4][i].classname, data[4][i].content);
}
}
}
if(data[5] != null) {
this.publicationInfo.journal = data[5].content;
}
if(data[6] != null) {
this.publicationInfo.languages = new Array<string>();
if(data[6].hasOwnProperty("classname")) {
this.publicationInfo.languages[0] = data[6].classname;
} else {
for(let i=0; i<data[6].length; i++) {
this.publicationInfo.languages[i] = data[6][i].classname;
}
}
}
if(data[7] != null) {
this.publicationInfo.classifiedSubjects = new Map<string, string[]>();
this.publicationInfo.subjects = new Array<string>();
let mydata;
let length = data[7].length!=undefined ? data[7].length : 1;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[7][i] : data[7];
if(mydata.inferred == true) {
if(!this.publicationInfo.classifiedSubjects.has(mydata.classid)) {
this.publicationInfo.classifiedSubjects.set(mydata.classid, new Array<string>());
}
let counter = this.publicationInfo.classifiedSubjects.get(mydata.classid).length;
this.publicationInfo.classifiedSubjects.get(mydata.classid)[counter] = mydata.content;
} else {
let counter = this.publicationInfo.subjects.length;
this.publicationInfo.subjects[counter] = mydata.content;
}
}
}
if(data[8] != null) {
this.publicationInfo.bestlicense = data[8].classid;
}
if(data[9] != null) {
this.publicationInfo.collectedFrom = new Map<string, string>();
let mydata;
let length = data[9].length!=undefined ? data[9].length : 1;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[9][i] : data[9];
let link = "https://beta.openaire.eu/search/dataprovider?datasourceId=";
this.publicationInfo.collectedFrom.set(mydata.name, link+mydata.id);
}
}
if(this.publicationInfo.journal != null
&& this.publicationInfo.identifiers != null
&& this.publicationInfo.identifiers.has("doi")) {
if( this.publicationInfo.downloadFrom == null) {
this.publicationInfo.downloadFrom = new Map<string, string[]>();
}
let doi = this.publicationInfo.identifiers.get("doi");
if(!this.publicationInfo.downloadFrom.has(doi)) {
this.publicationInfo.downloadFrom.set(doi, new Array<string>());
}
this.publicationInfo.downloadFrom.get(doi)[0] = "";
this.publicationInfo.downloadFrom.get(doi)[1] = this.publicationInfo.publisher+"/ "+this.publicationInfo.journal;
this.publicationInfo.downloadFrom.get(doi)[2] = "http://dx.doi.org/"+doi;
}
if(data[10] != null) {
this.publicationInfo.references = /*{};*/new Array<{[key: string]: string}>();
let mydata;
let length = data[10].length!=undefined ? data[10].length : 1;
for(let i=0; i<length; i++) {
mydata = length > 1 ? data[10][i] : data[10];
let url;
if(mydata.hasOwnProperty("id")) {
let mydata1;
let length1 = mydata['id'].length!=undefined ? mydata['id'].length : 1;
for(let j=0; j<length1; j++) {
mydata1 = length1 > 1 ? mydata['id'][j] : mydata['id'];
if(mydata1.type == "pmid") {
url = "http://www.ncbi.nlm.nih.gov/pubmed/"+mydata1.value;
}
}
}
this.publicationInfo.references[mydata.position-1] = {};
this.publicationInfo.references[mydata.position-1]['text'] = mydata.rawText;
this.publicationInfo.references[mydata.position-1]['url'] = url;
}
}
//this.printPublicationInfo();
return this.publicationInfo;
}
printPublicationInfo() {
console.info("DATE: "+this.publicationInfo.date);
console.info("PUBLISHER: "+this.publicationInfo.publisher);
console.info("DESCRIPTION: "+this.publicationInfo.description);
console.info("TITLE: "+this.publicationInfo.title);
console.info("AUTHORS: "+this.publicationInfo.authors);
console.info("\nFUNDED BY PROJECTS:");
if(this.publicationInfo.fundedByProjects != undefined) {
this.publicationInfo.fundedByProjects.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nRELATED RESEARCH DATA:");
if(this.publicationInfo.relatedResearchData != undefined) {
this.publicationInfo.relatedResearchData.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nSIMILAR PUBLICATIONS:");
if(this.publicationInfo.similarPublications != undefined) {
this.publicationInfo.similarPublications.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("TYPES: "+this.publicationInfo.types);
console.info("\nDOWNLOAD FROM:");
if(this.publicationInfo.downloadFrom != undefined) {
this.publicationInfo.downloadFrom.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nBIOENTITIES:");
if(this.publicationInfo.bioentities != undefined) {
this.publicationInfo.bioentities.forEach(function (value, key, map) {
value.forEach(function (value1, key1, map1) {
console.info(key + " = " + key1 + " = " + value1);
})
})
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nIDENTIFIERS:");
if(this.publicationInfo.identifiers != undefined) {
this.publicationInfo.identifiers.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("JOURNAL: "+this.publicationInfo.journal);
console.info("LANGUAGES: "+this.publicationInfo.languages);
console.info("SUBJECTS: "+this.publicationInfo.subjects);
console.info("\nCLASSIFIED OBJECTS:");
if(this.publicationInfo.classifiedSubjects != undefined) {
this.publicationInfo.classifiedSubjects.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("BEST LICENSE: "+this.publicationInfo.bestlicense);
console.info("\nCOLLECTED FROM:");
if(this.publicationInfo.collectedFrom != undefined) {
this.publicationInfo.collectedFrom.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nDOWNLOAD FROM:");
if(this.publicationInfo.downloadFrom != undefined) {
this.publicationInfo.downloadFrom.forEach(function (value, key, map) {
console.info(key + " = " + value);
});
} else {
console.info("undefined");
}
console.info("\n");
console.info("\nREFERENCES:");
if(this.publicationInfo.references != undefined) {
for(let i in this.publicationInfo.references) {
for(let key in this.publicationInfo.references[i]) {
console.info(key+" : "+this.publicationInfo.references[i][key]);
}
}
} else {
console.info("undefined");
}
}
}