comid 0.0.2__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {comid-0.0.2 → comid-0.0.3}/LICENSE +20 -20
- comid-0.0.3/PKG-INFO +224 -0
- comid-0.0.3/README.md +186 -0
- {comid-0.0.2 → comid-0.0.3}/comid/__init__.py +796 -507
- comid-0.0.2/comid/scraper.py → comid-0.0.3/comid/collector.py +279 -245
- comid-0.0.3/comid/explorer.py +277 -0
- comid-0.0.3/comid/pullpush.py +29 -0
- comid-0.0.3/comid.egg-info/PKG-INFO +224 -0
- {comid-0.0.2 → comid-0.0.3}/comid.egg-info/SOURCES.txt +3 -1
- {comid-0.0.2 → comid-0.0.3}/comid.egg-info/requires.txt +1 -1
- {comid-0.0.2 → comid-0.0.3}/setup.cfg +4 -4
- {comid-0.0.2 → comid-0.0.3}/setup.py +37 -37
- comid-0.0.2/PKG-INFO +0 -194
- comid-0.0.2/README.md +0 -174
- comid-0.0.2/comid.egg-info/PKG-INFO +0 -194
- {comid-0.0.2 → comid-0.0.3}/comid.egg-info/dependency_links.txt +0 -0
- {comid-0.0.2 → comid-0.0.3}/comid.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Thiago Henrique dos Santos
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Thiago Henrique dos Santos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
comid-0.0.3/PKG-INFO
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: comid
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: A community identification module for Reddit conversations
|
|
5
|
+
Home-page: https://github.com/d0d0th/comid
|
|
6
|
+
Author: Thiago Henrique dos Santos
|
|
7
|
+
Author-email: a22100011@alunos.ulht.pt
|
|
8
|
+
License: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: redditcleaner
|
|
21
|
+
Requires-Dist: contractions
|
|
22
|
+
Requires-Dist: nltk
|
|
23
|
+
Requires-Dist: spacy
|
|
24
|
+
Requires-Dist: tqdm
|
|
25
|
+
Requires-Dist: pandas
|
|
26
|
+
Requires-Dist: praw>=7.7
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: requires-dist
|
|
36
|
+
Dynamic: requires-python
|
|
37
|
+
Dynamic: summary
|
|
38
|
+
|
|
39
|
+
# **COMID - Community Identification Module for Reddit Conversations**
|
|
40
|
+
|
|
41
|
+
**COMID** is a Python toolkit specifically designed for collecting and analyzing Reddit conversations. It offers powerful tools for building corpora, annotating topics, and performing temporal analyses of discussions from subreddit threads.
|
|
42
|
+
|
|
43
|
+
## **Features**
|
|
44
|
+
|
|
45
|
+
### What COMID Can Do:
|
|
46
|
+
- Collect conversation threads from any specified subreddit.
|
|
47
|
+
- Explore and preprocess collected data for detailed analysis.
|
|
48
|
+
- Generate a corpus based on the original content (O.C.) of Reddit threads.
|
|
49
|
+
- Assist in annotating topics within pre-grouped conversation clusters.
|
|
50
|
+
- Perform temporal analysis to track the evolution of topics over time.
|
|
51
|
+
|
|
52
|
+
### What COMID Does Not Do:
|
|
53
|
+
- COMID does **not** perform topic modeling directly. For that, consider using the complementary [hSBM Topic Model](https://github.com/martingerlach/hSBM_Topicmodel).
|
|
54
|
+
|
|
55
|
+
### Documentation:
|
|
56
|
+
Comprehensive documentation is available for each module:
|
|
57
|
+
- [Comid](docs/Comid.md)
|
|
58
|
+
- [Collector](docs/RedditCollector.md)
|
|
59
|
+
- [Explorer](docs/Explorer.md)
|
|
60
|
+
|
|
61
|
+
## **Quick Start**
|
|
62
|
+
|
|
63
|
+
### Installation:
|
|
64
|
+
To install COMID and configure its dependencies, run the following commands:
|
|
65
|
+
``` bash
|
|
66
|
+
pip install comid
|
|
67
|
+
python -m spacy download en_core_web_sm
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Setting Up Reddit Credentials:
|
|
71
|
+
To use COMID, initialize your Reddit API credentials. If you don’t already have these credentials, you can follow this [guide](https://www.geeksforgeeks.org/how-to-get-client_id-and-client_secret-for-python-reddit-api-registration/).
|
|
72
|
+
``` python
|
|
73
|
+
from comid.collector import RedditCollector
|
|
74
|
+
import datetime as dt
|
|
75
|
+
|
|
76
|
+
collector = RedditCollector()
|
|
77
|
+
|
|
78
|
+
# Configure Reddit API credentials
|
|
79
|
+
collector.config_credentials(
|
|
80
|
+
client_id="YOUR_CLIENT_ID",
|
|
81
|
+
client_secret="YOUR_CLIENT_SECRET",
|
|
82
|
+
password="YOUR_PASSWORD",
|
|
83
|
+
username="YOUR_USERNAME"
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## **Collecting Data**
|
|
88
|
+
|
|
89
|
+
### Specify Subreddit and Date Range:
|
|
90
|
+
Define the subreddit and the range of dates to collect conversation thread IDs:
|
|
91
|
+
``` python
|
|
92
|
+
subreddit = 'digitalnomad'
|
|
93
|
+
start_dt = dt.datetime(2022, 1, 1)
|
|
94
|
+
end_dt = dt.datetime(2022, 1, 2)
|
|
95
|
+
|
|
96
|
+
# Collect thread IDs for the specified subreddit and date range
|
|
97
|
+
collector.search_ids_by_datetime(subreddit, start_dt, end_dt)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Download Submissions and Comments:
|
|
101
|
+
Once the IDs are collected, download all data, including original content, comments, and replies:
|
|
102
|
+
``` python
|
|
103
|
+
collector.download_by_ids()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## **Exploring Data and Creating a Corpus**
|
|
107
|
+
### Load JSON Data:
|
|
108
|
+
After downloading the data, load it from JSON files into COMID.
|
|
109
|
+
``` python
|
|
110
|
+
from comid import Comid
|
|
111
|
+
|
|
112
|
+
cm = Comid()
|
|
113
|
+
files = ['dataset/submissions.json', 'dataset/comments.json']
|
|
114
|
+
cm.load_json_files(files=files)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Explore Collected Data:
|
|
118
|
+
Perform exploratory data analysis to understand the dataset:
|
|
119
|
+
``` python
|
|
120
|
+
from comid.explorer import Explorer
|
|
121
|
+
|
|
122
|
+
# Initialize the Explorer with the loaded posts
|
|
123
|
+
explorer = Explorer(cm.posts)
|
|
124
|
+
|
|
125
|
+
# Display a summary of the dataset
|
|
126
|
+
explorer.data_summary()
|
|
127
|
+
|
|
128
|
+
# Calculate interval-based thread activity (e.g., by month)
|
|
129
|
+
explorer.thread_interval_activity('m')
|
|
130
|
+
|
|
131
|
+
# Export statistical data to files
|
|
132
|
+
explorer.export_data()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Generate the Corpus:
|
|
136
|
+
Extract only the main submissions to create a corpus. This step may take a few minutes for large datasets:
|
|
137
|
+
``` python
|
|
138
|
+
cm.generate_corpus()
|
|
139
|
+
print("Corpus size:", len(cm.corpus))
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Reduce the Corpus:
|
|
143
|
+
For efficient topic modeling, it is recommended to keep the corpus size under **6,000 documents**. Filter out posts with fewer than a specified number of interactions (e.g., 10 comments or replies):
|
|
144
|
+
``` python
|
|
145
|
+
cm.reduce_corpus(target_size=6000, min_num_interactions=10)
|
|
146
|
+
print("Corpus size:", len(cm.corpus))
|
|
147
|
+
print("Reduced corpus size:", len(cm.corpus_reduced))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## **Saving and Loading Data**
|
|
151
|
+
|
|
152
|
+
### Save the Corpus:
|
|
153
|
+
Save the reduced corpus as a JSON file for compatibility with hSBM Topic Modeling:
|
|
154
|
+
``` python
|
|
155
|
+
cm.save_corpus(reduced=True)
|
|
156
|
+
```
|
|
157
|
+
For details on working with hSBM, refer to the [hSBM Documentation](docs/SBM.md).
|
|
158
|
+
|
|
159
|
+
### Save and Load COMID Instances:
|
|
160
|
+
Save the current state of COMID for later use:
|
|
161
|
+
``` python
|
|
162
|
+
# Save the instance
|
|
163
|
+
cm.save("comid_saved_file.pickle")
|
|
164
|
+
|
|
165
|
+
# Reload the saved COMID instance
|
|
166
|
+
from comid import Comid
|
|
167
|
+
|
|
168
|
+
cm = Comid.load("comid_saved_file.pickle")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## **Working with Clusters and Topics**
|
|
172
|
+
|
|
173
|
+
### Load Topic Clusters:
|
|
174
|
+
After performing topic modeling with hSBM, load the generated clusters file for analysis:
|
|
175
|
+
``` python
|
|
176
|
+
cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
|
|
177
|
+
cm.load_clusters_file(cluster_file)
|
|
178
|
+
cm.df_clusters.head()
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Analyze Clusters:
|
|
182
|
+
Perform various operations on the topic clusters, such as viewing random samples or generating summaries:
|
|
183
|
+
|
|
184
|
+
#### Display Cluster Samples:
|
|
185
|
+
View random samples from any cluster to explore associated documents:
|
|
186
|
+
``` python
|
|
187
|
+
cm.print_cluster_samples('Cluster 1', 3)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Retrieve Flattened Conversation Text:
|
|
191
|
+
Flatten the conversational data for a specific document ID:
|
|
192
|
+
``` python
|
|
193
|
+
doc_id = 'rtsodc'
|
|
194
|
+
text = cm.retrieve_conversation(doc_id)
|
|
195
|
+
print(text)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Save Cluster Summary:
|
|
199
|
+
Create and save a summary of clusters, including cluster statistics and a topic label column for annotation:
|
|
200
|
+
``` python
|
|
201
|
+
cm.save_clusters_summary()
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
## **Building and Analyzing Topics**
|
|
206
|
+
|
|
207
|
+
### Build the Topics DataFrame:
|
|
208
|
+
Once clusters have been annotated with topic labels, build a topics DataFrame:
|
|
209
|
+
``` python
|
|
210
|
+
cm.build_topics("clusters_summary.csv")
|
|
211
|
+
cm.df_topics.head()
|
|
212
|
+
```
|
|
213
|
+
Alternatively, generate the topics DataFrame based on clusters containing a minimum percentage of documents (e.g., 7%):
|
|
214
|
+
``` python
|
|
215
|
+
cm.build_topics(min_percent=7)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Temporal Topic Analysis:
|
|
219
|
+
Group topics by time intervals, such as days, weeks, months, or years:
|
|
220
|
+
``` python
|
|
221
|
+
cm.group_by_period(period_type="m")
|
|
222
|
+
cm.df_periods.head()
|
|
223
|
+
```
|
|
224
|
+
Temporal analysis helps track the progression and evolution of topics over time.
|
comid-0.0.3/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# **COMID - Community Identification Module for Reddit Conversations**
|
|
2
|
+
|
|
3
|
+
**COMID** is a Python toolkit specifically designed for collecting and analyzing Reddit conversations. It offers powerful tools for building corpora, annotating topics, and performing temporal analyses of discussions from subreddit threads.
|
|
4
|
+
|
|
5
|
+
## **Features**
|
|
6
|
+
|
|
7
|
+
### What COMID Can Do:
|
|
8
|
+
- Collect conversation threads from any specified subreddit.
|
|
9
|
+
- Explore and preprocess collected data for detailed analysis.
|
|
10
|
+
- Generate a corpus based on the original content (O.C.) of Reddit threads.
|
|
11
|
+
- Assist in annotating topics within pre-grouped conversation clusters.
|
|
12
|
+
- Perform temporal analysis to track the evolution of topics over time.
|
|
13
|
+
|
|
14
|
+
### What COMID Does Not Do:
|
|
15
|
+
- COMID does **not** perform topic modeling directly. For that, consider using the complementary [hSBM Topic Model](https://github.com/martingerlach/hSBM_Topicmodel).
|
|
16
|
+
|
|
17
|
+
### Documentation:
|
|
18
|
+
Comprehensive documentation is available for each module:
|
|
19
|
+
- [Comid](docs/Comid.md)
|
|
20
|
+
- [Collector](docs/RedditCollector.md)
|
|
21
|
+
- [Explorer](docs/Explorer.md)
|
|
22
|
+
|
|
23
|
+
## **Quick Start**
|
|
24
|
+
|
|
25
|
+
### Installation:
|
|
26
|
+
To install COMID and configure its dependencies, run the following commands:
|
|
27
|
+
``` bash
|
|
28
|
+
pip install comid
|
|
29
|
+
python -m spacy download en_core_web_sm
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Setting Up Reddit Credentials:
|
|
33
|
+
To use COMID, initialize your Reddit API credentials. If you don’t already have these credentials, you can follow this [guide](https://www.geeksforgeeks.org/how-to-get-client_id-and-client_secret-for-python-reddit-api-registration/).
|
|
34
|
+
``` python
|
|
35
|
+
from comid.collector import RedditCollector
|
|
36
|
+
import datetime as dt
|
|
37
|
+
|
|
38
|
+
collector = RedditCollector()
|
|
39
|
+
|
|
40
|
+
# Configure Reddit API credentials
|
|
41
|
+
collector.config_credentials(
|
|
42
|
+
client_id="YOUR_CLIENT_ID",
|
|
43
|
+
client_secret="YOUR_CLIENT_SECRET",
|
|
44
|
+
password="YOUR_PASSWORD",
|
|
45
|
+
username="YOUR_USERNAME"
|
|
46
|
+
)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## **Collecting Data**
|
|
50
|
+
|
|
51
|
+
### Specify Subreddit and Date Range:
|
|
52
|
+
Define the subreddit and the range of dates to collect conversation thread IDs:
|
|
53
|
+
``` python
|
|
54
|
+
subreddit = 'digitalnomad'
|
|
55
|
+
start_dt = dt.datetime(2022, 1, 1)
|
|
56
|
+
end_dt = dt.datetime(2022, 1, 2)
|
|
57
|
+
|
|
58
|
+
# Collect thread IDs for the specified subreddit and date range
|
|
59
|
+
collector.search_ids_by_datetime(subreddit, start_dt, end_dt)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Download Submissions and Comments:
|
|
63
|
+
Once the IDs are collected, download all data, including original content, comments, and replies:
|
|
64
|
+
``` python
|
|
65
|
+
collector.download_by_ids()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## **Exploring Data and Creating a Corpus**
|
|
69
|
+
### Load JSON Data:
|
|
70
|
+
After downloading the data, load it from JSON files into COMID.
|
|
71
|
+
``` python
|
|
72
|
+
from comid import Comid
|
|
73
|
+
|
|
74
|
+
cm = Comid()
|
|
75
|
+
files = ['dataset/submissions.json', 'dataset/comments.json']
|
|
76
|
+
cm.load_json_files(files=files)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Explore Collected Data:
|
|
80
|
+
Perform exploratory data analysis to understand the dataset:
|
|
81
|
+
``` python
|
|
82
|
+
from comid.explorer import Explorer
|
|
83
|
+
|
|
84
|
+
# Initialize the Explorer with the loaded posts
|
|
85
|
+
explorer = Explorer(cm.posts)
|
|
86
|
+
|
|
87
|
+
# Display a summary of the dataset
|
|
88
|
+
explorer.data_summary()
|
|
89
|
+
|
|
90
|
+
# Calculate interval-based thread activity (e.g., by month)
|
|
91
|
+
explorer.thread_interval_activity('m')
|
|
92
|
+
|
|
93
|
+
# Export statistical data to files
|
|
94
|
+
explorer.export_data()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Generate the Corpus:
|
|
98
|
+
Extract only the main submissions to create a corpus. This step may take a few minutes for large datasets:
|
|
99
|
+
``` python
|
|
100
|
+
cm.generate_corpus()
|
|
101
|
+
print("Corpus size:", len(cm.corpus))
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Reduce the Corpus:
|
|
105
|
+
For efficient topic modeling, it is recommended to keep the corpus size under **6,000 documents**. Filter out posts with fewer than a specified number of interactions (e.g., 10 comments or replies):
|
|
106
|
+
``` python
|
|
107
|
+
cm.reduce_corpus(target_size=6000, min_num_interactions=10)
|
|
108
|
+
print("Corpus size:", len(cm.corpus))
|
|
109
|
+
print("Reduced corpus size:", len(cm.corpus_reduced))
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## **Saving and Loading Data**
|
|
113
|
+
|
|
114
|
+
### Save the Corpus:
|
|
115
|
+
Save the reduced corpus as a JSON file for compatibility with hSBM Topic Modeling:
|
|
116
|
+
``` python
|
|
117
|
+
cm.save_corpus(reduced=True)
|
|
118
|
+
```
|
|
119
|
+
For details on working with hSBM, refer to the [hSBM Documentation](docs/SBM.md).
|
|
120
|
+
|
|
121
|
+
### Save and Load COMID Instances:
|
|
122
|
+
Save the current state of COMID for later use:
|
|
123
|
+
``` python
|
|
124
|
+
# Save the instance
|
|
125
|
+
cm.save("comid_saved_file.pickle")
|
|
126
|
+
|
|
127
|
+
# Reload the saved COMID instance
|
|
128
|
+
from comid import Comid
|
|
129
|
+
|
|
130
|
+
cm = Comid.load("comid_saved_file.pickle")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## **Working with Clusters and Topics**
|
|
134
|
+
|
|
135
|
+
### Load Topic Clusters:
|
|
136
|
+
After performing topic modeling with hSBM, load the generated clusters file for analysis:
|
|
137
|
+
``` python
|
|
138
|
+
cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
|
|
139
|
+
cm.load_clusters_file(cluster_file)
|
|
140
|
+
cm.df_clusters.head()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Analyze Clusters:
|
|
144
|
+
Perform various operations on the topic clusters, such as viewing random samples or generating summaries:
|
|
145
|
+
|
|
146
|
+
#### Display Cluster Samples:
|
|
147
|
+
View random samples from any cluster to explore associated documents:
|
|
148
|
+
``` python
|
|
149
|
+
cm.print_cluster_samples('Cluster 1', 3)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Retrieve Flattened Conversation Text:
|
|
153
|
+
Flatten the conversational data for a specific document ID:
|
|
154
|
+
``` python
|
|
155
|
+
doc_id = 'rtsodc'
|
|
156
|
+
text = cm.retrieve_conversation(doc_id)
|
|
157
|
+
print(text)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Save Cluster Summary:
|
|
161
|
+
Create and save a summary of clusters, including cluster statistics and a topic label column for annotation:
|
|
162
|
+
``` python
|
|
163
|
+
cm.save_clusters_summary()
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
## **Building and Analyzing Topics**
|
|
168
|
+
|
|
169
|
+
### Build the Topics DataFrame:
|
|
170
|
+
Once clusters have been annotated with topic labels, build a topics DataFrame:
|
|
171
|
+
``` python
|
|
172
|
+
cm.build_topics("clusters_summary.csv")
|
|
173
|
+
cm.df_topics.head()
|
|
174
|
+
```
|
|
175
|
+
Alternatively, generate the topics DataFrame based on clusters containing a minimum percentage of documents (e.g., 7%):
|
|
176
|
+
``` python
|
|
177
|
+
cm.build_topics(min_percent=7)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Temporal Topic Analysis:
|
|
181
|
+
Group topics by time intervals, such as days, weeks, months, or years:
|
|
182
|
+
``` python
|
|
183
|
+
cm.group_by_period(period_type="m")
|
|
184
|
+
cm.df_periods.head()
|
|
185
|
+
```
|
|
186
|
+
Temporal analysis helps track the progression and evolution of topics over time.
|