Skip to content

1. About Chatroom class

ParkSangJun edited this page Mar 11, 2019 · 1 revision

1. Create instance

Chatroom(name, line_analyze=None)

You can use just "Chatroom(name)"
line_analyze parameter is for select word analyzer. but there is a analyzer in this.
You can use your costum analyzer by passing function name like "Chatroom(name, Custom_Analyze)"

2. Internal Variables

chatroom.name
chatroom.tot_msg
chatroom.tot_person
chatroom.people
chatroom.talkdays

chatroom.name is just name that you provided. type str.
ex) Hello python world

chatroom.tot_msg is the number of total message in chatroom. type int.
ex) 22

chatroom.tot_person is Dictionary containing all message count by person in chatroom. type Dict.
ex) {'python': 6, 'C': 5, 'Java': 2, 'c++': 9}

chatroom.people is a People type instance. I'll explain later.
chatroom.talkdays is a List of Talkday instances also explained later.

All example is about a "KakaoTalk_Sample.txt" file

3. Functions and Methods

Functions

len(chatroom)

It returns the number of Days

for day in chatroom: print(day)

You can use like this or chatroom[3]. Then It is same as chatroom.talkdays[3].
So the result of upper code is
2019-03-10
2019-03-11
in my sample.

Methods

chatroom.tot_person_rate()
chatroom.get_words()
chatroom.find_word(word, create=False)
chatroom.append(datetime, person_name, content)

chatroom.tot_person_rate() returns sorted list containing (person_name, count).
ex)
[('c++', 0.4090909090909091), ('python', 0.2727272727272727), ('C', 0.22727272727272727), ('Java', 0.09090909090909091)]

chatroom.get_words() returns Dict containing all {word:count} in this chatroom.
ex)
{'있어': 1, 'ㅋㅋㅋㅋㅋ': 1, '어디서든': 1, '느려터진': 1, '싸우지': 1, '중요하지': 1, '...': 1, '너는': 1, '사이': 1, '거': 1, '그': 1, '다들': 2, '!!!!': 1, '(저': 1, '....????': 1, '잘': 1, '좋다구': 1, ';;': 1, '설치되지': 1, '느리잖아': 1, '수': 1, '녀석': 1, 'JAVA는': 1, '관둘래': 1, '지내자': 1, '나는': 1, '파이썬이': 1, '필요': 1, '그냥': 1, '프로그래밍': 1, '대단': 1, '대회에서': 1, '너도': 1, '그런': 1, '하라구': 1, 'import': 1, '뛸': 1, '하셔라': 1, '않아!!': 1, '복잡해': 1, '준다며?': 1, '마찬가지야!': 1, '너무': 2, '으아악': 1, '말라구': 1, '참': 1, '느려서': 1, '시간도': 1, '진짜....)': 1, '없어': 1, 'antigravity': 1, '파이썬이라니': 1, '그만': 1, 'ㅜㅜ': 1, '더': 1, '좋게': 1, 'c++이': 1, '런': 1, 'ㅋㅋㅋㅋㅋㅋㅋㅋ': 1, '않아': 1, '건': 1}

chatroom.find_word(word, create=False) is used for get Word instance using only word name.
Also you can use create parameter if you want to add word to Words list when the word don't exist.
ex)
>> chatroom.find_word("사이")
<Word.Word object at 0x7fbc6429e320>

chatroom.append(datetime, person_name, content) is core method in this Analyzer.
When you excute "append" method, then it will analyze string and save internally.
So you can analyze string just only this method.
datetime is datetime.datetime instance. it is message time.
person_name is the name of this message sender.
content is message content.

Clone this wiki locally