Author SHA1 Message Date
Mark Eatonandaider 272b4c0909 fix: correct title keywords extraction to return proper word-frequency pairs
Co-authored-by: aider (ollama_chat/qwen3-coder:30b) <aider@aider.chat>
2026-08-16 19:51:23 -04:00
Mark Eatonandaider 3c5939e4f6 fix: resolve parsing errors and add error handling in parse.py
Co-authored-by: aider (ollama_chat/qwen3-coder:30b) <aider@aider.chat>
2026-08-16 19:41:54 -04:00
Mark Eaton 6d176ee93a Merge pull request 'Lock file maintenance' (#2) from renovate/lock-file-maintenance into main
Reviewed-on: https://tildegit.org/MarkEEaton/1article/pulls/2
2026-06-10 21:49:08 +00:00
+34 -14
View File
@@ -52,10 +52,17 @@ data = []
def parse_csv(file_path):
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:
try:
dates.append(int(row[4]))
years = range(min(dates), max(dates) + 2)
plt.hist(dates, bins=years)
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:]
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")