Merge pull request #535 from aurimasv/lookup-doi+isbn
[RecognizePDF] Don't skip ISBN search if a DOI search fails
This commit is contained in:
commit
abce94458b
2 changed files with 55 additions and 25 deletions
|
@ -95,30 +95,34 @@ var Zotero_RecognizePDF = new function() {
|
||||||
// Look up DOI
|
// Look up DOI
|
||||||
Zotero.debug("RecognizePDF: Found DOI: "+doi);
|
Zotero.debug("RecognizePDF: Found DOI: "+doi);
|
||||||
|
|
||||||
var translate = new Zotero.Translate.Search();
|
var translateDOI = new Zotero.Translate.Search();
|
||||||
translate.setTranslator("11645bd1-0420-45c1-badb-53fb41eeb753");
|
translateDOI.setTranslator("11645bd1-0420-45c1-badb-53fb41eeb753");
|
||||||
translate.setSearch({"itemType":"journalArticle", "DOI":doi});
|
translateDOI.setSearch({"itemType":"journalArticle", "DOI":doi});
|
||||||
promise = _promiseTranslate(translate, libraryID);
|
promise = _promiseTranslate(translateDOI, libraryID);
|
||||||
} else {
|
} else {
|
||||||
// Look for ISBNs if no DOI
|
promise = Q.reject("No DOI found in text");
|
||||||
var isbns = _findISBNs(allText);
|
|
||||||
if(isbns.length) {
|
|
||||||
Zotero.debug("RecognizePDF: Found ISBNs: " + isbns);
|
|
||||||
|
|
||||||
var translate = new Zotero.Translate.Search();
|
|
||||||
translate.setTranslator("c73a4a8c-3ef1-4ec8-8229-7531ee384cc4");
|
|
||||||
translate.setSearch({"itemType":"book", "ISBN":isbns[0]});
|
|
||||||
promise = _promiseTranslate(translate, libraryID);
|
|
||||||
} else {
|
|
||||||
promise = Q.reject("No ISBN or DOI found");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no DOI or ISBN, query Google Scholar
|
return promise
|
||||||
return promise.fail(function(error) {
|
// Look for ISBNs if no DOI
|
||||||
Zotero.debug("RecognizePDF: "+error);
|
.fail(function(error) {
|
||||||
return me.GSFullTextSearch.findItem(lines, libraryID, stopCheckCallback);
|
Zotero.debug("RecognizePDF: " + error);
|
||||||
});
|
var isbns = _findISBNs(allText);
|
||||||
|
if (isbns.length) {
|
||||||
|
Zotero.debug("RecognizePDF: Found ISBNs: " + isbns);
|
||||||
|
|
||||||
|
var translate = new Zotero.Translate.Search();
|
||||||
|
translate.setSearch({"itemType":"book", "ISBN":isbns[0]});
|
||||||
|
return _promiseTranslate(translate, libraryID);
|
||||||
|
} else {
|
||||||
|
return Q.reject("No ISBN found in text.");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// If no DOI or ISBN, query Google Scholar
|
||||||
|
.fail(function(error) {
|
||||||
|
Zotero.debug("RecognizePDF: " + error);
|
||||||
|
return me.GSFullTextSearch.findItem(lines, libraryID, stopCheckCallback);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +200,10 @@ var Zotero_RecognizePDF = new function() {
|
||||||
if(success && translate.newItems.length) {
|
if(success && translate.newItems.length) {
|
||||||
deferred.resolve(translate.newItems[0]);
|
deferred.resolve(translate.newItems[0]);
|
||||||
} else {
|
} else {
|
||||||
deferred.reject("Translation with Google Scholar failed");
|
deferred.reject(translate.translator && translate.translator.length
|
||||||
|
? "Translation with " + translate.translator.map(t => t.label) + " failed"
|
||||||
|
: "Could not find a translator for given search item"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
translate.translate(libraryID, false);
|
translate.translate(libraryID, false);
|
||||||
|
|
|
@ -1112,13 +1112,23 @@ Zotero.Translate.Base.prototype = {
|
||||||
* @param {Boolean} [saveAttachments=true] Exclude attachments (e.g., snapshots) on import
|
* @param {Boolean} [saveAttachments=true] Exclude attachments (e.g., snapshots) on import
|
||||||
*/
|
*/
|
||||||
"translate":function(libraryID, saveAttachments) { // initialize properties specific to each translation
|
"translate":function(libraryID, saveAttachments) { // initialize properties specific to each translation
|
||||||
this._currentState = "translate";
|
|
||||||
|
|
||||||
if(!this.translator || !this.translator.length) {
|
if(!this.translator || !this.translator.length) {
|
||||||
this.complete(false, new Error("No translator specified"));
|
var args = arguments;
|
||||||
|
Zotero.debug("Translate: translate called without specifying a translator. Running detection first.");
|
||||||
|
this.setHandler('translators', function(me, translators) {
|
||||||
|
if(!translators.length) {
|
||||||
|
me.complete(false, "Could not find an appropriate translator");
|
||||||
|
} else {
|
||||||
|
me.setTranslator(translators);
|
||||||
|
Zotero.Translate.Base.prototype.translate.apply(me, args);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.getTranslators();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._currentState = "translate";
|
||||||
|
|
||||||
this._libraryID = libraryID;
|
this._libraryID = libraryID;
|
||||||
this._saveAttachments = saveAttachments === undefined || saveAttachments;
|
this._saveAttachments = saveAttachments === undefined || saveAttachments;
|
||||||
this._savingAttachments = [];
|
this._savingAttachments = [];
|
||||||
|
@ -2158,6 +2168,19 @@ Zotero.Translate.Export.prototype._prepareTranslation = function() {
|
||||||
this._sandboxManager.importObject(this._io);
|
this._sandboxManager.importObject(this._io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overload Zotero.Translate.Base#translate to make sure that
|
||||||
|
* Zotero.Translate.Export#translate is not called without setting a
|
||||||
|
* translator first. Doesn't make sense to run detection for export.
|
||||||
|
*/
|
||||||
|
Zotero.Translate.Export.prototype.translate = function() {
|
||||||
|
if(!this.translator || !this.translator.length) {
|
||||||
|
this.complete(false, new Error("Export translation initiated without setting a translator"));
|
||||||
|
} else {
|
||||||
|
Zotero.Translate.Base.prototype.translate.apply(this, arguments);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the progress of the import operation, or null if progress cannot be determined
|
* Return the progress of the import operation, or null if progress cannot be determined
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue