citation-map 1.7__tar.gz → 2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: citation-map
3
- Version: 1.7
3
+ Version: 2.0
4
4
  Summary: A simple tool to generate your Google Scholar citation world map.
5
5
  Home-page: https://github.com/ChenLiu-1996/CitationMap
6
6
  Author: Chen Liu
@@ -16,6 +16,13 @@ License-File: LICENSE.md
16
16
 
17
17
  # Google Scholar Citation World Map
18
18
 
19
+ [![Latest PyPI version](https://img.shields.io/pypi/v/citation-map.svg)](https://pypi.org/project/citation-map/)
20
+ [![PyPI license](https://img.shields.io/pypi/l/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
21
+ [![PyPI download month](https://img.shields.io/pypi/dm/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
22
+ [![PyPI download day](https://img.shields.io/pypi/dd/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
23
+ [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
24
+
25
+
19
26
  [Chen Liu](https://www.chenliu1996.com/), CS PhD Candidate at Yale University.
20
27
 
21
28
  Research areas: Machine Learning, Spatial-Temporal Modeling, Medical Vision, AI4Science.
@@ -32,11 +39,8 @@ If you open it on a browser, you will see your own version of the following cita
32
39
 
33
40
  <img src = "assets/citation_world_map.png" width=800>
34
41
 
35
- ## Warning
36
- 1. Runtime concerns.
37
- - This script is a bit slow. On my personal computer, it takes half a minute to process each citation. If you have thousands of citations, it may or may not be a good idea to use this script.
38
- - I tried to use multiprocessing, but sadly the excessive visits get me blocked by Google Scholar.
39
- - I am a researcher and am not very good at software engineering. If you have any idea how to improve the runtime, you are very welcome to submit a pull request.
42
+ ## News
43
+ `citation-map` has been upgraded to version 2.0! I finally managed to drastically speed up the process using multiprocessing (without being blocked by Google Scholar). On my personal computer, processing my profile with 100 citations took 1 hour with version 1.0 while it's now taking 5 minutes with version 2.0.
40
44
 
41
45
  ## Usage
42
46
  1. Install the package.
@@ -68,6 +72,9 @@ If you open it on a browser, you will see your own version of the following cita
68
72
  output_path: str
69
73
  (default is 'citation_map.html')
70
74
  The path to the output HTML file.
75
+ num_processes: int
76
+ (default is 16)
77
+ Number of separate processes for parallel processing.
71
78
  use_proxy: bool
72
79
  (default is False)
73
80
  If true, we will use a scholarly proxy.
@@ -1,5 +1,12 @@
1
1
  # Google Scholar Citation World Map
2
2
 
3
+ [![Latest PyPI version](https://img.shields.io/pypi/v/citation-map.svg)](https://pypi.org/project/citation-map/)
4
+ [![PyPI license](https://img.shields.io/pypi/l/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
5
+ [![PyPI download month](https://img.shields.io/pypi/dm/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
6
+ [![PyPI download day](https://img.shields.io/pypi/dd/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
7
+ [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
8
+
9
+
3
10
  [Chen Liu](https://www.chenliu1996.com/), CS PhD Candidate at Yale University.
4
11
 
5
12
  Research areas: Machine Learning, Spatial-Temporal Modeling, Medical Vision, AI4Science.
@@ -16,11 +23,8 @@ If you open it on a browser, you will see your own version of the following cita
16
23
 
17
24
  <img src = "assets/citation_world_map.png" width=800>
18
25
 
19
- ## Warning
20
- 1. Runtime concerns.
21
- - This script is a bit slow. On my personal computer, it takes half a minute to process each citation. If you have thousands of citations, it may or may not be a good idea to use this script.
22
- - I tried to use multiprocessing, but sadly the excessive visits get me blocked by Google Scholar.
23
- - I am a researcher and am not very good at software engineering. If you have any idea how to improve the runtime, you are very welcome to submit a pull request.
26
+ ## News
27
+ `citation-map` has been upgraded to version 2.0! I finally managed to drastically speed up the process using multiprocessing (without being blocked by Google Scholar). On my personal computer, processing my profile with 100 citations took 1 hour with version 1.0 while it's now taking 5 minutes with version 2.0.
24
28
 
25
29
  ## Usage
26
30
  1. Install the package.
@@ -52,6 +56,9 @@ If you open it on a browser, you will see your own version of the following cita
52
56
  output_path: str
53
57
  (default is 'citation_map.html')
54
58
  The path to the output HTML file.
59
+ num_processes: int
60
+ (default is 16)
61
+ Number of separate processes for parallel processing.
55
62
  use_proxy: bool
56
63
  (default is False)
57
64
  If true, we will use a scholarly proxy.
@@ -0,0 +1,165 @@
1
+ import random
2
+ import time
3
+ import itertools
4
+ from scholarly import scholarly, ProxyGenerator
5
+ from geopy.geocoders import Nominatim
6
+ import folium
7
+ from tqdm import tqdm
8
+ from multiprocessing import Pool
9
+
10
+
11
+ def fetch_google_scholar_profile(scholar_id):
12
+ '''
13
+ Step 1: Fetch Google Scholar Profile using Scholar ID.
14
+ '''
15
+ author = scholarly.search_author_id(scholar_id)
16
+ author = scholarly.fill(author, sections=['publications'])
17
+ return author
18
+
19
+ def find_all_citing_institutions(publications, num_processes: int = 16):
20
+ '''
21
+ Step 2. Final all citing institutions (i.e., insitutions of citing authors).
22
+ '''
23
+
24
+ # Fetch metadata for all publications, in parallel.
25
+ with Pool(processes=num_processes) as pool:
26
+ all_publications = list(tqdm(pool.imap(__fill_publication_metadata, publications), desc='Filling metadata for all publications...', total=len(publications)))
27
+
28
+ # Find all citing papers from all publications, in parallel.
29
+ with Pool(processes=num_processes) as pool:
30
+ all_citing_papers_nested = list(tqdm(pool.imap(__citing_papers_from_publication, all_publications), desc='Finding all citations...', total=len(all_publications)))
31
+ all_citing_papers = list(itertools.chain(*all_citing_papers_nested))
32
+
33
+ # Find all citing authors from all citing papers, in parallel.
34
+ with Pool(processes=num_processes) as pool:
35
+ all_citing_authors_nested = list(tqdm(pool.imap(__authors_from_papers, all_citing_papers), desc='Finding all citing authors...', total=len(all_citing_papers)))
36
+ all_citing_authors = list(itertools.chain(*all_citing_authors_nested))
37
+
38
+ # Find all citing insitutions from all citing authors, in parallel.
39
+ with Pool(processes=num_processes) as pool:
40
+ all_citing_insitutions = list(tqdm(pool.imap(__institutions_from_authors, all_citing_authors), desc='Finding all citing institutions...', total=len(all_citing_authors)))
41
+
42
+ return sorted(all_citing_insitutions)
43
+
44
+ def text_to_geocode(institutions):
45
+ '''
46
+ Step 3: Convert institutions in plain text to Geocode.
47
+ '''
48
+ geolocator = Nominatim(user_agent='citation_mapper')
49
+ coordinates = []
50
+ for institution in institutions:
51
+ try:
52
+ geo_location = geolocator.geocode(institution)
53
+ if geo_location:
54
+ coordinates.append((geo_location.latitude, geo_location.longitude, institution))
55
+ except Exception as e:
56
+ print(f'Error geocoding institution {institution}: {e}')
57
+ return coordinates
58
+
59
+ def create_map(coordinates, pin_colorful: bool = True):
60
+ '''
61
+ Step 4: Create the Citation World Map.
62
+ '''
63
+ citation_map = folium.Map(location=[20, 0], zoom_start=2)
64
+ if pin_colorful:
65
+ colors = ['red', 'blue', 'green', 'purple', 'orange', 'darkred',
66
+ 'lightred', 'beige', 'darkblue', 'darkgreen', 'cadetblue',
67
+ 'darkpurple', 'pink', 'lightblue', 'lightgreen',
68
+ 'gray', 'black', 'lightgray']
69
+ for lat, lon, location in coordinates:
70
+ color = random.choice(colors)
71
+ folium.Marker([lat, lon], popup=location, icon=folium.Icon(color=color)).add_to(citation_map)
72
+ else:
73
+ for lat, lon, location in coordinates:
74
+ folium.Marker([lat, lon], popup=location).add_to(citation_map)
75
+ return citation_map
76
+
77
+ def __fill_publication_metadata(pub):
78
+ time.sleep(random.uniform(1, 5)) # Random delay to reduce risk of being blocked.
79
+ return scholarly.fill(pub)
80
+
81
+ def __citing_papers_from_publication(pub):
82
+ if 'citedby_url' in pub:
83
+ time.sleep(random.uniform(1, 5)) # Random delay to reduce risk of being blocked.
84
+ citing_paper_obj = scholarly.citedby(pub)
85
+ return [item for item in citing_paper_obj]
86
+ return []
87
+
88
+ def __authors_from_papers(citing_paper):
89
+ if 'author_id' in citing_paper:
90
+ author_id_list = citing_paper['author_id']
91
+ author_id_list = [item for item in author_id_list if item] # Filter out empty author ids.
92
+ return author_id_list
93
+ return []
94
+
95
+ def __institutions_from_authors(author_id):
96
+ time.sleep(random.uniform(1, 5)) # Random delay to reduce risk of being blocked.
97
+ citing_author = scholarly.search_author_id(author_id)
98
+ citing_author = scholarly.fill(citing_author)
99
+ if 'affiliation' in citing_author:
100
+ return citing_author['affiliation']
101
+ return []
102
+
103
+ def generate_citation_map(scholar_id: str,
104
+ output_path: str = 'citation_map.html',
105
+ num_processes: int = 16,
106
+ use_proxy: bool = False,
107
+ pin_colorful: bool = True,
108
+ print_citing_institutions: bool = True):
109
+ '''
110
+ Google Scholar Citation World Map.
111
+
112
+ Parameters
113
+ ----
114
+ scholar_id: str
115
+ Your Google Scholar ID.
116
+ output_path: str
117
+ (default is 'citation_map.html')
118
+ The path to the output HTML file.
119
+ num_processes: int
120
+ (default is 16)
121
+ Number of separate processes for parallel processing.
122
+ use_proxy: bool
123
+ (default is False)
124
+ If true, we will use a scholarly proxy.
125
+ It is necessary for some environments to avoid blocks, but it usually makes things slower.
126
+ pin_colorful: bool
127
+ (default is True)
128
+ If true, the location pins will have a variety of colors.
129
+ Otherwise, it will only have one color.
130
+ print_citing_institutions: bool
131
+ (default is True)
132
+ If true, print the list of citing institutions (affiliations of citing authors).
133
+ '''
134
+
135
+ if use_proxy:
136
+ pg = ProxyGenerator()
137
+ pg.FreeProxies()
138
+ scholarly.use_proxy(pg)
139
+ print('Using proxy.')
140
+
141
+ author_profile = fetch_google_scholar_profile(scholar_id)
142
+ print('\nAuthor profile found, with %d publications.\n' % len(author_profile['publications']))
143
+
144
+ institutions = find_all_citing_institutions(author_profile['publications'], num_processes=num_processes)
145
+ print('\nA total of %d citing institutions recorded.' % len(institutions))
146
+
147
+ coordinates = text_to_geocode(institutions)
148
+ print('\nConverted the institutions to Geocodes.')
149
+
150
+ citation_map = create_map(coordinates, pin_colorful=pin_colorful)
151
+ citation_map.save(output_path)
152
+ print('\nMap created and saved as citation_map.html.')
153
+
154
+ if print_citing_institutions:
155
+ print('\nList of all citing institutions:\n')
156
+ for institution in institutions:
157
+ print(institution)
158
+ return
159
+
160
+
161
+ if __name__ == '__main__':
162
+ # Replace this with your Google Scholar ID.
163
+ scholar_id = '3rDjnykAAAAJ'
164
+ generate_citation_map(scholar_id, output_path='citation_map.html',
165
+ num_processes=16, use_proxy=False, pin_colorful=True, print_citing_institutions=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: citation-map
3
- Version: 1.7
3
+ Version: 2.0
4
4
  Summary: A simple tool to generate your Google Scholar citation world map.
5
5
  Home-page: https://github.com/ChenLiu-1996/CitationMap
6
6
  Author: Chen Liu
@@ -16,6 +16,13 @@ License-File: LICENSE.md
16
16
 
17
17
  # Google Scholar Citation World Map
18
18
 
19
+ [![Latest PyPI version](https://img.shields.io/pypi/v/citation-map.svg)](https://pypi.org/project/citation-map/)
20
+ [![PyPI license](https://img.shields.io/pypi/l/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
21
+ [![PyPI download month](https://img.shields.io/pypi/dm/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
22
+ [![PyPI download day](https://img.shields.io/pypi/dd/citation-map.svg)](https://pypi.python.org/pypi/citation-map/)
23
+ [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
24
+
25
+
19
26
  [Chen Liu](https://www.chenliu1996.com/), CS PhD Candidate at Yale University.
20
27
 
21
28
  Research areas: Machine Learning, Spatial-Temporal Modeling, Medical Vision, AI4Science.
@@ -32,11 +39,8 @@ If you open it on a browser, you will see your own version of the following cita
32
39
 
33
40
  <img src = "assets/citation_world_map.png" width=800>
34
41
 
35
- ## Warning
36
- 1. Runtime concerns.
37
- - This script is a bit slow. On my personal computer, it takes half a minute to process each citation. If you have thousands of citations, it may or may not be a good idea to use this script.
38
- - I tried to use multiprocessing, but sadly the excessive visits get me blocked by Google Scholar.
39
- - I am a researcher and am not very good at software engineering. If you have any idea how to improve the runtime, you are very welcome to submit a pull request.
42
+ ## News
43
+ `citation-map` has been upgraded to version 2.0! I finally managed to drastically speed up the process using multiprocessing (without being blocked by Google Scholar). On my personal computer, processing my profile with 100 citations took 1 hour with version 1.0 while it's now taking 5 minutes with version 2.0.
40
44
 
41
45
  ## Usage
42
46
  1. Install the package.
@@ -68,6 +72,9 @@ If you open it on a browser, you will see your own version of the following cita
68
72
  output_path: str
69
73
  (default is 'citation_map.html')
70
74
  The path to the output HTML file.
75
+ num_processes: int
76
+ (default is 16)
77
+ Number of separate processes for parallel processing.
71
78
  use_proxy: bool
72
79
  (default is False)
73
80
  If true, we will use a scholarly proxy.
@@ -5,7 +5,7 @@ with open('README.md') as f:
5
5
 
6
6
  setup(
7
7
  name='citation-map',
8
- version='1.7',
8
+ version='2.0',
9
9
  license='MIT',
10
10
  author='Chen Liu',
11
11
  author_email='chen.liu.cl2482@yale.edu',
@@ -1,137 +0,0 @@
1
- from scholarly import scholarly, ProxyGenerator
2
- from geopy.geocoders import Nominatim
3
- import folium
4
- from tqdm import tqdm
5
- import random
6
-
7
-
8
- def __fetch_google_scholar_profile(scholar_id):
9
- '''
10
- Step 1: Fetch Google Scholar Profile using Scholar ID.
11
- '''
12
- author = scholarly.search_author_id(scholar_id)
13
- author = scholarly.fill(author, sections=['publications'])
14
- return author
15
-
16
- def __parse_profile(author):
17
- '''
18
- Step 2: Parse the Profile and find citing author affiliations.
19
-
20
- NOTE: Usually this is the most time-consuming part of the code.
21
- I tried to parallel process this, which indeed makes it faster,
22
- but unfortunately the frequent visiting makes Google Scholar block me. T_T
23
- You are very welcome to submit a pull request if you can help optimize this code.
24
- '''
25
- citing_institutions = []
26
- for pub_idx, pub in enumerate(tqdm(author['publications'], desc='publication iterator')):
27
- pub = scholarly.fill(pub)
28
- if 'citedby_url' in pub:
29
- citing_paper_obj = scholarly.citedby(pub)
30
- citing_paper_list = [item for item in citing_paper_obj]
31
- for citing_paper in tqdm(citing_paper_list,
32
- desc='citation iterator (for publication #%d/%d)' % (
33
- pub_idx + 1, len(author['publications'])
34
- )):
35
- if 'author_id' in citing_paper:
36
- author_id_list = citing_paper['author_id']
37
- author_id_list = [item for item in author_id_list if item] # Filter out empty author ids.
38
-
39
- for author_id in author_id_list:
40
- citing_author = scholarly.search_author_id(author_id)
41
- citing_author = scholarly.fill(citing_author)
42
- if 'affiliation' in citing_author:
43
- citing_institutions.append(citing_author['affiliation'])
44
- return citing_institutions
45
-
46
- def __text_to_geocode(institutions):
47
- '''
48
- Step 3: Convert institutions in plain text to Geocode.
49
- '''
50
- geolocator = Nominatim(user_agent='citation_mapper')
51
- coordinates = []
52
- for institution in institutions:
53
- try:
54
- geo_location = geolocator.geocode(institution)
55
- if geo_location:
56
- coordinates.append((geo_location.latitude, geo_location.longitude, institution))
57
- except Exception as e:
58
- print(f'Error geocoding institution {institution}: {e}')
59
- return coordinates
60
-
61
- def __create_map(coordinates, pin_colorful: bool = True):
62
- '''
63
- Step 4: Create the Map.
64
- '''
65
- citation_map = folium.Map(location=[20, 0], zoom_start=2)
66
- if pin_colorful:
67
- colors = ['red', 'blue', 'green', 'purple', 'orange', 'darkred',
68
- 'lightred', 'beige', 'darkblue', 'darkgreen', 'cadetblue',
69
- 'darkpurple', 'pink', 'lightblue', 'lightgreen',
70
- 'gray', 'black', 'lightgray']
71
- for lat, lon, location in coordinates:
72
- color = random.choice(colors)
73
- folium.Marker([lat, lon], popup=location, icon=folium.Icon(color=color)).add_to(citation_map)
74
- else:
75
- for lat, lon, location in coordinates:
76
- folium.Marker([lat, lon], popup=location).add_to(citation_map)
77
- return citation_map
78
-
79
- def generate_citation_map(scholar_id: str,
80
- output_path: str = 'citation_map.html',
81
- use_proxy: bool = False,
82
- pin_colorful: bool = True,
83
- print_citing_institutions: bool = True):
84
- '''
85
- Google Scholar Citation World Map.
86
-
87
- Parameters
88
- ----
89
- scholar_id: str
90
- Your Google Scholar ID.
91
- output_path: str
92
- (default is 'citation_map.html')
93
- The path to the output HTML file.
94
- use_proxy: bool
95
- (default is False)
96
- If true, we will use a scholarly proxy.
97
- It is necessary for some environments to avoid blocks, but it usually makes things slower.
98
- pin_colorful: bool
99
- (default is True)
100
- If true, the location pins will have a variety of colors.
101
- Otherwise, it will only have one color.
102
- print_citing_institutions: bool
103
- (default is True)
104
- If true, print the list of citing institutions (affiliations of citing authors).
105
- '''
106
-
107
- if use_proxy:
108
- pg = ProxyGenerator()
109
- pg.FreeProxies()
110
- scholarly.use_proxy(pg)
111
- print('Using proxy.')
112
-
113
- author = __fetch_google_scholar_profile(scholar_id)
114
- print('\nAuthor profile found, with %d publications.\n' % len(author['publications']))
115
-
116
- institutions = __parse_profile(author)
117
- print('\nA total of %d citating institutions recorded.' % len(institutions))
118
-
119
- coordinates = __text_to_geocode(institutions)
120
- print('\nConverted the institutions to Geocodes.')
121
-
122
- citation_map = __create_map(coordinates, pin_colorful=pin_colorful)
123
- citation_map.save(output_path)
124
- print('\nMap created and saved as citation_map.html.')
125
-
126
- if print_citing_institutions:
127
- print('\nList of all citing institutions:\n')
128
- for institution in sorted(institutions):
129
- print(institution)
130
- return
131
-
132
-
133
- if __name__ == '__main__':
134
- # Replace this with your Google Scholar ID.
135
- scholar_id = '3rDjnykAAAAJ'
136
- generate_citation_map(scholar_id, output_path='citation_map.html',
137
- use_proxy=False, pin_colorful=True, print_citing_institutions=True)
File without changes
File without changes