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
2 changes: 1 addition & 1 deletion src/everyai/data_loader/dataprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def split_remove_stopwords_punctuation(text: str, language="both") -> str:
Defaults to 'both'.

Returns:
str: Processed text with words split, punctuation removed,
str: Processed text with words split, punctuation removed,
and stopwords removed.
"""
if language.lower() in ["zh", "chinese"]:
Expand Down
28 changes: 7 additions & 21 deletions src/everyai/data_loader/everyai_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def __init__(
if datas is not None:
self.datas: pd.DataFrame = datas
else:
self.datas: pd.DataFrame = pd.DataFrame(
columns=["question", "human"]
)
self.datas: pd.DataFrame = pd.DataFrame(columns=["question", "human"])
if ai_list is not None:
for ai_name in ai_list:
self.datas[ai_name] = None
Expand Down Expand Up @@ -59,17 +57,13 @@ def insert_ai_response(self, question, ai_name: str, ai_response: str):
if question_exists:
self._update_new_row(question, ai_name, ai_response)
else:
self.datas.loc[self.datas["question"] == question, ai_name] = (
ai_response
)
self.datas.loc[self.datas["question"] == question, ai_name] = ai_response

def insert_human_response(self, question, human_response: str):
if self.datas[self.datas["question"] == question].empty:
self._update_new_row(question, "human", human_response)
else:
self.datas.loc[self.datas["question"] == question, "human"] = (
human_response
)
self.datas.loc[self.datas["question"] == question, "human"] = human_response

# TODO Rename this here and in `insert_ai_response` and `insert_human_response`
def _update_new_row(self, question, arg1, arg2):
Expand Down Expand Up @@ -101,9 +95,7 @@ def _load_from_mongodb(self, database: pymongo.database.Database):
data = data.drop(columns=["timestamp"])
self.datas = data

def load(
self, path_or_database: str | Path = None, formatter: str = "csv"
):
def load(self, path_or_database: str | Path = None, formatter: str = "csv"):
if formatter == "mongodb":
if path_or_database is None:
path_or_database = self._initialize_mongo_connection()
Expand All @@ -124,9 +116,7 @@ def load(
and path_or_database.suffix != f".{formatter}"
):
logging.warning("Change file format to %s", formatter)
path_or_database = path_or_database.with_suffix(
f".{formatter}"
)
path_or_database = path_or_database.with_suffix(f".{formatter}")
else:
logging.info("Loading dataset from %s", path_or_database)
match formatter:
Expand All @@ -143,9 +133,7 @@ def load(
set(self.datas.columns) - {"question", "human", "timestamp"}
)

def save(
self, path_or_database: str | Path = None, formatter: str = "csv"
):
def save(self, path_or_database: str | Path = None, formatter: str = "csv"):
if formatter == "mongodb":
if path_or_database is None:
path_or_database = self._initialize_mongo_connection()
Expand All @@ -164,9 +152,7 @@ def save(
return
if path_or_database.suffix != f".{formatter}":
logging.warning("Change file format to %s", formatter)
path_or_database = path_or_database.with_suffix(
f".{formatter}"
)
path_or_database = path_or_database.with_suffix(f".{formatter}")
else:
logging.info("Saving dataset to %s", path_or_database)
match formatter:
Expand Down