-
Notifications
You must be signed in to change notification settings - Fork 4
/
constants.py
100 lines (79 loc) · 2.4 KB
/
constants.py
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
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
"""Constants for search-query"""
# pylint: disable=too-few-public-methods
# pylint: disable=line-too-long
from enum import Enum
# noqa: E501
class PLATFORM(Enum):
"""Database identifier"""
WOS = "wos"
PUBMED = "pubmed"
EBSCO = "ebsco"
STRUCTURED = "structured"
PRE_NOTATION = "pre_notation"
class Operators:
"""Operators"""
AND = "AND"
OR = "OR"
NOT = "NOT"
NEAR = "NEAR"
class Fields:
"""Search fields"""
TITLE = "ti"
ALL = "all"
ABSTRACT = "ab"
AUTHOR_KEYWORDS = "au"
@classmethod
def all(cls) -> list:
"""Return all fields as a list."""
return [
value
for key, value in vars(cls).items()
if not key.startswith("_") and not callable(value) and key not in ["all"]
]
# The PLATFORM_FIELD_MAP contains the current mapping of standard Fields to the
# syntax of the databases. If a field is not present in the map, it is assumed
# that the field is not supported by the database.
# If multiple options exist for valid database syntax, only the most common
# option is included in the map. Less common options are replaced in the parser.
# For instance, pubmed recommends [mh]. However, [mesh] is also valid and is replaced
# in the parser.
PLATFORM_FIELD_MAP = {
# fields from
# https://webofscience.help.clarivate.com/en-us/Content/wos-core-collection/woscc-search-field-tags.htm
PLATFORM.WOS: {
Fields.ALL: "ALL=",
Fields.ABSTRACT: "AB=",
Fields.TITLE: "TI=",
},
# fields from https://pubmed.ncbi.nlm.nih.gov/help/
PLATFORM.PUBMED: {
Fields.ALL: "[all]",
Fields.TITLE: "[ti]",
Fields.ABSTRACT: "[ab]",
},
# fields from https://connect.ebsco.com/s/article/Searching-with-Field-Codes?language=en_US
PLATFORM.EBSCO: {
Fields.TITLE: "TI ",
},
}
# For convenience, modules can use the following to translate fields to a DB
PLATFORM_FIELD_TRANSLATION_MAP = {
db: {v: k for k, v in fields.items()} for db, fields in PLATFORM_FIELD_MAP.items()
}
PLATFORM_COMBINED_FIELDS_MAP = {
PLATFORM.PUBMED: {
"[tiab]": [Fields.TITLE, Fields.ABSTRACT],
},
}
class ExitCodes:
"""Exit codes"""
SUCCESS = 0
FAIL = 1
class Colors:
"""Colors for CLI printing"""
RED = "\033[91m"
GREEN = "\033[92m"
ORANGE = "\033[93m"
BLUE = "\033[94m"
END = "\033[0m"