comid 0.0.2__tar.gz → 0.0.4__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.
@@ -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.4/PKG-INFO ADDED
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.2
2
+ Name: comid
3
+ Version: 0.0.4
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.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Utilities
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: redditcleaner
22
+ Requires-Dist: contractions
23
+ Requires-Dist: nltk
24
+ Requires-Dist: spacy
25
+ Requires-Dist: tqdm
26
+ Requires-Dist: pandas
27
+ Requires-Dist: praw>=7.7
28
+ Requires-Dist: numpy
29
+ Requires-Dist: convokit>=3.1.0
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: description-content-type
35
+ Dynamic: home-page
36
+ Dynamic: license
37
+ Dynamic: requires-dist
38
+ Dynamic: requires-python
39
+ Dynamic: summary
40
+
41
+ # **COMID - Community Identification Module for Reddit Conversations**
42
+
43
+ **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.
44
+
45
+ ## **Features**
46
+
47
+ ### What COMID Can Do:
48
+ - Collect conversation threads from any specified subreddit.
49
+ - Explore and preprocess collected data for detailed analysis.
50
+ - Generate a corpus based on the original content (O.C.) of Reddit threads.
51
+ - Assist in annotating topics within pre-grouped conversation clusters.
52
+ - Perform temporal analysis to track the evolution of topics over time.
53
+ - Integrate with [Convokit](https://github.com/CornellNLP/ConvoKit)
54
+
55
+ ### What COMID Does Not Do:
56
+ - COMID does **not** perform topic modeling directly. For that, consider using the complementary [hSBM Topic Model](https://github.com/martingerlach/hSBM_Topicmodel).
57
+
58
+ ### Documentation:
59
+ Comprehensive documentation is available for each module:
60
+ - [Comid](docs/Comid.md)
61
+ - [Collector](docs/RedditCollector.md)
62
+ - [Explorer](docs/Explorer.md)
63
+ - [ConvoBridge](docs/ConvoBridge.md)
64
+
65
+ ## **Quick Start**
66
+
67
+ ### Installation:
68
+ To install COMID and configure its dependencies, run the following commands:
69
+ ``` bash
70
+ pip install comid
71
+ python -m spacy download en_core_web_sm
72
+ ```
73
+
74
+ ### Setting Up Reddit Credentials:
75
+ 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/).
76
+ ``` python
77
+ from comid.collector import RedditCollector
78
+ import datetime as dt
79
+
80
+ collector = RedditCollector()
81
+
82
+ # Configure Reddit API credentials
83
+ collector.config_credentials(
84
+ client_id="YOUR_CLIENT_ID",
85
+ client_secret="YOUR_CLIENT_SECRET",
86
+ password="YOUR_PASSWORD",
87
+ username="YOUR_USERNAME"
88
+ )
89
+ ```
90
+
91
+ ## **Collecting Data**
92
+
93
+ ### Specify Subreddit and Date Range:
94
+ Define the subreddit and the range of dates to collect conversation thread IDs:
95
+ ``` python
96
+ subreddit = 'digitalnomad'
97
+ start_dt = dt.datetime(2022, 1, 1)
98
+ end_dt = dt.datetime(2022, 1, 2)
99
+
100
+ # Collect thread IDs for the specified subreddit and date range
101
+ collector.search_ids_by_datetime(subreddit, start_dt, end_dt)
102
+ ```
103
+
104
+ ### Download Submissions and Comments:
105
+ Once the IDs are collected, download all data, including original content, comments, and replies:
106
+ ``` python
107
+ collector.download_by_ids()
108
+ ```
109
+
110
+ ## **Exploring Data and Creating a Corpus**
111
+ ### Load JSON Data:
112
+ After downloading the data, load it from JSON files into COMID.
113
+ ``` python
114
+ from comid import Comid
115
+
116
+ cm = Comid()
117
+ files = ['dataset/submissions.json', 'dataset/comments.json']
118
+ cm.load_json_files(files=files)
119
+ ```
120
+
121
+ ### Explore Collected Data:
122
+ Perform exploratory data analysis to understand the dataset:
123
+ ``` python
124
+ from comid.explorer import Explorer
125
+
126
+ # Initialize the Explorer with the loaded posts
127
+ explorer = Explorer(cm.posts)
128
+
129
+ # Display a summary of the dataset
130
+ explorer.data_summary()
131
+
132
+ # Calculate interval-based thread activity (e.g., by month)
133
+ explorer.thread_interval_activity('m')
134
+
135
+ # Export statistical data to files
136
+ explorer.export_data()
137
+ ```
138
+
139
+ ### Generate the Corpus:
140
+ Extract only the main submissions to create a corpus. This step may take a few minutes for large datasets:
141
+ ``` python
142
+ cm.generate_corpus()
143
+ print("Corpus size:", len(cm.corpus))
144
+ ```
145
+
146
+ ### Reduce the Corpus:
147
+ 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):
148
+ ``` python
149
+ cm.reduce_corpus(target_size=6000, min_num_interactions=10)
150
+ print("Corpus size:", len(cm.corpus))
151
+ print("Reduced corpus size:", len(cm.corpus_reduced))
152
+ ```
153
+
154
+ ## **Saving and Loading Data**
155
+
156
+ ### Save the Corpus:
157
+ Save the reduced corpus as a JSON file for compatibility with hSBM Topic Modeling:
158
+ ``` python
159
+ cm.save_corpus(reduced=True)
160
+ ```
161
+ For details on working with hSBM, refer to the [hSBM Documentation](docs/SBM.md).
162
+
163
+ ### Save and Load COMID Instances:
164
+ Save the current state of COMID for later use:
165
+ ``` python
166
+ # Save the instance
167
+ cm.save("comid_saved_file.pickle")
168
+
169
+ # Reload the saved COMID instance
170
+ from comid import Comid
171
+
172
+ cm = Comid.load("comid_saved_file.pickle")
173
+ ```
174
+
175
+ ## **Working with Clusters and Topics**
176
+
177
+ ### Load Topic Clusters:
178
+ After performing topic modeling with hSBM, load the generated clusters file for analysis:
179
+ ``` python
180
+ cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
181
+ cm.load_clusters_file(cluster_file)
182
+ cm.df_clusters.head()
183
+ ```
184
+
185
+ ### Analyze Clusters:
186
+ Perform various operations on the topic clusters, such as viewing random samples or generating summaries:
187
+
188
+ #### Display Cluster Samples:
189
+ View random samples from any cluster to explore associated documents:
190
+ ``` python
191
+ cm.print_cluster_samples('Cluster 1', 3)
192
+ ```
193
+
194
+ #### Retrieve Flattened Conversation Text:
195
+ Flatten the conversational data for a specific document ID:
196
+ ``` python
197
+ doc_id = 'rtsodc'
198
+ text = cm.retrieve_conversation(doc_id)
199
+ print(text)
200
+ ```
201
+
202
+ #### Save Cluster Summary:
203
+ Create and save a summary of clusters, including cluster statistics and a topic label column for annotation:
204
+ ``` python
205
+ cm.save_clusters_summary()
206
+ ```
207
+
208
+
209
+ ## **Building and Analyzing Topics**
210
+
211
+ ### Build the Topics DataFrame:
212
+ Once clusters have been annotated with topic labels, build a topics DataFrame:
213
+ ``` python
214
+ cm.build_topics("clusters_summary.csv")
215
+ cm.df_topics.head()
216
+ ```
217
+ Alternatively, generate the topics DataFrame based on clusters containing a minimum percentage of documents (e.g., 7%):
218
+ ``` python
219
+ cm.build_topics(min_percent=7)
220
+ ```
221
+
222
+ ### Temporal Topic Analysis:
223
+ Group topics by time intervals, such as days, weeks, months, or years:
224
+ ``` python
225
+ cm.group_by_period(period_type="m")
226
+ cm.df_periods.head()
227
+ ```
228
+ Temporal analysis helps track the progression and evolution of topics over time.
comid-0.0.4/README.md ADDED
@@ -0,0 +1,188 @@
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
+ - Integrate with [Convokit](https://github.com/CornellNLP/ConvoKit)
14
+
15
+ ### What COMID Does Not Do:
16
+ - COMID does **not** perform topic modeling directly. For that, consider using the complementary [hSBM Topic Model](https://github.com/martingerlach/hSBM_Topicmodel).
17
+
18
+ ### Documentation:
19
+ Comprehensive documentation is available for each module:
20
+ - [Comid](docs/Comid.md)
21
+ - [Collector](docs/RedditCollector.md)
22
+ - [Explorer](docs/Explorer.md)
23
+ - [ConvoBridge](docs/ConvoBridge.md)
24
+
25
+ ## **Quick Start**
26
+
27
+ ### Installation:
28
+ To install COMID and configure its dependencies, run the following commands:
29
+ ``` bash
30
+ pip install comid
31
+ python -m spacy download en_core_web_sm
32
+ ```
33
+
34
+ ### Setting Up Reddit Credentials:
35
+ 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/).
36
+ ``` python
37
+ from comid.collector import RedditCollector
38
+ import datetime as dt
39
+
40
+ collector = RedditCollector()
41
+
42
+ # Configure Reddit API credentials
43
+ collector.config_credentials(
44
+ client_id="YOUR_CLIENT_ID",
45
+ client_secret="YOUR_CLIENT_SECRET",
46
+ password="YOUR_PASSWORD",
47
+ username="YOUR_USERNAME"
48
+ )
49
+ ```
50
+
51
+ ## **Collecting Data**
52
+
53
+ ### Specify Subreddit and Date Range:
54
+ Define the subreddit and the range of dates to collect conversation thread IDs:
55
+ ``` python
56
+ subreddit = 'digitalnomad'
57
+ start_dt = dt.datetime(2022, 1, 1)
58
+ end_dt = dt.datetime(2022, 1, 2)
59
+
60
+ # Collect thread IDs for the specified subreddit and date range
61
+ collector.search_ids_by_datetime(subreddit, start_dt, end_dt)
62
+ ```
63
+
64
+ ### Download Submissions and Comments:
65
+ Once the IDs are collected, download all data, including original content, comments, and replies:
66
+ ``` python
67
+ collector.download_by_ids()
68
+ ```
69
+
70
+ ## **Exploring Data and Creating a Corpus**
71
+ ### Load JSON Data:
72
+ After downloading the data, load it from JSON files into COMID.
73
+ ``` python
74
+ from comid import Comid
75
+
76
+ cm = Comid()
77
+ files = ['dataset/submissions.json', 'dataset/comments.json']
78
+ cm.load_json_files(files=files)
79
+ ```
80
+
81
+ ### Explore Collected Data:
82
+ Perform exploratory data analysis to understand the dataset:
83
+ ``` python
84
+ from comid.explorer import Explorer
85
+
86
+ # Initialize the Explorer with the loaded posts
87
+ explorer = Explorer(cm.posts)
88
+
89
+ # Display a summary of the dataset
90
+ explorer.data_summary()
91
+
92
+ # Calculate interval-based thread activity (e.g., by month)
93
+ explorer.thread_interval_activity('m')
94
+
95
+ # Export statistical data to files
96
+ explorer.export_data()
97
+ ```
98
+
99
+ ### Generate the Corpus:
100
+ Extract only the main submissions to create a corpus. This step may take a few minutes for large datasets:
101
+ ``` python
102
+ cm.generate_corpus()
103
+ print("Corpus size:", len(cm.corpus))
104
+ ```
105
+
106
+ ### Reduce the Corpus:
107
+ 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):
108
+ ``` python
109
+ cm.reduce_corpus(target_size=6000, min_num_interactions=10)
110
+ print("Corpus size:", len(cm.corpus))
111
+ print("Reduced corpus size:", len(cm.corpus_reduced))
112
+ ```
113
+
114
+ ## **Saving and Loading Data**
115
+
116
+ ### Save the Corpus:
117
+ Save the reduced corpus as a JSON file for compatibility with hSBM Topic Modeling:
118
+ ``` python
119
+ cm.save_corpus(reduced=True)
120
+ ```
121
+ For details on working with hSBM, refer to the [hSBM Documentation](docs/SBM.md).
122
+
123
+ ### Save and Load COMID Instances:
124
+ Save the current state of COMID for later use:
125
+ ``` python
126
+ # Save the instance
127
+ cm.save("comid_saved_file.pickle")
128
+
129
+ # Reload the saved COMID instance
130
+ from comid import Comid
131
+
132
+ cm = Comid.load("comid_saved_file.pickle")
133
+ ```
134
+
135
+ ## **Working with Clusters and Topics**
136
+
137
+ ### Load Topic Clusters:
138
+ After performing topic modeling with hSBM, load the generated clusters file for analysis:
139
+ ``` python
140
+ cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
141
+ cm.load_clusters_file(cluster_file)
142
+ cm.df_clusters.head()
143
+ ```
144
+
145
+ ### Analyze Clusters:
146
+ Perform various operations on the topic clusters, such as viewing random samples or generating summaries:
147
+
148
+ #### Display Cluster Samples:
149
+ View random samples from any cluster to explore associated documents:
150
+ ``` python
151
+ cm.print_cluster_samples('Cluster 1', 3)
152
+ ```
153
+
154
+ #### Retrieve Flattened Conversation Text:
155
+ Flatten the conversational data for a specific document ID:
156
+ ``` python
157
+ doc_id = 'rtsodc'
158
+ text = cm.retrieve_conversation(doc_id)
159
+ print(text)
160
+ ```
161
+
162
+ #### Save Cluster Summary:
163
+ Create and save a summary of clusters, including cluster statistics and a topic label column for annotation:
164
+ ``` python
165
+ cm.save_clusters_summary()
166
+ ```
167
+
168
+
169
+ ## **Building and Analyzing Topics**
170
+
171
+ ### Build the Topics DataFrame:
172
+ Once clusters have been annotated with topic labels, build a topics DataFrame:
173
+ ``` python
174
+ cm.build_topics("clusters_summary.csv")
175
+ cm.df_topics.head()
176
+ ```
177
+ Alternatively, generate the topics DataFrame based on clusters containing a minimum percentage of documents (e.g., 7%):
178
+ ``` python
179
+ cm.build_topics(min_percent=7)
180
+ ```
181
+
182
+ ### Temporal Topic Analysis:
183
+ Group topics by time intervals, such as days, weeks, months, or years:
184
+ ``` python
185
+ cm.group_by_period(period_type="m")
186
+ cm.df_periods.head()
187
+ ```
188
+ Temporal analysis helps track the progression and evolution of topics over time.