Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
bibliovenv/
Bibenv/
.idea/
.idea/venv/
venv/
10 changes: 8 additions & 2 deletions functions/get_frequentwords.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from www.services import *

import ast

def get_frequent_words(df, ngram, num_of_words, word_type, file_upload_terms, file_upload_synonyms, field_separator_frequent=';'):
"""
Expand Down Expand Up @@ -116,7 +116,13 @@ def table_tag(df, tag, ngrams=1, remove_terms=None, synonyms=None):

# Handle list columns (DE and ID)
if tag in ['DE', 'ID']:
text_data = text_data.dropna().apply(lambda x: ', '.join(eval(x) if isinstance(x, str) else x))
text_data = text_data.dropna().apply(
lambda x: ', '.join(
x if isinstance(x, list)
else (ast.literal_eval(x) if isinstance(x, str) and x.strip().startswith("[")
else [i.strip() for i in x.split(";")])
)
)

# Process words
if tag in ['DE', 'ID']:
Expand Down
13 changes: 10 additions & 3 deletions functions/get_relevantauthors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from www.services import *

import ast

def get_relevant_authors(df, num_of_authors, frequency="N. of Documents"):
"""
Expand All @@ -19,8 +19,12 @@ def get_relevant_authors(df, num_of_authors, frequency="N. of Documents"):
data = data.dropna(subset=["AU"])

# Ensure all values in the "AU" column are lists
data["AU"] = data["AU"].apply(lambda x: x if isinstance(x, list) else [])

#data["AU"] = data["AU"].apply(lambda x: x if isinstance(x, list) else [])
data["AU"] = data["AU"].apply(
lambda x: x if isinstance(x, list)
else (ast.literal_eval(x) if isinstance(x, str) and x.strip().startswith("[")
else ([i.strip() for i in x.split(";")] if isinstance(x, str) and x.strip() else []))
)
# Flatten the list of authors and calculate occurrences
all_authors = [author for sublist in data["AU"] for author in sublist]
author_counts = pd.Series(all_authors).value_counts()
Expand Down Expand Up @@ -103,7 +107,10 @@ def get_relevant_authors(df, num_of_authors, frequency="N. of Documents"):
)

# Set x-axis ticks to 0, 5, 10, etc.

max_x = author_counts[frequency].max()
if pd.isna(max_x):
max_x = 0
tick_step = 5
x_ticks = list(range(0, int(max_x) + tick_step, tick_step))
if x_ticks[-1] < max_x:
Expand Down
11 changes: 9 additions & 2 deletions functions/get_wordcloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from www.services import *

import ast

def is_legible_on_white(color):
"""Restituisce True se il colore è leggibile su sfondo bianco"""
Expand Down Expand Up @@ -122,7 +122,14 @@ def table_tag(df, tag, ngrams=1, remove_terms=None, synonyms=None):

# Handle list columns (DE and ID)
if tag in ['DE', 'ID']:
text_data = text_data.dropna().apply(lambda x: ', '.join(eval(x) if isinstance(x, str) else x))
#text_data = text_data.dropna().apply(lambda x: ', '.join(eval(x) if isinstance(x, str) else x))
text_data = text_data.dropna().apply(
lambda x: ', '.join(
x if isinstance(x, list)
else (ast.literal_eval(x) if isinstance(x, str) and x.strip().startswith("[")
else [i.strip() for i in x.split(";")])
)
)

# Process words
if tag in ['DE', 'ID']:
Expand Down
Binary file added sources/samples/dimensions_sample.xlsx
Binary file not shown.
Binary file added sources/samples/dimensions_standardized.xlsx
Binary file not shown.
Binary file added sources/samples/openalex_standardized.xlsx
Binary file not shown.
Loading