-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 21.3 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
str_remove_all("http.*?( |$)") %>%
str_remove_all("\n") %>%
str_replace_all(pattern = "&",replacement = "&") %>% #replaced with white space because of consecutive hashtags
str_replace_all("( )+", " ")# I might as well do all the preprocessing here actually...
spelling_mistakes<- hunspell(text = for_spell_checking_tweets,format = "text",ignore = to_ignore) %>% unlist()
spelling_suggestions<- hunspell_suggest(spelling_mistakes) %>% map(.,1) %>% set_names(nm = spelling_mistakes)
spelling_mistakes<- hunspell(text = for_spell_checking_tweets,format = "text",ignore = to_ignore) %>% unlist() %>% unique()
spelling_mistakes
spelling_suggestions<- hunspell_suggest(spelling_mistakes) %>% map(.,1) %>% set_names(nm = spelling_mistakes)
View(spelling_suggestions)
hunspell::list_dictionaries()
spelling_mistakes<- hunspell(text = for_spell_checking_tweets,format = "text",ignore = to_ignore,dict = dictionary("en_GB")) %>% unlist() %>% unique()
spelling_suggestions<- hunspell_suggest(spelling_mistakes) %>% map(.,1) %>% set_names(nm = spelling_mistakes)
View(spelling_suggestions)
spelling_mistakes<- hunspell_check(text = for_spell_checking_tweets,format = "text",ignore = to_ignore,dict = dictionary("en_GB")) %>% unlist() %>% unique()
no_emoji_tweets
library("qdapRegex")
install.packages(qdapRegex)
install.packages("qdapRegex")
library(qdapRegex)
sandbox<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-level dialog conference",
tweet3 ="ECB announced new measures against inflation",
tweet4 ="After consultation with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day coudln't get any beteter!I received my missoin letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
sandbox<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-level dialog conference",
tweet3 ="ECB announced new measures against inflation",
tweet4 ="After consultation with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day couldn't get any better!I received my mission letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
#get a feeling of the data structure after quanteda preprocessing:####
library(quanteda)
sandbox_corpus<- quanteda::corpus(sandbox)
docnames(sandbox_corpus)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
dfm(.,tolower = T,
remove = stopwords("en"),
stem = T)
stopwords_getsources()
stopwords::stopwords_getsources()
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),10)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),10)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = F) %>%
# tokens_compound(.,
# phrase(c("European Union","EU commission")),
# case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),10)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = F) %>%
# tokens_compound(.,
# phrase(c("European Union","EU commission")),
# case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),10)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
# tokens_compound(.,
# phrase(c("European Union","EU commission")),
# case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),10)
head(colnames(sandbox_dfm),15)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
head(colnames(sandbox_dfm),15)
phrase(c("European Union","EU commission"))
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T)
sandbox_dfm
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
dfm(.,tolower = T)
sandbox_dfm
colnames(sandbox_dfm)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
colnames(sandbox_dfm)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>% tokens_remove(x = ., pattern = "[#][\\w_-]+")
sandbox_dfm
View(sandbox_dfm)
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>% tokens_remove(x = ., pattern = "[#][\\w_-]+")
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
sandbox_dfm<- tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
tokens_remove(x = ., pattern = "[#][\\w_-]+") %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
colnames(sandbox_dfm)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus() %>%
tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
tokens_remove(x = ., pattern = "[#][\\w_-]+") %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
packs<- c("tidyverse","spacyr")
pacman::p_load(char = packs)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus() %>%
tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
tokens_remove(x = ., pattern = "[#][\\w_-]+") %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+")
sandbox
sandbox_dfm
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox))
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox)) %>%
tokens(x = sandbox_corpus,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox)) %>%
tokens(x = .,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox)) %>%
tokens(x = .,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%
tokens_remove(x = ., pattern = "[#][\\w_-]+") %>%
dfm(.,tolower = T) %>%
dfm_remove(.,pattern = stopwords("en")) %>%
dfm_wordstem(.,language = "en")
sandbox_dfm
utils::download.file(url = "http://www.snsoroka.com/wp-content/uploads/2020/08/LTDjun2013.zip",destfile = "./dictionaries")
dir.exists("./dictionaries")
utils::download.file(url = "http://www.snsoroka.com/wp-content/uploads/2020/08/LTDjun2013.zip",destfile = "./dictionaries/")
utils::download.file(url = "http://www.snsoroka.com/wp-content/uploads/2020/08/LTDjun2013.zip",destfile = "./dictionaries/LTDjun2013.zip")
utils::unzip(zipfile = "./dictionaries/LTDjun2013.zip",exdir = "./dictionaries/topic_dictionary")
utils::unzip(zipfile = "./dictionaries/LTDjun2013.zip",exdir = "./dictionaries/")
utils::unzip(zipfile = "./dictionaries/LTDjun2013.zip",exdir = "./dictionaries")
utils::remove.file("./dictionaries/LTDjun2013.zip")
file.remove("./dictionaries/LTDjun2013.zip")
dict<- dictionary(x = "./dictionaries/LTDjun2013/policy_agendas_english.lcd")
dict<- dictionary(file = "./dictionaries/LTDjun2013/policy_agendas_english.lcd")
dict
typeof(dict)
names(dict)
dict[grepl(pattern = "rule*",x = dict)]
grep("rule*",dict)
grep("law",dict)
grep("law",dict,value = T)
grep("law",dict)
dict[[13]]
dict[[1]]
dict[13
]
dict[grep("rule",x = dict)]
dict[grep("rule",x = dict)[1]]
sandbox_policy_dfm <- sandbox_dfm %>% dfm_select(pattern = dict, selection = "keep", case_insensitive = T)
sandbox_policy_dfm
sandbox_policy_dfm <- sandbox_dfm %>% dfm_lookup(x = .,dictionary = dict,case_insensitive = T,capkeys = T,verbose = T)
sandbox_policy_dfm
sandbox_policy <- sandbox_dfm %>%
dfm_lookup(x = .,dictionary = dict,case_insensitive = T,capkeys = T,verbose = T) %>%
convert(.,to = "data.frame",docid_field = "tweet_id")
View(sandbox_policy)
sandbox<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-level dialog conference",
tweet3 ="ECB announced new measures against inflation",
tweet4 ="After consultation with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day couldn't get any better!I received my mission letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
#get a feeling of the data structure after quanteda preprocessing:####
library(quanteda)
sandbox_corpus<- quanteda::corpus(sandbox)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox)) %>%
tokens(x = .,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T,) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%tokens_tolower(.) %>%
tokens_remove(.,stopwords("en")) %>%
tokens_wordstem(.,language = "en") %>%
dfm()
packs<- c("tidyverse","spacyr")
pacman::p_load(char = packs)
sandbox_dfm<- sandbox %>%
str_remove_all("[#][\\w_-]+") %>%
corpus(.,docnames = names(sandbox)) %>%
tokens(x = .,remove_punct = T,
remove_symbols = T,
remove_numbers = T,
remove_url = T,
remove_separators = T,) %>%
tokens_compound(.,
phrase(c("European Union","EU commission")),
case_insensitive = T) %>%tokens_tolower(.) %>%
tokens_remove(.,stopwords("en")) %>%
tokens_wordstem(.,language = "en") %>%
dfm()
dict<- dictionary(file = "./dictionaries/LTDjun2013/policy_agendas_english.lcd")
sandbox_policy <- sandbox_dfm %>%
dfm_lookup(x = .,dictionary = dict,case_insensitive = T,capkeys = T,verbose = T) %>%
convert(.,to = "data.frame",docid_field = "tweet_id")
View(sandbox_policy)
dict["MACROECONOMICS"]
dict
names(dict)
dict[["macroeconomics"]]
dict[["macroeconomics"]]<-c(dict[["macroeconomics"]],"inflati")
dict[["macroeconomics"]]
sandbox_policy <- sandbox_dfm %>%
dfm_lookup(x = .,dictionary = dict,case_insensitive = T,capkeys = T,verbose = T) %>%
convert(.,to = "data.frame",docid_field = "tweet_id")
View(sandbox_policy)
sandbox_dfm
View(sandbox_dfm)
colnameS(sandbox_dfm)
colnames(sandbox_dfm)
dict<- dictionary(file = "./dictionaries/LTDjun2013/policy_agendas_english.lcd")
dict[["macroeconomics"]]<- c(dict[["macroeconomics"]],"inflat")
sandbox_policy <- sandbox_dfm %>%
dfm_lookup(x = .,dictionary = dict,case_insensitive = T,capkeys = T,verbose = T) %>%
convert(.,to = "data.frame",docid_field = "tweet_id")
View(sandbox_policy)
sandbox<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-level dialog conference",
tweet3 ="ECB announced new measures against inflation",
tweet4 ="After consultation with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day couldn't get any better!I received my mission letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
test_a<- str_remove_all(string = sandbox,pattern = "[#][\\w_-]+")
test_b<- gsub(pattern = "[#][\\w_-]+",replacement = "",x = sandbox)
names(test_a)
names(test_b)
test_a
test_b
test_b<- gsub(pattern = "[#][\\w_-]+",replacement = "",x = sandbox,perl = T)
names(test_b)
test_b
library(hunspell)
library(textcat) # 1.0-7, n-gram based language detection
library(cld2) # 1.2
library(cld3) # 1.
library(cld2) # 1.2
#also differing lengths of lists make it hard to vectorize the operation
#testing a for loop approach
to_ignore<- c("TTNET","ECB","OurWay","vdL")
sandbox_spellcheck<- hunspell(text = sandbox,format = "text",ignore = to_ignore)
sandbox_spellcheck<- hunspell(text = sandbox,format = "text",ignore = to_ignore) %>% unlist()
sandbox_misspell<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-level dialog conference",
tweet3 ="ECB announced newmeasures against inflation",
tweet4 ="After consultasion with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day coulnd't get any better!I received my mission letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
sandbox_spellcheck<- hunspell(text = sandbox_misspell,format = "text",ignore = to_ignore) %>% unlist()
sandbox_misspell<- c(tweet1 = "The EU commission has concluded an investigation against Poland due to recent events and found serious breaches of rule-of-law. Poland will be kicked out of the union",
tweet2 ="Amazing organization. I attended the first TTNET high-seviye dialog conference",
tweet3 ="ECB announced newmeasures against inflation",
tweet4 ="After consultasion with relevant stakeholders, we decided to stop vaccination purchases",
tweet5 ="This day coulnd't get any better!I received my mission letter to ensure our European way of life #EU#OurWay!! Great honor to be part of vdL")
to_ignore<- c("TTNET","ECB","OurWay","vdL")
sandbox_spellcheck<- hunspell(text = sandbox_misspell,format = "text",ignore = to_ignore) %>% unlist()
lang_det_test_1<- textcat::textcat(x = sandbox_spellcheck)
lang_det_test_2<- textcat::textcat(x = sandbox_spellcheck,p = ECIMCI_profiles)
lang_det_test_3<- cld2::detect_language_mixed(text = sandbox_spellcheck,plain_text = T)
View(lang_det_test_3)
lang_det_test_3
lang_det_test_3$classification
lang_det_test_3<- cld2::detect_language_mixed(text = sandbox_spellcheck[2],plain_text = T)#this needs looping over
View(lang_det_test_3)
lang_det_test_3<- cld2::detect_language_mixed(text = sandbox_spellcheck[3],plain_text = T)#this needs looping over
lang_det_test_3$classification
lang_det_test_4<- cld3::detect_language_mixed(text = sandbox_spellcheck[3])
View(lang_det_test_4)
lang_det_test_4<- cld3::detect_language_multi(text = sandbox_spellcheck[3])
cld3::detect_language_multi()
file_ftz = system.file("language_identification/lid.176.ftz", package = "fastText")
file_ftz = system.file("./dictionaries/lid.176.ftz", package = "fastText")
#fastText based on the blog post: https://www.r-bloggers.com/2021/05/language-identification-using-the-fasttext-package-a-benchmark/
install.packages("fastText")
library(fastText)
file_ftz = system.file("langugage_detection/lid.176.ftz", package = "fastText")
file_ftz = system.file("langugage_detection/lid.176.ftz", package = "fastText")
model_pat<-("./dictionaries/lid.176.ftz")
lang_det_test_ft = fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = model_pat,
k = 1,
th = 0.0,
threads = 1,
verbose = TRUE)
View(lang_det_test_ft)
small_model<-("./dictionaries/lid.176.ftz")
lang_det_test_ft <- fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = small_model,
k = 3,
th = 0.0,
threads = 1,
verbose = TRUE)
View(lang_det_test_ft)
large_model<- (".7dictionaries/lid.176.bin")
lang_det_test_ft_large<- fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = large_model,
k = 3,
th = 0,
threads = 1,
verbose = T)
large_model<- ("./dictionaries/lid.176.bin")
lang_det_test_ft_large<- fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = large_model,
k = 3,
th = 0,
threads = 1,
verbose = T)
View(lang_det_test_ft_large)
lang_det_test_ft <- fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = small_model,
k = 3,
th = 0.0,
threads = 1,
verbose = TRUE) %>% as_tibble(rownames = "word_id")
View(lang_det_test_ft)
lang_det_test_ft_large<- fastText::language_identification(input_obj = sandbox_spellcheck,
pre_trained_language_model_path = large_model,
k = 3,
th = 0,
threads = 1,
verbose = T) %>% as_tibble(rownames = "word_id")
View(lang_det_test_ft)
View(lang_det_test_ft_large)
packs<- c("tidyverse","spacyr")
pacman::p_load(char = packs)
data.path<- paste0(getwd(),"/analysis_data/")
data_id<- readRDS(paste0(data.path,"EU_corpus_sample.RDS")) %>% pull(tweet_id)
data<- readRDS(file.choose()) %>% filter(id %in% data_id)
tweets<- data %>% filter(lang == "en") %>% pull(text)
tweet_ids <- data %>% filter(lang == "en") %>% pull(id)
political_respons_example<-data %>% filter(id == "1001044775120916480") %>% pull(text)
tweets<-gsub("http.*?( |$)","",tweets,perl = T)
hashtags<- str_extract_all(string = tweets,pattern = "[#][\\w_-]+") %>% unlist() %>% unique()
mentions<- str_extract_all(string = tweets,pattern = "[@][\\w_-]+") %>% unlist() %>% unique()
to_ignore<- c(hashtags,mentions)
tweets_spellcheck <- hunspell(text = tweets, format = "text",ignore = to_ignore)
View(tweets_spellcheck)
tweets[7]
to_ignore
mentions<- str_extract_all(string = tweets,pattern = "[@][\\w_-]+") %>% unlist() %>% unique()
mentions
to_ignore<- c(hashtags,mentions)
mentions
tweets_spellcheck <- hunspell(text = tweets, format = "text",ignore = to_ignore)
View(tweets_spellcheck)
to_ignore
mentions
#interesting, some mentions are not ignored
tweets_spellcheck <- hunspell(text = tweets, format = "text",ignore = to_ignore) %>% unlist()
rl_text_cat<- textcat::textcat(x = tweets_spellcheck)
rl_text_cat
rl_text_cat<- data.frame(word = tweets_spellcheck,
language = textcat::textcat(x = tweets_spellcheck))
View(rl_text_cat)
rl_text_cat_ext<- data.frame(word = tweets_spellcheck,
language = textcat::textcat(x = tweets_spellcheck,p = ECIMCI_profiles))
View(rl_text_cat_ext)
rl_ft_small<- fastText::language_identification(input_obj = tweets_spellcheck,
pre_trained_language_model_path = small_model) %>% rbind(.,tweets_spellcheck)
rl_ft_small<- fastText::language_identification(input_obj = tweets_spellcheck,
pre_trained_language_model_path = small_model)
View(rl_ft_small)
rl_ft_small<- fastText::language_identification(input_obj = tweets_spellcheck,
pre_trained_language_model_path = small_model) %>% cbind(.,tweets_spellcheck)
View(rl_ft_small)
rl_ft_large<- fastText::language_identification(input_obj = tweets_spellcheck,
pre_trained_language_model_path = large_model) %>% cbind(.,tweets_spellcheck)
View(rl_ft_large)
glimpse(tweets)
hashtags<- str_extract_all(string = tweets,pattern = "[#][\\w_-]+|[@][\\w_-]+") %>% unlist() %>% unique()
cat("spellchecking the tweets")
View(rl_ft_large)
spacy_initialize()
spacy_tokenize(x = sandbox,what = "sentence")
a<-spacy_tokenize(x = sandbox,what = "sentence")
View(a)
a<-spacy_tokenize(x = sandbox,what = "sentence",output = "data.frame")
View(a)
a<-spacy_parse(x = sandbox,pos = T,tag = T,lemma = T,entity = T)
a<-spacy_parse(x = sandbox,pos = T,tag = T,lemma = T,entity = T,dependency = T)
a<-spacy_parse(x = political_respons_example,pos = T,tag = T,lemma = T,entity = T,dependency = T)
a
file.exists("./dictionaries/lid.176.bin")