-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_search_string.py
More file actions
113 lines (92 loc) · 4.64 KB
/
Copy pathcreate_search_string.py
File metadata and controls
113 lines (92 loc) · 4.64 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# This script creates search string and writes them into text files.
# imports
from itertools import product
import re
# define your search string components:
# text blocks within an inner list are not combined in one string, but are used rotationally
# The blocks from the inner lists are connected with an AND in the final search string
# use empty strings to make parts optional
# "NOT"-clauses you be inserted last
# INFO: Wildcards and logical operators need to be supported by the database engine
search_terms = [
["Trust*", "Trustworthy", "Trustworth*",
"(Trustworth* OR Responsib*)",],
["Artificial AND Intelligence", "((Artificial AND Intelligence) OR AI)",
"((Artificial AND Intelligence) OR AI OR ML OR (Machine AND Learning))"],
["Platform", "Development", "Development AND Platform",
"(Development OR Platform)"],
["", "characteristic*", "(trade-off* OR tradeoff*)",
"(trade-off* OR tradeoff* OR characteristic*)", "(trade-off* OR tradeoff*) AND characteristic*"] # ,
# ["", "NOT (generative OR Transformer* OR ChatGPT OR (Large AND Language AND Model))"],
]
# Specify the Name of the fields you want to search in
# Please make sure that the names are correct for the database you want to search in
# If you don't want to specify a field, then you should enter an empty string.
fields_to_search = ["", "TITLE", "ABSTRACT"]
fields_to_search_acm = ["", "TITLE", "ABSTRACT", "Full text"]
fields_to_search_ebscohost = ["", "TI", "AB", "TX"]
fields_to_search_proquest = ["", "TI", "AB", "FT"]
fields_to_search_ieee = ["", "Document Title", "Abstract", "Full Text Only"]
def construct_string_standard(combinations):
search_string_list = []
for combi in combinations:
if combi[0] != "":
search_string = "\n" + combi[0] + "("
else:
search_string = "\n("
for combi_index in range(1, len(combi)):
if combi[combi_index] != "":
search_string += " AND " + combi[combi_index]
search_string += ")"
# replace "(AND" to "(" at the beginning of search string
search_string = search_string.replace("( AND ", "(")
# replace "AND NOT" to "NOT"
search_string = search_string.replace(
"AND NOT", "NOT")
search_string_list.append(search_string)
return search_string_list
def construct_string_ieeexplore(combinations):
search_string_list = []
for combi in combinations:
search_string = ""
for combi_index in range(1, len(combi)):
if combi[combi_index] != "":
search_string += " AND " + combi[combi_index]
# Insert line break and remove the first " AND "
search_string = "\n" + search_string[5:]
if combi[0] != "":
# Ingest the field name before every search term as ieee requires it.
repl_string = "\"" + combi[0] + "\": \\1"
search_string = re.sub(
r"(\b(?!AND\b|OR\b|NOT\b)\w)", repl_string, search_string)
# replace "AND NOT" to "NOT"
search_string = search_string.replace(
"AND NOT", "NOT")
search_string_list.append(search_string)
return search_string_list
def create_search_string(search_terms: list, fields_to_search: list, database: str):
# combine the components to get all possible combinations
input_list = search_terms.copy()
input_list.insert(0, fields_to_search)
combinations = list(product(*input_list))
if database.lower() == "web of science":
database = "wos"
if database.lower() in ["acm", "wos", "ais", "ebscohost", "proquest"]:
search_string_list = construct_string_standard(combinations)
elif database.lower() == "ieeexplore":
search_string_list = construct_string_ieeexplore(combinations)
else:
print("INFO: You specified a not known database. The standard string generation method is used. The generated search string might not work.")
search_string_list = construct_string_standard(combinations)
out_file_name = "data/search_strings_" + database.lower() + ".txt"
with open(out_file_name, "w") as f:
f.writelines(search_string_list)
return
if __name__ == "__main__":
# by default strings for all databases are generated
create_search_string(search_terms, fields_to_search_ieee, "ieeexplore")
create_search_string(search_terms, fields_to_search_acm, "acm")
create_search_string(search_terms, fields_to_search, "ais")
create_search_string(search_terms, fields_to_search_ebscohost, "ebscohost")
create_search_string(search_terms, fields_to_search_proquest, "proquest")
create_search_string(search_terms, fields_to_search, "web of science")