Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
272b4c0909 | ||
|
|
3c5939e4f6 | ||
|
|
6d176ee93a |
@@ -52,10 +52,17 @@ data = []
|
|||||||
|
|
||||||
|
|
||||||
def parse_csv(file_path):
|
def parse_csv(file_path):
|
||||||
|
try:
|
||||||
with open(file_path, "r") as file:
|
with open(file_path, "r") as file:
|
||||||
reader = csv.reader(file)
|
reader = csv.reader(file)
|
||||||
for row in reader:
|
for row in reader:
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"Error: File {file_path} not found")
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error reading file: {e}")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def extract_journal_titles(data):
|
def extract_journal_titles(data):
|
||||||
@@ -70,32 +77,42 @@ def extract_journal_titles(data):
|
|||||||
|
|
||||||
def extract_title_keywords(data):
|
def extract_title_keywords(data):
|
||||||
title_keywords = []
|
title_keywords = []
|
||||||
re_words = []
|
|
||||||
for row in data:
|
for row in data:
|
||||||
raw_words = row[2].split(" ")
|
raw_words = row[2].split(" ")
|
||||||
row_words = []
|
|
||||||
for word in raw_words:
|
for word in raw_words:
|
||||||
re_word = re.sub(r"[^a-zA-Z\-]", "", word.lower())
|
re_word = re.sub(r"[^a-zA-Z\-]", "", word.lower())
|
||||||
if re_word not in stop_words:
|
if re_word not in stop_words and re_word != "":
|
||||||
re_words.append(re_word)
|
title_keywords.append(re_word)
|
||||||
row_words.append(re_word)
|
return Counter(title_keywords).most_common(30)
|
||||||
title_keywords = [(word, row_words) for word in re_words]
|
|
||||||
return title_keywords
|
|
||||||
|
|
||||||
|
|
||||||
def print_title_keywords(data):
|
def print_title_keywords(data):
|
||||||
title_keywords = extract_title_keywords(data)
|
title_keywords = extract_title_keywords(data)
|
||||||
title_keywords = [word[0] for word in title_keywords]
|
pprint(title_keywords)
|
||||||
count_title_words = Counter(title_keywords).most_common(30)
|
|
||||||
pprint(count_title_words)
|
|
||||||
|
|
||||||
|
|
||||||
def histogram(data):
|
def histogram(data):
|
||||||
dates = []
|
dates = []
|
||||||
for row in data:
|
for row in data:
|
||||||
|
try:
|
||||||
dates.append(int(row[4]))
|
dates.append(int(row[4]))
|
||||||
years = range(min(dates), max(dates) + 2)
|
except (ValueError, IndexError):
|
||||||
plt.hist(dates, bins=years)
|
# Skip invalid date entries
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not dates:
|
||||||
|
print("No valid dates found")
|
||||||
|
return
|
||||||
|
|
||||||
|
min_year = min(dates)
|
||||||
|
max_year = max(dates)
|
||||||
|
|
||||||
|
# Create bins with reasonable spacing
|
||||||
|
years = range(min_year, max_year + 1)
|
||||||
|
plt.hist(dates, bins=len(years), edgecolor='black')
|
||||||
|
plt.xlabel('Year')
|
||||||
|
plt.ylabel('Frequency')
|
||||||
|
plt.title('Publication Year Distribution')
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
@@ -106,7 +123,7 @@ def names(data):
|
|||||||
for name in name_parts:
|
for name in name_parts:
|
||||||
name = name.rstrip(",")
|
name = name.rstrip(",")
|
||||||
if name not in stop_words:
|
if name not in stop_words:
|
||||||
if "." not in name:
|
if "." not in name and name != "":
|
||||||
names.append(name)
|
names.append(name)
|
||||||
count_names = Counter(names).most_common(30)
|
count_names = Counter(names).most_common(30)
|
||||||
pprint(count_names)
|
pprint(count_names)
|
||||||
@@ -114,8 +131,11 @@ def names(data):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parse_csv(file_path)
|
parse_csv(file_path)
|
||||||
data = data[1:]
|
if data: # Only process if data was loaded
|
||||||
|
data = data[1:] # Skip header row
|
||||||
extract_journal_titles(data)
|
extract_journal_titles(data)
|
||||||
print_title_keywords(data)
|
print_title_keywords(data)
|
||||||
# names(data)
|
# names(data)
|
||||||
histogram(data)
|
histogram(data)
|
||||||
|
else:
|
||||||
|
print("No data to process")
|
||||||
|
|||||||
Reference in New Issue
Block a user