Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
272b4c0909 | ||
|
|
3c5939e4f6 | ||
|
|
6d176ee93a |
@@ -52,10 +52,17 @@ data = []
|
||||
|
||||
|
||||
def parse_csv(file_path):
|
||||
with open(file_path, "r") as file:
|
||||
reader = csv.reader(file)
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
reader = csv.reader(file)
|
||||
for row in reader:
|
||||
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):
|
||||
@@ -70,32 +77,42 @@ def extract_journal_titles(data):
|
||||
|
||||
def extract_title_keywords(data):
|
||||
title_keywords = []
|
||||
re_words = []
|
||||
for row in data:
|
||||
raw_words = row[2].split(" ")
|
||||
row_words = []
|
||||
for word in raw_words:
|
||||
re_word = re.sub(r"[^a-zA-Z\-]", "", word.lower())
|
||||
if re_word not in stop_words:
|
||||
re_words.append(re_word)
|
||||
row_words.append(re_word)
|
||||
title_keywords = [(word, row_words) for word in re_words]
|
||||
return title_keywords
|
||||
if re_word not in stop_words and re_word != "":
|
||||
title_keywords.append(re_word)
|
||||
return Counter(title_keywords).most_common(30)
|
||||
|
||||
|
||||
def print_title_keywords(data):
|
||||
title_keywords = extract_title_keywords(data)
|
||||
title_keywords = [word[0] for word in title_keywords]
|
||||
count_title_words = Counter(title_keywords).most_common(30)
|
||||
pprint(count_title_words)
|
||||
pprint(title_keywords)
|
||||
|
||||
|
||||
def histogram(data):
|
||||
dates = []
|
||||
for row in data:
|
||||
dates.append(int(row[4]))
|
||||
years = range(min(dates), max(dates) + 2)
|
||||
plt.hist(dates, bins=years)
|
||||
try:
|
||||
dates.append(int(row[4]))
|
||||
except (ValueError, IndexError):
|
||||
# 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()
|
||||
|
||||
|
||||
@@ -106,7 +123,7 @@ def names(data):
|
||||
for name in name_parts:
|
||||
name = name.rstrip(",")
|
||||
if name not in stop_words:
|
||||
if "." not in name:
|
||||
if "." not in name and name != "":
|
||||
names.append(name)
|
||||
count_names = Counter(names).most_common(30)
|
||||
pprint(count_names)
|
||||
@@ -114,8 +131,11 @@ def names(data):
|
||||
|
||||
if __name__ == "__main__":
|
||||
parse_csv(file_path)
|
||||
data = data[1:]
|
||||
extract_journal_titles(data)
|
||||
print_title_keywords(data)
|
||||
# names(data)
|
||||
histogram(data)
|
||||
if data: # Only process if data was loaded
|
||||
data = data[1:] # Skip header row
|
||||
extract_journal_titles(data)
|
||||
print_title_keywords(data)
|
||||
# names(data)
|
||||
histogram(data)
|
||||
else:
|
||||
print("No data to process")
|
||||
|
||||
Reference in New Issue
Block a user