Sn1per has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182752

Change subject: Detect and request PMID/PCMID info
......................................................................

Detect and request PMID/PCMID info

- Add regex for PMID and PCMID (with or
    without 'PMC' prefix)
- If PMID or PCMID detected, use
    requestFromPubMedID to request proper
    information

Bug: T78769
Change-Id: I068e686603251bfd8ce53c6d93c67916cedfd8fa
---
M lib/distinguish.js
1 file changed, 26 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid 
refs/changes/52/182752/1

diff --git a/lib/distinguish.js b/lib/distinguish.js
index 9205013..51c9132 100644
--- a/lib/distinguish.js
+++ b/lib/distinguish.js
@@ -10,7 +10,8 @@
 var request = require('request'),
        urlParse = require('url'),
        requestFromURL = require('./requests.js').requestFromURL,
-       requestFromDOI = require('./requests.js').requestFromDOI;
+       requestFromDOI = require('./requests.js').requestFromDOI,
+       requestFromPubMedID = require('./requests.js').requestFromPubMedID;
 
 /**
  * Determine type of string (doi, url) and callback on correct handler
@@ -18,25 +19,39 @@
  * @param  {Function} callback     callback(extractedValue, correctFunction)
  */
 var distinguish = function (searchString, callback){
-       var search, match, reDOI, parsedURL;
+       var search, reDOI, rePMID, rePMCID, rePMCID2, parsedURL;
 
        searchString.trim();
 
        search = searchString;
 
        reDOI = new RegExp('\\b10[.][0-9]{4,}[//].*\\b');
+       rePMID = new RegExp('\\b\\d{8}\\b');
+       rePMCID = new RegExp('\\bPMC\\d{7}\\b');
+       rePMCID2 = new RegExp('\\b\\d{7}\\b');
 
-       match = search.match(reDOI);
+       var matchDOI = search.match(reDOI);
+       var matchPMID = search.match(rePMID);
+       var matchPMCID = search.match(rePMCID);
 
-       if (match){
-               callback(match[0], requestFromDOI);
+       if (matchDOI) {
+               callback(matchDOI[0], requestFromDOI);
+       } else if (matchPMID) {
+               callback(matchPMID[0], requestFromPubMedID);
+       } else if (matchPMCID) {
+               callback(matchPMCID[0], requestFromPubMedID);
        } else {
-               parsedURL = urlParse.parse(search);
-               if (!parsedURL.protocol){
-                       search = 'http://'+ search;
-                       callback(search, requestFromURL);
+               matchPMCID = search.match(rePMCID2);
+               if (matchPMCID) {
+                       callback('PMC' + matchPMCID[0], requestFromPubMedID);
                } else {
-                       callback(search, requestFromURL); //assume url if not 
doi
+                       parsedURL = urlParse.parse(search);
+                       if (!parsedURL.protocol){
+                               search = 'http://'+ search;
+                               callback(search, requestFromURL);
+                       } else {
+                               callback(search, requestFromURL); //assume url 
if not doi
+                       }
                }
        }
 };
@@ -52,4 +67,4 @@
 /* Exports */
 module.exports = {
        distinguish: distinguish
-};
\ No newline at end of file
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/182752
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I068e686603251bfd8ce53c6d93c67916cedfd8fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Sn1per <geof...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to