Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Conversation CSV loader #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
44 changes: 29 additions & 15 deletions src/cmn/conversation.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import os
import csv

from cmn.message import Message


class Conversation(Object):
def __init__(self, id, messages, participants):
class Conversation:
def __init__(self, id):
self.id = id
self.messages = messages
self.participants = participants
self.messages = []
self.participants = set()
self.conv_size = 0

@staticmethod
def loader(path):
if path.endswith(".csv"): return Conversation.csv_loader(path)
if path.endswith(".csv"):
arun-esh marked this conversation as resolved.
Show resolved Hide resolved
return Conversation.csv_loader(path)

def add_message(self, message_content, author_involved, size):
arun-esh marked this conversation as resolved.
Show resolved Hide resolved
self.messages.append(message_content)
self.participants.add(author_involved)
self.conv_size = size

@staticmethod
def csv_loader(filepath):
Expand All @@ -26,34 +32,42 @@ def csv_loader(filepath):
# before we import, could be taken care here.
try:
# Assign the conversation id to Conversation Object
# conversation.conversation_id = row['conv_id']

message = Message(
row["msg_line"],
row["author_id"],
row["time"],
row["msg_char_count"],
row["msg_word_count"],
row["conv_size"],
row["nauthor"],
row["text"],
row["tagged_predator"],
row["predatory_conv"],
)

if id not in convs: convs[id] = Conversation(row["conv_id"], None, None)
convs[id].add_message(message)
conv_id = row["conv_id"]
author_involved = row["author_id"]
conversation_size = row["conv_size"]

if conv_id not in convs:
arun-esh marked this conversation as resolved.
Show resolved Hide resolved
convs[conv_id] = Conversation(conv_id)

convs[conv_id].add_message(
message, author_involved, conversation_size
)

except KeyError as e:
print(f"Import Error: {e}")

return convs

def __repr__(self):
repr_string = f"Conversation ID: {self.id}\nNumber of messages: {len(self.messages)}\n"
authors_list = "\n".join(self.participants)

repr_string = f"Conversation ID: {self.id}\nConversation Size: {self.conv_size}\nAuthors Involved: {len(list(self.participants))}\n{authors_list}\n"

if not self.messages: repr_string += "No messages found for this conversation.\n"
if not self.messages:
repr_string += "No messages found for this conversation.\n"
else:
for message in self.messages: repr_string += f"\n{message}"
for message in self.messages:
repr_string += f"\n{message}"

return repr_string
2 changes: 1 addition & 1 deletion src/cmn/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Message(Object):
class Message:
def __init__(
self,
idx: str,
Expand Down