Spaces:
Runtime error
Runtime error
13macattack37
commited on
Commit
•
159bf74
1
Parent(s):
07962c4
Adding a main for testing text_classifier
Browse files- text-classifier/main.py +48 -0
text-classifier/main.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from text_classifier import text_classifier
|
2 |
+
|
3 |
+
# Some examples of tweets:
|
4 |
+
data_dict = {'25 years ago we made a promise to the people of Hong Kong. We intend to keep it. https://t.co/nIN96ZydgV': {'hour': '17',
|
5 |
+
'nlikes': 7878,
|
6 |
+
'nreplies': 2999,
|
7 |
+
'nretweets': 1993,
|
8 |
+
'topic': '',
|
9 |
+
'sentiment': ''},
|
10 |
+
'A huge delight to meet @SwedishPM Magdalena Andersson and President @niinisto again. The accession of Finland and Sweden to @NATO will permanently strengthen our defensive Alliance, helping to keep us all safe. #WeAreNATO https://t.co/pArvdWHr2F': {'hour': '16',
|
11 |
+
'nlikes': 3468,
|
12 |
+
'nreplies': 686,
|
13 |
+
'nretweets': 435,
|
14 |
+
'topic': '',
|
15 |
+
'sentiment': ''},
|
16 |
+
'At this @NATO Leaders’ Summit, I’ll be urging fellow nations to continue to do everything they can to support Ukraine. The UK has always played a historic role in the @NATO alliance, working to address the biggest global threats and build a more secure world.': {'hour': '07',
|
17 |
+
'nlikes': 7742,
|
18 |
+
'nreplies': 1838,
|
19 |
+
'nretweets': 1112,
|
20 |
+
'topic': '',
|
21 |
+
'sentiment': ''},
|
22 |
+
'Morgan Johansson måste avgå som minister. Otryggheten biter sig fast och gängkriminaliteten är allt annat än knäckt. Antalet skjutningar ökar och sätter skräck i varje del av vårt land. Sverige har förvandlats till ett gangsterland.': {'hour': '16',
|
23 |
+
'nlikes': 3468,
|
24 |
+
'nreplies': 686,
|
25 |
+
'nretweets': 435,
|
26 |
+
'topic': '',
|
27 |
+
'sentiment': ''},
|
28 |
+
'Döms man för brott, särskilt våldsbrott, ska man vara inlåst från det att domen faller tills straffet är avtjänat. Allt annat är vansinne.': {'hour': '16',
|
29 |
+
'nlikes': 3468,
|
30 |
+
'nreplies': 686,
|
31 |
+
'nretweets': 435,
|
32 |
+
'topic': '',
|
33 |
+
'sentiment': ''},
|
34 |
+
'Motionerna: ' + '\n' + 'K339 avslogs av enig riksdag (inkl KD).' + '\n' + 'K220 avslogs av enig riksdag (inkl KD).' + '\n' + '1601 avslogs av enig riksdag (inkl KD).' + '\n' + 'K281 avslogs av enig riksdag (inkl KD).' + '\n' + '\n' + '¯\_(ツ)_/¯': {'hour': '16',
|
35 |
+
'nlikes': 3468,
|
36 |
+
'nreplies': 686,
|
37 |
+
'nretweets': 435,
|
38 |
+
'topic': '',
|
39 |
+
'sentiment': ''}
|
40 |
+
}
|
41 |
+
|
42 |
+
# Classify the TOPICS and insert the results into the data dictionary found above
|
43 |
+
topic_results = text_classifier.classify_topics(data_dict)
|
44 |
+
# Classify the SENTIMENTS and insert the results into the data dictionary found above
|
45 |
+
sentiment_results = text_classifier.classify_sentiments(data_dict)
|
46 |
+
# Print simple statistics related to TOPICS and SENTIMENTS
|
47 |
+
text_classifier.print_stats(sentiment_results)
|
48 |
+
|