comid 0.0.2__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/LICENSE +21 -0
- comid-0.0.2/PKG-INFO +194 -0
- comid-0.0.2/README.md +174 -0
- comid-0.0.2/comid/__init__.py +507 -0
- comid-0.0.2/comid/scraper.py +245 -0
- comid-0.0.2/comid.egg-info/PKG-INFO +194 -0
- comid-0.0.2/comid.egg-info/SOURCES.txt +10 -0
- comid-0.0.2/comid.egg-info/dependency_links.txt +1 -0
- comid-0.0.2/comid.egg-info/requires.txt +8 -0
- comid-0.0.2/comid.egg-info/top_level.txt +1 -0
- comid-0.0.2/setup.cfg +4 -0
- comid-0.0.2/setup.py +37 -0
comid-0.0.2/LICENSE
ADDED
|
@@ -0,0 +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
|
|
21
|
+
SOFTWARE.
|
comid-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: comid
|
|
3
|
+
Version: 0.0.2
|
|
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
|
+
|
|
21
|
+
# COMID - Community identification module for Reddit conversations
|
|
22
|
+
|
|
23
|
+
COMID is a package of tools for analyzing conversations on Reddit
|
|
24
|
+
|
|
25
|
+
### What does COMID?
|
|
26
|
+
|
|
27
|
+
- Collects submissions from a subreddit
|
|
28
|
+
- Generates a corpus based on the O.C. (original content) of the submissions.
|
|
29
|
+
- Assists in the annotation of topics in pre-grouped conversation clusters.
|
|
30
|
+
- Conducts temporal analysis of topics.
|
|
31
|
+
|
|
32
|
+
### What does Comid not do?
|
|
33
|
+
|
|
34
|
+
- Comid does not conduct topic modeling. For topic modeling, we recommend using the SBM [https://github.com/martingerlach/hSBM_Topicmodel](https://github.com/martingerlach/hSBM_Topicmodel).
|
|
35
|
+
|
|
36
|
+
# Quick Start
|
|
37
|
+
|
|
38
|
+
Install Comid and download the en_core_web_sm model
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install comid
|
|
42
|
+
python -m spacy download en_core_web_sm
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Import RedditScrapper submodule, creates a RedditScraper instance and configure the reddit credentials.
|
|
46
|
+
|
|
47
|
+
If you don’t have the credentials, you can follow the instructions here:
|
|
48
|
+
|
|
49
|
+
[How to get client_id and client_secret for Python Reddit API registration ? - GeeksforGeeks](https://www.geeksforgeeks.org/how-to-get-client_id-and-client_secret-for-python-reddit-api-registration/)
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from comid.scraper import RedditScraper
|
|
53
|
+
import datetime as dt
|
|
54
|
+
|
|
55
|
+
rscrap = RedditScraper()
|
|
56
|
+
|
|
57
|
+
#setup reddit credentials
|
|
58
|
+
rscrap.config_credentials(
|
|
59
|
+
client_id= "YOUR_CLIENT_ID",
|
|
60
|
+
client_secret= "YOUR_CLIENT_SECRET",
|
|
61
|
+
password= "YOUR_PASSWORD",
|
|
62
|
+
username= "YOUR_USERNAME"
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Inform the subreddit and date range and download the O.C. ids.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
subreddit = 'digitalnomad' # the subreddit
|
|
70
|
+
start_dt = dt.datetime(2022,1,1) # the initial date
|
|
71
|
+
end_dt = dt.datetime(2022,1,2) #the final date
|
|
72
|
+
|
|
73
|
+
# downlaod the O.C ids of given subreddit and date range
|
|
74
|
+
rscrap.search_ids_by_datetime(subreddit,start_dt,end_dt)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Download all submissions of collected ids, including O.C, comments and replies
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
rscrap.donwload_by_ids()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Import Comid and load the json files of files of Reddit submissions.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from comid import Comid
|
|
87
|
+
cm = Comid()
|
|
88
|
+
# Load all json files as a list. You can use full or relative path for every file
|
|
89
|
+
files = ['dataset/submissions.json','dataset/comments.json']
|
|
90
|
+
cm.load_json_files(files=files)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Generate the corpus of submission posts. The corpus includes only the main submission, not will include the comments and replies. This step can expends few minutes if has a large number of posts.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
cm.generate_corpus()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Once generated, The corpus can be accessed in the atribute `corpus`. Explore the corpus and check the corpus size.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
print("corpus size: ",len(cm.corpus))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
For a reasonable runtime topic modelling using SBM, it is recommended that the corpus does not exceed the approximate size of 6000 documents. If the corpus is too large, perform the next step to shrink the corpus.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# reduce the corpus by optimizing the number of tokens and pinning documents that have
|
|
109
|
+
# at last 10 interactions (comments or replies)
|
|
110
|
+
cm.reduce_corpus(target_size=6000,optimize_num_interactions=False,min_num_interactions=10)
|
|
111
|
+
#print the full corpus length vs reduced corpus length
|
|
112
|
+
print("corpus: ",len(cm.corpus),"corpus_reduced: ",len(cm.corpus_reduced))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Save the corpus as a json to used in HSMB
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# gerating json of reduced corpus
|
|
119
|
+
cm.save_corpus(reduced=True)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Save the current Comid instance in a pickle file to be loaded anytime.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
cm.save()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Use the json file of corpus in a topic modelling. For Comid, it is recommended the use of SBMTopic Model. Here is a guide how to use the corpus in SBM [SBM Topic Model](SBM.md). Once the topic modelling is finished, the previous Comid state can be loaded.
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from comid import Comid
|
|
132
|
+
# replace the comid_file_name with the name of the file to be loaded
|
|
133
|
+
comid_file_name = "comid_saved_file.pickle"
|
|
134
|
+
cm = Comid.load(comid_file_name)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Load the CSV clusters file generated in topic modelling
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# replace the cluster_file with the name of the file to be loaded
|
|
141
|
+
cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
|
|
142
|
+
cm.load_clusters_file(cluster_file )
|
|
143
|
+
# show clusters dataframe
|
|
144
|
+
cm.df_clusters.head()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Print random samples from any Cluster executing the method `print_cluster_samples`
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Printing 3 random samples from 'Cluster 1'
|
|
151
|
+
cm.print_cluster_samples('Cluster 1',3)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Also, it is possible to retrieve a conversation flatten text by a document id
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
# replace the doc_id with the id of document to retrieve
|
|
158
|
+
doc_id = 'rtsodc'
|
|
159
|
+
text = c.retrieve_conversation(doc_id)
|
|
160
|
+
print(text)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Save a CSV summary of clusters. The summary file contains four columns: Cluster (cluster id), Num Docs (number of documents in cluster), Percent (percentual of documents in the cluster from all documents) and Topic (To annotate the topic label).
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
cm.save_clusters_summary()
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Use the saved file in previous step to annotate the topics label in the `Topic` column.
|
|
170
|
+
|
|
171
|
+
Build the topics data frame from Topics annotated in cluster summary CSV. Clusters not annotated will not be included in the data frame.
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
cm.build_topics("clusters_summary.csv")
|
|
175
|
+
cm.df_topics.head()
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Alternatively, it is possible to build the topics data frame without annotate the topic labels. In this case, it this case the method will consider a minimum value for the percentual of documents to include the cluster in the topic data frame.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
# build the df_topics just for the clusters with a minimal of 7% of documents.
|
|
182
|
+
# if omitted the parameter min_percent, it will consider 10%
|
|
183
|
+
cm.build_topics(min_percent=7)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Explore the topics grouping them by periods
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
# Group topics by months.
|
|
190
|
+
# parameter period_type can be 'd' for days, 'w' for weeks, 'm' for months and
|
|
191
|
+
# 'y' for years
|
|
192
|
+
cm.group_by_period(period_type="m")
|
|
193
|
+
cm.df_periods
|
|
194
|
+
```
|
comid-0.0.2/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# COMID - Community identification module for Reddit conversations
|
|
2
|
+
|
|
3
|
+
COMID is a package of tools for analyzing conversations on Reddit
|
|
4
|
+
|
|
5
|
+
### What does COMID?
|
|
6
|
+
|
|
7
|
+
- Collects submissions from a subreddit
|
|
8
|
+
- Generates a corpus based on the O.C. (original content) of the submissions.
|
|
9
|
+
- Assists in the annotation of topics in pre-grouped conversation clusters.
|
|
10
|
+
- Conducts temporal analysis of topics.
|
|
11
|
+
|
|
12
|
+
### What does Comid not do?
|
|
13
|
+
|
|
14
|
+
- Comid does not conduct topic modeling. For topic modeling, we recommend using the SBM [https://github.com/martingerlach/hSBM_Topicmodel](https://github.com/martingerlach/hSBM_Topicmodel).
|
|
15
|
+
|
|
16
|
+
# Quick Start
|
|
17
|
+
|
|
18
|
+
Install Comid and download the en_core_web_sm model
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install comid
|
|
22
|
+
python -m spacy download en_core_web_sm
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import RedditScrapper submodule, creates a RedditScraper instance and configure the reddit credentials.
|
|
26
|
+
|
|
27
|
+
If you don’t have the credentials, you can follow the instructions here:
|
|
28
|
+
|
|
29
|
+
[How to get client_id and client_secret for Python Reddit API registration ? - GeeksforGeeks](https://www.geeksforgeeks.org/how-to-get-client_id-and-client_secret-for-python-reddit-api-registration/)
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from comid.scraper import RedditScraper
|
|
33
|
+
import datetime as dt
|
|
34
|
+
|
|
35
|
+
rscrap = RedditScraper()
|
|
36
|
+
|
|
37
|
+
#setup reddit credentials
|
|
38
|
+
rscrap.config_credentials(
|
|
39
|
+
client_id= "YOUR_CLIENT_ID",
|
|
40
|
+
client_secret= "YOUR_CLIENT_SECRET",
|
|
41
|
+
password= "YOUR_PASSWORD",
|
|
42
|
+
username= "YOUR_USERNAME"
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Inform the subreddit and date range and download the O.C. ids.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
subreddit = 'digitalnomad' # the subreddit
|
|
50
|
+
start_dt = dt.datetime(2022,1,1) # the initial date
|
|
51
|
+
end_dt = dt.datetime(2022,1,2) #the final date
|
|
52
|
+
|
|
53
|
+
# downlaod the O.C ids of given subreddit and date range
|
|
54
|
+
rscrap.search_ids_by_datetime(subreddit,start_dt,end_dt)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Download all submissions of collected ids, including O.C, comments and replies
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
rscrap.donwload_by_ids()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Import Comid and load the json files of files of Reddit submissions.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from comid import Comid
|
|
67
|
+
cm = Comid()
|
|
68
|
+
# Load all json files as a list. You can use full or relative path for every file
|
|
69
|
+
files = ['dataset/submissions.json','dataset/comments.json']
|
|
70
|
+
cm.load_json_files(files=files)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Generate the corpus of submission posts. The corpus includes only the main submission, not will include the comments and replies. This step can expends few minutes if has a large number of posts.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
cm.generate_corpus()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Once generated, The corpus can be accessed in the atribute `corpus`. Explore the corpus and check the corpus size.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
print("corpus size: ",len(cm.corpus))
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
For a reasonable runtime topic modelling using SBM, it is recommended that the corpus does not exceed the approximate size of 6000 documents. If the corpus is too large, perform the next step to shrink the corpus.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# reduce the corpus by optimizing the number of tokens and pinning documents that have
|
|
89
|
+
# at last 10 interactions (comments or replies)
|
|
90
|
+
cm.reduce_corpus(target_size=6000,optimize_num_interactions=False,min_num_interactions=10)
|
|
91
|
+
#print the full corpus length vs reduced corpus length
|
|
92
|
+
print("corpus: ",len(cm.corpus),"corpus_reduced: ",len(cm.corpus_reduced))
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Save the corpus as a json to used in HSMB
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# gerating json of reduced corpus
|
|
99
|
+
cm.save_corpus(reduced=True)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Save the current Comid instance in a pickle file to be loaded anytime.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
cm.save()
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use the json file of corpus in a topic modelling. For Comid, it is recommended the use of SBMTopic Model. Here is a guide how to use the corpus in SBM [SBM Topic Model](SBM.md). Once the topic modelling is finished, the previous Comid state can be loaded.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from comid import Comid
|
|
112
|
+
# replace the comid_file_name with the name of the file to be loaded
|
|
113
|
+
comid_file_name = "comid_saved_file.pickle"
|
|
114
|
+
cm = Comid.load(comid_file_name)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Load the CSV clusters file generated in topic modelling
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# replace the cluster_file with the name of the file to be loaded
|
|
121
|
+
cluster_file = 'path_to_file/topsbm_level_1_clusters.csv'
|
|
122
|
+
cm.load_clusters_file(cluster_file )
|
|
123
|
+
# show clusters dataframe
|
|
124
|
+
cm.df_clusters.head()
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Print random samples from any Cluster executing the method `print_cluster_samples`
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# Printing 3 random samples from 'Cluster 1'
|
|
131
|
+
cm.print_cluster_samples('Cluster 1',3)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Also, it is possible to retrieve a conversation flatten text by a document id
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
# replace the doc_id with the id of document to retrieve
|
|
138
|
+
doc_id = 'rtsodc'
|
|
139
|
+
text = c.retrieve_conversation(doc_id)
|
|
140
|
+
print(text)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Save a CSV summary of clusters. The summary file contains four columns: Cluster (cluster id), Num Docs (number of documents in cluster), Percent (percentual of documents in the cluster from all documents) and Topic (To annotate the topic label).
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
cm.save_clusters_summary()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Use the saved file in previous step to annotate the topics label in the `Topic` column.
|
|
150
|
+
|
|
151
|
+
Build the topics data frame from Topics annotated in cluster summary CSV. Clusters not annotated will not be included in the data frame.
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
cm.build_topics("clusters_summary.csv")
|
|
155
|
+
cm.df_topics.head()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Alternatively, it is possible to build the topics data frame without annotate the topic labels. In this case, it this case the method will consider a minimum value for the percentual of documents to include the cluster in the topic data frame.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
# build the df_topics just for the clusters with a minimal of 7% of documents.
|
|
162
|
+
# if omitted the parameter min_percent, it will consider 10%
|
|
163
|
+
cm.build_topics(min_percent=7)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Explore the topics grouping them by periods
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
# Group topics by months.
|
|
170
|
+
# parameter period_type can be 'd' for days, 'w' for weeks, 'm' for months and
|
|
171
|
+
# 'y' for years
|
|
172
|
+
cm.group_by_period(period_type="m")
|
|
173
|
+
cm.df_periods
|
|
174
|
+
```
|