Datasets:
Upload token_filter.py
Browse files- token_filter.py +26 -0
token_filter.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
# Load the JSON data from your file
|
4 |
+
with open('discord_logs.json', 'r') as json_file:
|
5 |
+
data = json.load(json_file)
|
6 |
+
|
7 |
+
# Define the minimum values for filtering
|
8 |
+
minimum_average_token_length = 125 # Set your desired minimum average token length
|
9 |
+
minimum_median_token_length = 125 # Set your desired minimum median token length
|
10 |
+
minimum_conversations_length = 6 # Set your desired minimum length of the 'conversations' array
|
11 |
+
|
12 |
+
# Filter the items that meet the minimum criteria
|
13 |
+
filtered_items = [
|
14 |
+
item for item in data
|
15 |
+
if item.get('average_token_length', 0) >= minimum_average_token_length
|
16 |
+
and item.get('median_token_length', 0) >= minimum_median_token_length
|
17 |
+
and len(item.get('conversations', [])) >= minimum_conversations_length
|
18 |
+
]
|
19 |
+
|
20 |
+
# Save the filtered items to a new JSON file
|
21 |
+
with open(f'{minimum_median_token_length}_tokens_{minimum_conversations_length}_messages.json', 'w') as filtered_json_file:
|
22 |
+
json.dump(filtered_items, filtered_json_file, indent=4)
|
23 |
+
|
24 |
+
# Optionally, you can print the filtered items
|
25 |
+
for i, item in enumerate(filtered_items):
|
26 |
+
print(f"Filtered Item {i + 1} - Average Token Length: {item.get('average_token_length')}, Conversations Length: {len(item.get('conversations', []))}")
|