يوفر برنامج chat-miner محللًا بسيطًا لكل منصة رئيسية لتحويل الدردشات إلى إطارات بيانات. تسمح لك المرئيات الفنية باستكشاف بياناتك وإنشاء أعمال فنية من محادثاتك.
يمكن تثبيت أحدث إصدار بما في ذلك التبعيات عبر PyPI:
pip install chat-miner
إذا كنت مهتمًا بالمساهمة، أو تشغيل أحدث كود المصدر، أو ترغب فقط في إنشاء كل شيء بنفسك:
git clone https://github.com/joweich/chat-miner.git
cd chat-miner
pip install .
قم بإلقاء نظرة على البرامج التعليمية الرسمية لتطبيقات WhatsApp أو Signal أو Telegram أو Facebook Messenger أو Instagram Chats لمعرفة كيفية تصدير سجلات الدردشة لمنصتك.
يعرض الكود التالي وحدة WhatsAppParser
. يتبع استخدام SignalParser
و TelegramJsonParser
و FacebookMessengerParser
و InstagramJsonParser
نفس النمط.
from chatminer . chatparsers import WhatsAppParser
parser = WhatsAppParser ( FILEPATH )
parser . parse_file ()
df = parser . parsed_messages . get_df ( as_pandas = True ) # as_pandas=False returns polars dataframe
ملاحظة: اعتمادًا على نظامك المصدر، تتطلب لغة Python تحويل مسار الملف إلى سلسلة نصية أولية.
import os
FILEPATH = r"C:UsersUsernamechat.txt" # Windows
FILEPATH = "/home/username/chat.txt" # Unix
assert os . path . isfile ( FILEPATH )
import chatminer . visualizations as vis
import matplotlib . pyplot as plt
fig , ax = plt . subplots ( 2 , 1 , figsize = ( 9 , 3 ))
ax [ 0 ] = vis . calendar_heatmap ( df , year = 2020 , cmap = 'Oranges' , ax = ax [ 0 ])
ax [ 1 ] = vis . calendar_heatmap ( df , year = 2021 , linewidth = 0 , monthly_border = True , ax = ax [ 1 ])
fig , ax = plt . subplots ( 1 , 2 , figsize = ( 7 , 3 ), subplot_kw = { 'projection' : 'polar' })
ax [ 0 ] = vis . sunburst ( df , highlight_max = True , isolines = [ 2500 , 5000 ], isolines_relative = False , ax = ax [ 0 ])
ax [ 1 ] = vis . sunburst ( df , highlight_max = False , isolines = [ 0.5 , 1 ], color = 'C1' , ax = ax [ 1 ])
fig , ax = plt . subplots ( figsize = ( 8 , 3 ))
stopwords = [ 'these' , 'are' , 'stopwords' ]
kwargs = { "background_color" : "white" , "width" : 800 , "height" : 300 , "max_words" : 500 }
ax = vis . wordcloud ( df , ax = ax , stopwords = stopwords , ** kwargs )
if not vis . is_radar_registered ():
vis . radar_factory ( 7 , frame = "polygon" )
fig , ax = plt . subplots ( 1 , 2 , figsize = ( 7 , 3 ), subplot_kw = { 'projection' : 'radar' })
ax [ 0 ] = vis . radar ( df , ax = ax [ 0 ])
ax [ 1 ] = vis . radar ( df , ax = ax [ 1 ], color = 'C1' , alpha = 0 )
from chatminer . nlp import add_sentiment
df_sentiment = add_sentiment ( df )
df_grouped = df_sentiment . groupby ([ 'author' , 'sentiment' ]). size (). unstack ( fill_value = 0 )
ax = df_grouped . plot ( kind = 'bar' , stacked = True , figsize = ( 8 , 3 ))
يدعم CLI تحليل سجلات الدردشة إلى ملفات CSV. اعتبارًا من الآن، لا يمكنك إنشاء تصورات من واجهة سطر الأوامر مباشرةً.
مثال للاستخدام:
$ chatminer -p whatsapp -i exportfile.txt -o output.csv
دليل الاستخدام:
usage: chatminer [-h] [-p {whatsapp,instagram,facebook,signal,telegram}] [-i INPUT] [-o OUTPUT]
options:
-h, --help
Show this help message and exit
-p {whatsapp,instagram,facebook,signal,telegram}, --parser {whatsapp,instagram,facebook,signal,telegram}
The platform from which the chats are imported
-i INPUT, --input INPUT
Input file to be processed
-o OUTPUT, --output OUTPUT
Output file for the results