-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
91 lines (70 loc) · 2.47 KB
/
__init__.py
File metadata and controls
91 lines (70 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
55
56
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
88
89
90
91
"""BibX is a library to work with bibliographic data."""
import logging
from typing import TextIO
from bibx.algorithms.sap import Sap
from bibx.exceptions import BibXError
from bibx.models.article import Article
from bibx.models.collection import Collection
from bibx.sources.openalex import EnrichReferences, OpenAlexSource
from bibx.sources.scopus_bib import ScopusBibSource
from bibx.sources.scopus_csv import ScopusCsvSource
from bibx.sources.scopus_ris import ScopusRisSource
from bibx.sources.wos import WosSource
logger = logging.getLogger(__name__)
__all__ = [
"Article",
"Collection",
"EnrichReferences",
"Sap",
"query_openalex",
"read_any",
"read_scopus_bib",
"read_scopus_csv",
"read_scopus_ris",
"read_wos",
]
__version__ = "0.8.0"
def query_openalex(
query: str,
limit: int = 600,
enrich: EnrichReferences = EnrichReferences.BASIC,
) -> Collection:
"""Query OpenAlex and return a collection."""
return OpenAlexSource(query, limit, enrich=enrich).build()
def read_scopus_bib(*files: TextIO) -> Collection:
"""Take any number of bibtex files from scopus and generates a collection.
:param files: Scopus bib files open.
:return: the collection
"""
return ScopusBibSource(*files).build()
def read_scopus_ris(*files: TextIO) -> Collection:
"""Take any number of ris files from scopus and generates a collection.
:param files: Scopus bib files open.
:return: the collection
"""
return ScopusRisSource(*files).build()
def read_scopus_csv(*files: TextIO) -> Collection:
"""Take any number of csv files from scopus and generates a collection.
:param files: Scopus csv files open.
:return: the collection
"""
return ScopusCsvSource(*files).build()
def read_wos(*files: TextIO) -> Collection:
"""Take any number of wos text files and returns a collection.
:param files: WoS files open.
:return: the collection
"""
return WosSource(*files).build()
def read_any(file: TextIO) -> Collection:
"""Try to read a file with the supported formats."""
for handler in (read_wos, read_scopus_ris, read_scopus_csv, read_scopus_bib):
try:
return handler(file)
except BibXError as e:
logger.debug("Error: %s", e)
except ValueError:
logger.debug(
"Error: the %s function does not support this file", handler.__name__
)
message = "Unsupported file type"
raise ValueError(message)