Zotero download
download_file(url, file_name, output_dir, chunk_size=10 * 1024, overwrite=False)
Download a file from a given 'url' to a given output_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to download. |
required |
file_name
|
str
|
Name and extension of the target file. |
required |
output_dir
|
Path
|
Path to store the file. |
required |
chunk_size
|
int
|
Size of the temporary file to store while downloading. Defaults to 10*1024. |
10 * 1024
|
overwrite
|
bool
|
Whether or not to overwrite a file with the same name. Defaults to False. |
False
|
Source code in src/kibad_llm/data_integration/zotero_download.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
get_paper_ids_by_title(df, paper_ids_file)
Query to S2 API to find IDs of papers based on their title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
pd.DataFrame with exported Zotero list. |
required |
paper_ids_file
|
Path | str
|
Text file to keep state of downloaded papers. |
required |
Returns:
| Type | Description |
|---|---|
Path | str
|
None | Path | str: Path to the |
Source code in src/kibad_llm/data_integration/zotero_download.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
get_papers_from_dois(df, verbose=True)
Download papers based on DOIs. It will query S2 to get the open access url for the paper and return a pd.DataFrame with the urls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Exported list from a Zotero group. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: pd.DataFrame with open access url for the papers. |
Source code in src/kibad_llm/data_integration/zotero_download.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
get_s2_data(ids)
Returns a dict with data about a paper from SemanticScholar (S2) API. Using DOIs as ID is a very effective way to find the correct paper from S2.
S2 API call documented here
https://api.semanticscholar.org/api-docs/graph#tag/Paper-Data/operation/post_graph_get_papers
Limitations
Can only process 500 paper ids at a time. Can only return up to 10 MB of data at a time. Can only return up to 9999 citations at a time. For a list of supported IDs reference the "Details about a paper" endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
List of paper ids to query SemanticScholar. i.e.: ["649def34f8be52c8b66281af98ae884c09aef38b", "ARXIV:2106.15928"] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
dict with all requested fields. One item per paper id. |
Source code in src/kibad_llm/data_integration/zotero_download.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
get_s2_data_by_title(title)
Returns a dict with paperId, title and matchScore.
Giving the limitations of the API this function uses a
API request documented in
https://api.semanticscholar.org/api-docs/graph#tag/Paper-Data/operation/get_graph_paper_title_search
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title of the paper or publication. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
requests.Response: The response from the S2 API. |
Source code in src/kibad_llm/data_integration/zotero_download.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
main(file_path, output_dir, download_type='doi')
This script allows to download papers based on three methods:
doi: searching ID papers in SemanticScholar using the DOI and then downloading the paper using the open access url.direct: using the URL provided by Zotero that ends with '.pdf'title: searching ID papers in Semantic Scholar using the title of the paper and then downloading the paper using the open access url.
It uses an exported CSV version of any Zotero list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Exported CSV from a Zotero list. |
required |
output_dir
|
Path
|
Directory to store the downloaded papers. |
required |
download_type
|
str
|
Type of download to perform. Options are 'doi', 'direct' and 'title'. Defaults to 'doi'. |
'doi'
|
Source code in src/kibad_llm/data_integration/zotero_download.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |