-
Notifications
You must be signed in to change notification settings - Fork 2
/
5_dft_convert.R
51 lines (45 loc) · 2.21 KB
/
5_dft_convert.R
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
library(tidyverse)
library(dplyr)
library(readr)
setwd("C:/Users/User/Documents/GitHub/taiwan-mandarin-corpus-annotation/4_final_tokenised")
data <- read.csv("NCCU-TM039-CN-FM_Lu&Yuting.csv")
x = data$Turn
speaker = data$Speaker
for (i in 1:length(data$Utterance)){
print(i)
if (is.na(data$Turn[i])){
x[i]=x[i-1]
speaker[i] = speaker[i-1]
}
}
data = data %>% mutate(Utterance = as.character(Utterance))
result= data %>%
mutate(Utterance=case_when(str_detect(Utterance, "\\.{3}\\([:digit:]\\.[:digit:]\\)") ~
gsub('^.{3}', '', Utterance), T ~ Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, "\\.{3}"),
gsub('\\.{3}', '(...)', Utterance),Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, "^\\.{2}"),
gsub('^\\.{2}', '(.)', Utterance),Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, " \\.{2} "),
gsub(' \\.{2} ', ' (.) ', Utterance),Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, "--"),
gsub('--', '—', Utterance),Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, "\\[{3}"),
gsub('\\[{3}', '[3', Utterance),Utterance))%>%
mutate(Utterance=ifelse(str_detect(Utterance, "\\[{2}"),
gsub('\\[{2}', '[2', Utterance),Utterance))%>%
mutate(Utterance=ifelse(str_detect(Utterance, "\\]{3}"),
gsub('\\]{3}', '3]', Utterance),Utterance))%>%
mutate(Utterance=ifelse(str_detect(Utterance, "\\]{2}"),
gsub('\\]{2}', '2]', Utterance),Utterance)) %>%
mutate(Utterance=ifelse(str_detect(Utterance, "X"),
gsub('X', '#', Utterance),Utterance)) %>%
mutate(Speaker=ifelse(str_detect(Speaker, "M1:"),
gsub('M1:', 'M1', Speaker),Speaker)) %>%
mutate(Speaker=ifelse(str_detect(Speaker, "M2:"),
gsub('M2:', 'M2', Speaker),Speaker)) %>%
rename(c(TurnSeq = "Turn")) %>%
mutate(TurnSeq=x) %>%
mutate(Speaker = speaker) %>%
mutate(IUSeq=seq(1,length(data$Utterance)))
write.csv(result,"../5_dft_converted/NCCU-TM039-CN-FM_Lu&Yuting.csv",fileEncoding = "UTF-8")