-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bringing Crossref, Semantic Scholar, Open Citations and Open Alex loo…
…kup + auto-import + redesign to Cita for Zotero 7 (#300) Huge commit that includes: * Getting citations from Crossref, Semantic Scholar, Open Alex, and Open Citations * Storing arXiv ID, Open Citations OMID, Open Alex ID, and Semantic Scholar CorpusID for each item * Restyle the citations pane to match the Zotero 7 item pane style * Split the bottom of the Citations tab into an Identifiers tab to keep track of all an item's identifiers * Allow drag and drop reordering of citation order * Significant code refactoring, with the indexer and pid classes * much more...
- Loading branch information
1 parent
1c83e04
commit 49a1273
Showing
87 changed files
with
12,520 additions
and
2,046 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
diff --git a/node_modules/openalex-sdk/dist/src/index.js b/node_modules/openalex-sdk/dist/src/index.js | ||
index 70b2df5..518d455 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/index.js | ||
+++ b/node_modules/openalex-sdk/dist/src/index.js | ||
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const authors_1 = require("./utils/authors"); | ||
const exportCSV_1 = require("./utils/exportCSV"); | ||
const helpers_1 = require("./utils/helpers"); | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/authors.js b/node_modules/openalex-sdk/dist/src/utils/authors.js | ||
index 0b1cbc5..f824766 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/authors.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/authors.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleAllAuthorsPages = exports.handleMultipleAuthorsPages = exports.validateAuthorParameters = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const exportCSV_1 = require("./exportCSV"); | ||
const helpers_1 = require("./helpers"); | ||
const http_1 = require("./http"); | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/exportCSV.js b/node_modules/openalex-sdk/dist/src/utils/exportCSV.js | ||
index 7f4d748..9c01df5 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/exportCSV.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/exportCSV.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertToCSV = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
function flattenObject(obj, parentKey = '', depth = 0) { | ||
const flattened = {}; | ||
for (const [key, value] of Object.entries(obj)) { | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/institutions.js b/node_modules/openalex-sdk/dist/src/utils/institutions.js | ||
index 1082435..099275a 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/institutions.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/institutions.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleAllInstitutionsPages = exports.handleMultipleInstitutionsPages = exports.validateInstitutionsParameters = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const exportCSV_1 = require("./exportCSV"); | ||
const helpers_1 = require("./helpers"); | ||
const http_1 = require("./http"); | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/sources.js b/node_modules/openalex-sdk/dist/src/utils/sources.js | ||
index 699da8d..38c68b8 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/sources.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/sources.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleAllSourcesPages = exports.handleMultipleSourcesPages = exports.validateSourcesParameters = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const exportCSV_1 = require("./exportCSV"); | ||
const helpers_1 = require("./helpers"); | ||
const http_1 = require("./http"); | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/topics.js b/node_modules/openalex-sdk/dist/src/utils/topics.js | ||
index b2946cc..b9fd0ed 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/topics.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/topics.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleAllTopicsPages = exports.handleMultipleTopicsPages = exports.validateTopicsParameters = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const exportCSV_1 = require("./exportCSV"); | ||
const helpers_1 = require("./helpers"); | ||
const http_1 = require("./http"); | ||
diff --git a/node_modules/openalex-sdk/dist/src/utils/works.js b/node_modules/openalex-sdk/dist/src/utils/works.js | ||
index 46d5d38..2a5591c 100644 | ||
--- a/node_modules/openalex-sdk/dist/src/utils/works.js | ||
+++ b/node_modules/openalex-sdk/dist/src/utils/works.js | ||
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatNumber = exports.handleAllPagesInChunks = exports.handleMultiplePages = exports.handleAllPages = exports.validateParameters = void 0; | ||
-const fs_1 = __importDefault(require("fs")); | ||
+//const fs_1 = __importDefault(require("fs")); | ||
const exportCSV_1 = require("./exportCSV"); | ||
const helpers_1 = require("./helpers"); | ||
const http_1 = require("./http"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
diff --git a/node_modules/zotero-types/types/xpcom/db.d.ts b/node_modules/zotero-types/types/xpcom/db.d.ts | ||
index 8a2aeb1..8f9bf2d 100644 | ||
--- a/node_modules/zotero-types/types/xpcom/db.d.ts | ||
+++ b/node_modules/zotero-types/types/xpcom/db.d.ts | ||
@@ -70,12 +70,12 @@ declare namespace _ZoteroTypes { | ||
executeTransaction<T>( | ||
func: () => T | Promise<T>, | ||
options?: { | ||
- disbledForeignKeys: boolean; | ||
- timeout: number; | ||
- vacuumOnCommit: boolean; | ||
- inBackup: boolean; | ||
- onCommit: (id: string) => void; | ||
- onRollback: (id: string) => void; | ||
+ disbledForeignKeys?: boolean; | ||
+ timeout?: number; | ||
+ vacuumOnCommit?: boolean; | ||
+ inBackup?: boolean; | ||
+ onCommit?: (id: string) => void; | ||
+ onRollback?: (id: string) => void; | ||
}, | ||
): Promise<T>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
export default class PID { | ||
type: PIDType; | ||
id: string; | ||
|
||
constructor(type: PIDType, id: string) { | ||
this.type = type; | ||
this.id = id; | ||
} | ||
|
||
get url(): string | null { | ||
const cleanPID = this.cleanID; | ||
if (cleanPID) { | ||
switch (this.type) { | ||
case "DOI": { | ||
const url = | ||
"https://doi.org/" + | ||
// From Zotero's itembox.xml: | ||
// Encode some characters that are technically valid in DOIs, | ||
// though generally not used. '/' doesn't need to be encoded. | ||
cleanPID | ||
.replace(/#/g, "%23") | ||
.replace(/\?/g, "%3f") | ||
.replace(/%/g, "%25") | ||
.replace(/"/g, "%22"); | ||
return url; | ||
} | ||
case "OMID": | ||
return "https://opencitations.net/meta/" + cleanPID; | ||
case "OpenAlex": | ||
return "https://openalex.org/works/" + cleanPID; | ||
case "arXiv": | ||
return "https://arxiv.org/abs/" + cleanPID; | ||
case "QID": | ||
return "https://www.wikidata.org/wiki/" + cleanPID; | ||
case "CorpusID": | ||
return ( | ||
"https://api.semanticscholar.org/CorpusID:" + cleanPID | ||
); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** Get the cleaned ID | ||
* @returns The cleaned ID or null if it couldn't be cleaned | ||
*/ | ||
get cleanID(): string | null { | ||
switch (this.type) { | ||
case "DOI": | ||
return Zotero.Utilities.cleanDOI(this.id); | ||
case "ISBN": | ||
return Zotero.Utilities.cleanISBN(this.id) || null; | ||
case "QID": { | ||
let qid = this.id.toUpperCase().trim(); | ||
if (qid[0] !== "Q") qid = "Q" + qid; | ||
if (!qid.match(/^Q\d+$/)) return null; | ||
return qid; | ||
} | ||
case "OMID": { | ||
let omid = this.id.toLowerCase().trim(); | ||
if (/^https?:/.test(omid)) | ||
omid = omid.match(/br\/\d+/)?.[0] ?? ""; | ||
if (omid.substring(0, 3) !== "br/") omid = "br/" + omid; | ||
if (!omid.match(/^br\/06[1-9]*0\d+$/)) return null; | ||
return omid; | ||
} | ||
case "arXiv": { | ||
const arXiv_RE = | ||
/\b(([-A-Za-z.]+\/\d{7}|\d{4}\.\d{4,5})(?:v(\d+))?)(?!\d)/g; // 1: full ID, 2: ID without version, 3: version # | ||
const m = arXiv_RE.exec(this.id); | ||
if (m) { | ||
const cleanArXiv = m[2]; | ||
return cleanArXiv; | ||
} | ||
|
||
return null; | ||
} | ||
case "OpenAlex": { | ||
let openAlex = this.id.trim(); | ||
if (/^https?:/.test(openAlex)) | ||
openAlex = openAlex.match(/[Ww]\d+/)?.[0] ?? ""; | ||
openAlex = openAlex.toUpperCase(); | ||
if (openAlex[0] !== "W") openAlex = "W" + openAlex; | ||
if (!openAlex.match(/^W\d+$/)) return null; | ||
return openAlex; | ||
} | ||
case "CorpusID": { | ||
const _semantic = parseInt(this.id.trim(), 10); | ||
const semantic = `${_semantic}`; | ||
if (!semantic) return null; | ||
return semantic; | ||
} | ||
default: | ||
return this.id; | ||
} | ||
} | ||
|
||
/** | ||
* Clean the ID if possible | ||
* @returns The cleaned ID or null if it couldn't be cleaned | ||
*/ | ||
cleaned(): this | null { | ||
if (this.cleanID) { | ||
this.id = this.cleanID; | ||
return this; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
get zoteroIdentifier(): | ||
| { DOI: string } | ||
| { ISBN: string } | ||
| { arXiv: string } | ||
| { adsBibcode: string } | ||
| { PMID: string } | ||
| null { | ||
return Zotero.Utilities.extractIdentifiers(this.id)[0] ?? null; | ||
} | ||
|
||
get comparable(): string | undefined { | ||
const rawID = this.cleanID?.toLowerCase(); | ||
return rawID ? `${this.type}:${rawID}` : undefined; | ||
} | ||
|
||
static readonly allTypes: PIDType[] = [ | ||
"DOI", | ||
"ISBN", | ||
"QID", | ||
"OMID", | ||
"arXiv", | ||
"OpenAlex", | ||
"MAG", | ||
"CorpusID", | ||
"PMID", | ||
"PMCID", | ||
]; | ||
|
||
static readonly showable: PIDType[] = [ | ||
"DOI", | ||
"ISBN", | ||
"QID", | ||
"OMID", | ||
"arXiv", | ||
"OpenAlex", | ||
"CorpusID", | ||
// Don't show PMID or PMCID because we can't fetch citations from them | ||
]; | ||
|
||
static readonly fetchable: PIDType[] = [ | ||
"QID", | ||
"OMID", | ||
"OpenAlex", | ||
"DOI", | ||
"CorpusID", | ||
]; | ||
|
||
static isEqual(a: PID, b: PID): boolean { | ||
if (a.type !== b.type) return false; | ||
const aComp = a.comparable; | ||
const bComp = b.comparable; | ||
return aComp !== null && aComp === bComp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.