Commit 3a15fb3e authored by Maxime Chaillet's avatar Maxime Chaillet

Handle the possible cases where the data.litteral is all uppercase, all...

Handle the possible cases where the data.litteral is all uppercase, all lowercase or all titlecase. Then it is not possible to distinguish between family name and first name.
parent 45814155
Pipeline #2257 failed with stages
function DOIController(e){this.doiServer="https://data.datacite.org/",this.acceptedPrefix=["10.5072","10.15151"],this.view=e}function findRegExpInText(e,t){return t.search(e)}function extractFieldsFromCategories(e){var t,n=e.categories;for(t in n)0!=findRegExpInText(/id/,n[t])&&0!=findRegExpInText(/bm/,n[t])||(e.beamline=n[t]);for(t in n)0==findRegExpInText(/\D+-/,n[t])&&(e.proposalNumber=n[t]);for(t in n)-1!=findRegExpInText(/\s/,n[t])&&(e.proposalType=n[t])}function extractFieldsFromDoi(e){var t=RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);e.investigationId=t.exec(e.DOI)[1]}function createCitation(e){var t=_.transform(e.author,function(e,t){if(t.given)e.push(t.family+" "+t.given);else{var n=new RegExp(/\s([^a-z]+$)/),r=new RegExp(/^(.[^A-Z]+)+\b/);e.push(n.exec(t.literal)[1]+" "+r.exec(t.literal)[0].trim())}},[]),n=_.join(t,"; ")+". ("+e.issued["date-parts"]+"). "+e.title+". "+e.publisher+" (ESRF). <a href='https://doi.esrf.fr/"+e.DOI+"'> doi:"+e.DOI+"</a>";e.citation=n}function DOIView(){}var BEAMLINEURL=[{name:"BM05",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/BM05"},{name:"BM29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/BM29"},{name:"CM01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/CM01.html"},{name:"ID01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID01"},{name:"ID06",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MEx/id06-large-volume-press.html"},{name:"ID11",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11"},{name:"ID16A",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16A"},{name:"ID16B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16B"},{name:"ID17",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/CBS/ID17"},{name:"ID19",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/home/UsersAndScience/Experiments/StructMaterials/ID19.html"},{name:"ID21",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"},{name:"ID22",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id22"},{name:"ID23-1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-1"},{name:"ID23-2",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-2"},{name:"ID29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/Beamlines/content/content/id29.html"},{name:"ID30A1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/MASSIF1"},{name:"ID30A3",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/id30a-3--massif-3.html"},{name:"ID30B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id30b"},{name:"ID32",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/ID32"}];DOIController.prototype.getData=function(e){var t=this;this.view.setDOI(e),this.hasAcceptedPrefix(e)?$.ajax({headers:{Accept:"application/vnd.citationstyles.csl+json"},type:"GET",url:this.doiServer+e,beforeSend:function(){t.view.setLoading("Retrieving data from Server")},complete:function(){t.view.setLoading(!1)},success:function(e){if(e){extractFieldsFromCategories(e),extractFieldsFromDoi(e),createCitation(e);var n=e.issued["date-parts"]-3,r=new Date(n+"-01-01T00:00+00:00");e.beamlineUrl=t.findsUrl(e.beamline,r),dust.render("esrf-landing-page",{data:e},function(e,t){$("#main").html(t)})}else"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","Sorry, the requested DOI was not found.","error"):t.view.displayMessage("doi-not-found-page","Sorry, the requested DOI was not found.","main")},error:function(e,n,r){"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","<h3> Not found ! </h3> <p> Sorry, there was a connexion problem with the datacite server. </p>","error"):t.view.displayMessage("doi-not-found-page","<h2> Not found ! </h2> <p> Sorry, there was a connexion problem with the datacite server. </p>","main"),t.view.setLoading(!1)}}):"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","<h3> Not found ! </h3> <p> The DOI <b>"+e+'</b> was not found at ESRF because its prefix is not ESRF specific. Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>. </p>',"error"):t.view.displayMessage("doi-not-found-page","<h2> Not found ! </h2> <p> The DOI <b>"+e+'</b> was not found at ESRF because its prefix is not ESRF specific. </br> Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>.</p>',"main")},DOIController.prototype.hasAcceptedPrefix=function(e){var t=e.split("/")[0];return-1!=_.findIndex(this.acceptedPrefix,function(e){return t==e})},DOIController.prototype.displayMainContent=function(e){"welcome-page"===this.origin&&dust.render("welcome-page",{},function(e,t){$("#main").html(t)}),"index"===this.origin&&this.getData(e)},DOIController.prototype.setOrigin=function(e){this.origin=e},DOIController.prototype.findsUrl=function(e,t){for(var n="noLink",r=0;BEAMLINEURL[r]&&"noLink"===n;){var a=new Date(BEAMLINEURL[r].startDate),i=new Date(BEAMLINEURL[r].endDate);BEAMLINEURL[r].name.toLowerCase()===e.toLowerCase()&&t>a&&t<i&&(n=BEAMLINEURL[r].url),r++}return n},DOIView.prototype.setLoading=function(e){0!=e?$("body").addClass("loading"):$("body").removeClass("loading")},DOIView.prototype.setDOI=function(e){$("#doiPanel").html(e)},DOIView.prototype.displayMessage=function(e,t,n){dust.render(e,{message:t},function(e,t){$("#"+n).html(t)})};
\ No newline at end of file
function DOIController(e){this.doiServer="https://data.datacite.org/",this.acceptedPrefix=["10.5072","10.15151"],this.view=e}function findRegExpInText(e,t){return t.search(e)}function extractFieldsFromCategories(e){var t,n=e.categories;for(t in n)0!=findRegExpInText(/id/,n[t])&&0!=findRegExpInText(/bm/,n[t])||(e.beamline=n[t]);for(t in n)0==findRegExpInText(/\D+-/,n[t])&&(e.proposalNumber=n[t]);for(t in n)-1!=findRegExpInText(/\s/,n[t])&&(e.proposalType=n[t])}function extractFieldsFromDoi(e){var t=RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);e.investigationId=t.exec(e.DOI)[1]}function createCitation(e){var t=_.transform(e.author,function(e,t){if(t.given)e.push(t.family+" "+t.given);else{var n=new RegExp(/\s([^a-z]+$)/),r=new RegExp(/^(.[^A-Z]+)+\b/),a=n.exec(t.literal),i=r.exec(t.literal);a&&i?e.push(a[1]+" "+i[0].trim()):e.push(t.literal)}},[]),n=_.join(t,"; ")+". ("+e.issued["date-parts"]+"). "+e.title+". "+e.publisher+" (ESRF). <a href='https://doi.esrf.fr/"+e.DOI+"'> doi:"+e.DOI+"</a>";e.citation=n}function DOIView(){}var BEAMLINEURL=[{name:"BM05",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/BM05"},{name:"BM29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/BM29"},{name:"CM01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/CM01.html"},{name:"ID01",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID01"},{name:"ID06",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MEx/id06-large-volume-press.html"},{name:"ID11",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/StructMaterials/ID11"},{name:"ID16A",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16A"},{name:"ID16B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/XNP/ID16B"},{name:"ID17",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/UsersAndScience/Experiments/CBS/ID17"},{name:"ID19",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.fr/home/UsersAndScience/Experiments/StructMaterials/ID19.html"},{name:"ID21",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/XNP/ID21"},{name:"ID22",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id22"},{name:"ID23-1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-1"},{name:"ID23-2",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/UsersAndScience/Experiments/MX/About_our_beamlines/ID23-2"},{name:"ID29",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/Beamlines/content/content/id29.html"},{name:"ID30A1",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/MASSIF1"},{name:"ID30A3",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/home/UsersAndScience/Experiments/MX/About_our_beamlines/id30a-3--massif-3.html"},{name:"ID30B",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/id30b"},{name:"ID32",startDate:"2000-01-01T00:00+00:00",endDate:"2100-12-31T00:00+00:00",url:"http://www.esrf.eu/ID32"}];DOIController.prototype.getData=function(e){var t=this;this.view.setDOI(e),this.hasAcceptedPrefix(e)?$.ajax({headers:{Accept:"application/vnd.citationstyles.csl+json"},type:"GET",url:this.doiServer+e,beforeSend:function(){t.view.setLoading("Retrieving data from Server")},complete:function(){t.view.setLoading(!1)},success:function(e){if(e){extractFieldsFromCategories(e),extractFieldsFromDoi(e),createCitation(e);var n=e.issued["date-parts"]-3,r=new Date(n+"-01-01T00:00+00:00");e.beamlineUrl=t.findsUrl(e.beamline,r),dust.render("esrf-landing-page",{data:e},function(e,t){$("#main").html(t)})}else"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","Sorry, the requested DOI was not found.","error"):t.view.displayMessage("doi-not-found-page","Sorry, the requested DOI was not found.","main")},error:function(e,n,r){"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","<h3> Not found ! </h3> <p> Sorry, there was a connexion problem with the datacite server. </p>","error"):t.view.displayMessage("doi-not-found-page","<h2> Not found ! </h2> <p> Sorry, there was a connexion problem with the datacite server. </p>","main"),t.view.setLoading(!1)}}):"welcome-page"===t.origin?t.view.displayMessage("doi-not-found-page2","<h3> Not found ! </h3> <p> The DOI <b>"+e+'</b> was not found at ESRF because its prefix is not ESRF specific. Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>. </p>',"error"):t.view.displayMessage("doi-not-found-page","<h2> Not found ! </h2> <p> The DOI <b>"+e+'</b> was not found at ESRF because its prefix is not ESRF specific. </br> Please use the DOI search engine at <a href="https://www.doi.org"> doi.org</a>.</p>',"main")},DOIController.prototype.hasAcceptedPrefix=function(e){var t=e.split("/")[0];return-1!=_.findIndex(this.acceptedPrefix,function(e){return t==e})},DOIController.prototype.displayMainContent=function(e){"welcome-page"===this.origin&&dust.render("welcome-page",{},function(e,t){$("#main").html(t)}),"index"===this.origin&&this.getData(e)},DOIController.prototype.setOrigin=function(e){this.origin=e},DOIController.prototype.findsUrl=function(e,t){for(var n="noLink",r=0;BEAMLINEURL[r]&&"noLink"===n;){var a=new Date(BEAMLINEURL[r].startDate),i=new Date(BEAMLINEURL[r].endDate);BEAMLINEURL[r].name.toLowerCase()===e.toLowerCase()&&t>a&&t<i&&(n=BEAMLINEURL[r].url),r++}return n},DOIView.prototype.setLoading=function(e){0!=e?$("body").addClass("loading"):$("body").removeClass("loading")},DOIView.prototype.setDOI=function(e){$("#doiPanel").html(e)},DOIView.prototype.displayMessage=function(e,t,n){dust.render(e,{message:t},function(e,t){$("#"+n).html(t)})};
\ No newline at end of file
......@@ -180,12 +180,23 @@ function createCitation(data) {
if (obj.given) {
result.push(obj.family + ' ' + obj.given);
} else {
// we have the first name followed by the Sir name
// flip them
var familleRegExp = new RegExp(/\s([^a-z]+$)/);
var prenomRegExp = new RegExp(/^(.[^A-Z]+)+\b/);
result.push(familleRegExp.exec(obj.literal)[1] + " " + prenomRegExp.exec(obj.literal)[0].trim());
// cells of data.authors contains First Name FAMILY NAME most of the time.
// 1 - detect the words in UPPERCASE as FAMILY name
// 2 - detect the words in LOWERcase except first letter which can optionally be uppercase.
// 3 - flip them
var familyRegExp = new RegExp(/\s([^a-z]+$)/);
var firstNameRegExp = new RegExp(/^(.[^A-Z]+)+\b/);
var familyName = familyRegExp.exec(obj.literal);
var firstName = firstNameRegExp.exec(obj.literal);
// Sometime all words are uppercase or lowercase or uppercase for the first letter only. In this case we can not distinguish between family name and firstname. => string unchanged
if (!familyName || !firstName ){
result.push(obj.literal);
} else {
result.push(familyName[1] + " " + firstName[0].trim());
}
}
},[]);
var authorString = _.join(authorList,'; ');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment