citation-map 3.0__tar.gz → 3.1__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.
- {citation-map-3.0 → citation-map-3.1}/PKG-INFO +1 -1
- {citation-map-3.0 → citation-map-3.1}/citation_map/citation_map.py +47 -33
- {citation-map-3.0 → citation-map-3.1}/citation_map.egg-info/PKG-INFO +1 -1
- {citation-map-3.0 → citation-map-3.1}/citation_map.egg-info/requires.txt +0 -1
- {citation-map-3.0 → citation-map-3.1}/setup.py +2 -2
- {citation-map-3.0 → citation-map-3.1}/LICENSE.md +0 -0
- {citation-map-3.0 → citation-map-3.1}/README.md +0 -0
- {citation-map-3.0 → citation-map-3.1}/citation_map/__init__.py +0 -0
- {citation-map-3.0 → citation-map-3.1}/citation_map.egg-info/SOURCES.txt +0 -0
- {citation-map-3.0 → citation-map-3.1}/citation_map.egg-info/dependency_links.txt +0 -0
- {citation-map-3.0 → citation-map-3.1}/citation_map.egg-info/top_level.txt +0 -0
- {citation-map-3.0 → citation-map-3.1}/setup.cfg +0 -0
|
@@ -3,8 +3,7 @@ import random
|
|
|
3
3
|
import time
|
|
4
4
|
import itertools
|
|
5
5
|
|
|
6
|
-
from typing import List
|
|
7
|
-
import numpy as np
|
|
6
|
+
from typing import List, Tuple
|
|
8
7
|
from scholarly import scholarly, ProxyGenerator
|
|
9
8
|
from geopy.geocoders import Nominatim
|
|
10
9
|
import folium
|
|
@@ -20,57 +19,71 @@ def fetch_google_scholar_profile(scholar_id: str):
|
|
|
20
19
|
author = scholarly.fill(author, sections=['publications'])
|
|
21
20
|
return author
|
|
22
21
|
|
|
23
|
-
def find_all_citing_institutions(publications, num_processes: int = 16) -> List[str]:
|
|
22
|
+
def find_all_citing_institutions(publications, num_processes: int = 16) -> List[Tuple[str]]:
|
|
24
23
|
'''
|
|
25
24
|
Step 2. Final all citing institutions (i.e., insitutions of citing authors).
|
|
26
25
|
'''
|
|
27
26
|
# Fetch metadata for all publications, in parallel.
|
|
28
27
|
with Pool(processes=num_processes) as pool:
|
|
29
|
-
all_publications = list(tqdm(pool.imap(__fill_publication_metadata, publications),
|
|
28
|
+
all_publications = list(tqdm(pool.imap(__fill_publication_metadata, publications),
|
|
29
|
+
desc='Filling metadata for all publications...',
|
|
30
|
+
total=len(publications)))
|
|
30
31
|
|
|
31
32
|
# Find all citing papers from all publications, in parallel.
|
|
32
33
|
with Pool(processes=num_processes) as pool:
|
|
33
|
-
all_citing_papers_nested = list(tqdm(pool.imap(__citing_papers_from_publication, all_publications),
|
|
34
|
+
all_citing_papers_nested = list(tqdm(pool.imap(__citing_papers_from_publication, all_publications),
|
|
35
|
+
desc='Finding all citations...',
|
|
36
|
+
total=len(all_publications)))
|
|
34
37
|
all_citing_papers = list(itertools.chain(*all_citing_papers_nested))
|
|
35
38
|
|
|
36
39
|
# Find all citing authors from all citing papers, in parallel.
|
|
37
40
|
with Pool(processes=num_processes) as pool:
|
|
38
|
-
all_citing_authors_nested = list(tqdm(pool.imap(__authors_from_papers, all_citing_papers),
|
|
41
|
+
all_citing_authors_nested = list(tqdm(pool.imap(__authors_from_papers, all_citing_papers),
|
|
42
|
+
desc='Finding all citing authors...',
|
|
43
|
+
total=len(all_citing_papers)))
|
|
39
44
|
all_citing_authors = list(itertools.chain(*all_citing_authors_nested))
|
|
40
45
|
|
|
41
46
|
# Find all citing insitutions from all citing authors, in parallel.
|
|
42
47
|
with Pool(processes=num_processes) as pool:
|
|
43
|
-
|
|
48
|
+
author_institution_tuple_list = list(tqdm(pool.imap(__institutions_from_authors, all_citing_authors),
|
|
49
|
+
desc='Finding all citing institutions...',
|
|
50
|
+
total=len(all_citing_authors)))
|
|
44
51
|
|
|
45
|
-
return
|
|
52
|
+
return author_institution_tuple_list
|
|
46
53
|
|
|
47
|
-
def clean_institution_names(
|
|
54
|
+
def clean_institution_names(author_institution_tuple_list: List[Tuple[str]]) -> List[Tuple[str]]:
|
|
48
55
|
'''
|
|
49
56
|
Step 3. Clean up the name of institutions from the author's self-entered Google Scholar affiliation.
|
|
50
57
|
'''
|
|
51
|
-
|
|
52
|
-
for institution_string in
|
|
58
|
+
cleaned_author_institution_tuple_list = []
|
|
59
|
+
for author_name, institution_string in author_institution_tuple_list:
|
|
53
60
|
# Use a regular expression to split the string by ',', ';', or 'and'.
|
|
54
61
|
substring_list = [part.strip() for part in re.split(r'[;,]|\band\b', institution_string)]
|
|
55
62
|
for substring in substring_list:
|
|
56
63
|
# Use a regular expression to remove anything before 'at', or '@'.
|
|
57
64
|
cleaned_institution = re.sub(r'.*?\bat\b|.*?@', '', substring, flags=re.IGNORECASE).strip()
|
|
58
65
|
# Use a regular expression to check if the string is a common weird string.
|
|
59
|
-
is_common_weird_string = re.search(
|
|
66
|
+
is_common_weird_string = re.search(
|
|
67
|
+
re.compile(
|
|
68
|
+
r'\b(director|manager|chair|engineer|programmer|scientist|professor|lecturer|phd|student|ph\.d|department of)\b',
|
|
69
|
+
re.IGNORECASE),
|
|
70
|
+
substring)
|
|
60
71
|
if not is_common_weird_string:
|
|
61
|
-
|
|
62
|
-
return
|
|
72
|
+
cleaned_author_institution_tuple_list.append((author_name, cleaned_institution))
|
|
73
|
+
return cleaned_author_institution_tuple_list
|
|
63
74
|
|
|
64
|
-
def institution_text_to_geocode(
|
|
75
|
+
def institution_text_to_geocode(author_institution_tuple_list: List[Tuple[str]], num_processes: int = 16) -> List[Tuple[str]]:
|
|
65
76
|
'''
|
|
66
77
|
Step 4: Convert institutions in plain text to Geocode.
|
|
67
78
|
'''
|
|
68
79
|
with Pool(processes=num_processes) as pool:
|
|
69
|
-
coordinates = list(tqdm(pool.imap(__text_to_geocode,
|
|
80
|
+
coordinates = list(tqdm(pool.imap(__text_to_geocode, author_institution_tuple_list),
|
|
81
|
+
desc='Finding all geographic coordinates...',
|
|
82
|
+
total=len(author_institution_tuple_list)))
|
|
70
83
|
coordinates = [item for item in coordinates if item is not None] # Filter out empty coordinates.
|
|
71
84
|
return coordinates
|
|
72
85
|
|
|
73
|
-
def create_map(coordinates, pin_colorful: bool = True):
|
|
86
|
+
def create_map(coordinates: List[Tuple[str]], pin_colorful: bool = True):
|
|
74
87
|
'''
|
|
75
88
|
Step 5: Create the Citation World Map.
|
|
76
89
|
'''
|
|
@@ -80,12 +93,12 @@ def create_map(coordinates, pin_colorful: bool = True):
|
|
|
80
93
|
'lightred', 'beige', 'darkblue', 'darkgreen', 'cadetblue',
|
|
81
94
|
'darkpurple', 'pink', 'lightblue', 'lightgreen',
|
|
82
95
|
'gray', 'black', 'lightgray']
|
|
83
|
-
for lat, lon, location in coordinates:
|
|
96
|
+
for lat, lon, author_name, location in coordinates:
|
|
84
97
|
color = random.choice(colors)
|
|
85
|
-
folium.Marker([lat, lon], popup=location, icon=folium.Icon(color=color)).add_to(citation_map)
|
|
98
|
+
folium.Marker([lat, lon], popup='%s (%s)' % (location, author_name), icon=folium.Icon(color=color)).add_to(citation_map)
|
|
86
99
|
else:
|
|
87
|
-
for lat, lon, location in coordinates:
|
|
88
|
-
folium.Marker([lat, lon], popup=location).add_to(citation_map)
|
|
100
|
+
for lat, lon, author_name, location in coordinates:
|
|
101
|
+
folium.Marker([lat, lon], popup='%s (%s)' % (location, author_name)).add_to(citation_map)
|
|
89
102
|
return citation_map
|
|
90
103
|
|
|
91
104
|
def __fill_publication_metadata(pub):
|
|
@@ -111,15 +124,16 @@ def __institutions_from_authors(author_id):
|
|
|
111
124
|
citing_author = scholarly.search_author_id(author_id)
|
|
112
125
|
citing_author = scholarly.fill(citing_author)
|
|
113
126
|
if 'affiliation' in citing_author:
|
|
114
|
-
return citing_author['affiliation']
|
|
127
|
+
return (citing_author['name'], citing_author['affiliation'])
|
|
115
128
|
return []
|
|
116
129
|
|
|
117
|
-
def __text_to_geocode(
|
|
130
|
+
def __text_to_geocode(author_institution_tuple):
|
|
118
131
|
geolocator = Nominatim(user_agent='citation_mapper')
|
|
119
132
|
try:
|
|
120
|
-
|
|
133
|
+
author_name, institution_name = author_institution_tuple
|
|
134
|
+
geo_location = geolocator.geocode(institution_name)
|
|
121
135
|
if geo_location:
|
|
122
|
-
return (geo_location.latitude, geo_location.longitude,
|
|
136
|
+
return (geo_location.latitude, geo_location.longitude, author_name, institution_name)
|
|
123
137
|
except:
|
|
124
138
|
return None
|
|
125
139
|
|
|
@@ -164,22 +178,22 @@ def generate_citation_map(scholar_id: str,
|
|
|
164
178
|
author_profile = fetch_google_scholar_profile(scholar_id)
|
|
165
179
|
print('\nAuthor profile found, with %d publications.\n' % len(author_profile['publications']))
|
|
166
180
|
|
|
167
|
-
|
|
168
|
-
print('\nA total of %d citing institutions recorded.\n' % len(
|
|
181
|
+
author_institution_tuple_list = find_all_citing_institutions(author_profile['publications'], num_processes=num_processes)
|
|
182
|
+
print('\nA total of %d citing institutions recorded.\n' % len(author_institution_tuple_list))
|
|
169
183
|
|
|
170
184
|
if print_citing_institutions:
|
|
171
|
-
print('\nList of all citing institutions before cleaning:\n')
|
|
172
|
-
for item in
|
|
185
|
+
print('\nList of all citing authors and institutions before cleaning:\n')
|
|
186
|
+
for item in sorted(author_institution_tuple_list):
|
|
173
187
|
print(item)
|
|
174
188
|
|
|
175
|
-
|
|
189
|
+
cleaned_author_institution_tuple_list = clean_institution_names(author_institution_tuple_list)
|
|
176
190
|
|
|
177
191
|
if print_citing_institutions:
|
|
178
|
-
print('\nList of all citing institutions after cleaning:\n')
|
|
179
|
-
for item in
|
|
192
|
+
print('\nList of all citing authors and institutions after cleaning:\n')
|
|
193
|
+
for item in sorted(cleaned_author_institution_tuple_list):
|
|
180
194
|
print(item)
|
|
181
195
|
|
|
182
|
-
coordinates = institution_text_to_geocode(
|
|
196
|
+
coordinates = institution_text_to_geocode(author_institution_tuple_list + cleaned_author_institution_tuple_list)
|
|
183
197
|
print('\nConverted the institutions to Geocodes.')
|
|
184
198
|
|
|
185
199
|
citation_map = create_map(coordinates, pin_colorful=pin_colorful)
|
|
@@ -5,7 +5,7 @@ with open('README.md') as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='citation-map',
|
|
8
|
-
version='3.
|
|
8
|
+
version='3.1',
|
|
9
9
|
license='MIT',
|
|
10
10
|
author='Chen Liu',
|
|
11
11
|
author_email='chen.liu.cl2482@yale.edu',
|
|
@@ -16,7 +16,7 @@ setup(
|
|
|
16
16
|
long_description_content_type='text/markdown',
|
|
17
17
|
url='https://github.com/ChenLiu-1996/CitationMap',
|
|
18
18
|
keywords='citation map, citation world map, google scholar',
|
|
19
|
-
install_requires=['scholarly', 'geopy', 'folium', 'tqdm'
|
|
19
|
+
install_requires=['scholarly', 'geopy', 'folium', 'tqdm'],
|
|
20
20
|
classifiers=[
|
|
21
21
|
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
|
|
22
22
|
'Intended Audience :: Developers', # Define that your audience are developers
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|