-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessToolResults.R
239 lines (184 loc) · 10.4 KB
/
processToolResults.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
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
library(ggplot2)
library(ggsci)
library(stringr)
source('utils.R')
experimentName <- "Experiment_50_all"
pathDocuments <- paste("/Users/kresimir/Experiments/", experimentName, "/", experimentName ,"/Documents/", sep="")
pathResults <- paste("/Users/kresimir/Experiments/", experimentName, "/", experimentName, "/Results/", sep="")
pathToolResults <- paste(pathResults, "", sep="")
#tools <- c("ApacheTika1_1", "ApacheTika1_2", "ApacheTika1_13", "DocToText", "Xpdf", "icecite", "AbiWord")
listTools <- list.files(pathToolResults)
print(listTools)
listFiles <- list.files(pathDocuments)
dfHolder <- data.frame(testCaseName=character(), toolName=character(), measure=character(), value=character(), format=character())
for (tool in listTools) {
pTR <- paste(pathToolResults, tool, "/results/", sep="")
for (f in listFiles) {
filNameList <- unlist(strsplit(f, ".", fixed=TRUE))
name <- filNameList[1]
extension <- filNameList[2]
fileResult <- paste(pTR, name, ".xml", sep="")
if (file.exists(fileResult)) {
print(fileResult)
tmp <- readDocumentMeasures(fileResult, extension)
dfHolder <- rbind(dfHolder, tmp)
}
}
}
#dfHolder[dfHolder$toolName=="ApacheTika_11",]$toolName <- "Apache Tika v1.1"
#dfHolder[dfHolder$toolName=="ApacheTika_12",]$toolName <- "Apache Tika v1.2"
#dfHolder[dfHolder$toolName=="ApacheTika_113",]$toolName <- "Apache Tika v1.13"
#barPlot <- ggplot(dfAvgCorrect, aes(x=factor(testCaseName), y=value, fill=toolName)) +
# geom_bar(stat="identity", position="dodge") +
# coord_flip()
#barPlot
############
# ALL FORMATS
###########
allTotalResults <- data.frame(toolName=character(), measureName=character(), value=numeric())
#avgCorrect
dfAvgCorrect <- dfHolder[dfHolder$measure=="percCorrect",]
dfAvgCorrect <- dfAvgCorrect[!is.nan(dfAvgCorrect$value),]
dfAvgCorrect$value <- as.numeric(as.character(dfAvgCorrect$value))
totalResults <- dfAvgCorrect[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Apache Tika v1.1", "Apache Tika v1.2", "Apache Tika v1.13", "Apache Tika v1.19", "DocToText v4.01512", "AbiWord v3.0.0"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgCorrect"
allTotalResults <- totalResults
barPlotAvgCorrect <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Percentage of correctly extracted text (avgCorrect)")
barPlotAvgCorrect
#avgOrder
dfAvgOrder <- dfHolder[dfHolder$measure=="orderPreserved",]
dfAvgOrder <- dfAvgOrder[!is.nan(dfAvgOrder$value),]
dfAvgOrder$value <- as.logical(as.character(dfAvgOrder$value))
dfAvgOrder[dfAvgOrder$value==TRUE,]$value <- 1
dfAvgOrder[dfAvgOrder$value==FALSE,]$value <- 0
totalResults <- dfAvgOrder[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Apache Tika v1.1", "Apache Tika v1.2", "Apache Tika v1.13", "Apache Tika v1.19", "DocToText v4.01512", "AbiWord v3.0.0"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgOrder"
allTotalResults <- rbind(allTotalResults, totalResults)
barPlotAvgOrder <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Percentage of files with correct order (avgOrder)")
barPlotAvgOrder
#avgLayout
dfAvgLayout <- dfHolder[dfHolder$measure=="percLayoutPreserved",]
dfAvgLayout <- dfAvgLayout[!is.nan(dfAvgLayout$value),]
dfAvgLayout$value <- as.numeric(as.character(dfAvgLayout$value))
totalResults <- dfAvgLayout[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Apache Tika v1.1", "Apache Tika v1.2", "Apache Tika v1.13", "Apache Tika v1.19", "DocToText v4.01512", "AbiWord v3.0.0"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgLayout"
allTotalResults <- rbind(allTotalResults, totalResults)
barPlotAvgLayout <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Average percentage of snippets with preserved layout (avgLayout)")
barPlotAvgLayout
allTotalResults$toolName <- str_wrap(allTotalResults$toolName, width=10)
allTotalResults$measureName <- factor(allTotalResults$measureName, levels=c("avgCorrect", "avgOrder", "avgLayout"))
barPlotAllResults <- ggplot(allTotalResults, aes(x=toolName, y=value, fill=measureName)) +
geom_bar(stat="identity", position="dodge", width = 0.75, colour="gray25") +
geom_text(aes(label=round(value, digits = 2)), position = position_dodge(width=0.8), vjust=-0.5, size=4) +
scale_y_continuous(limits = c(0,1.00)) +
scale_fill_brewer() + theme_bw() +
theme(axis.title.x = element_blank(), axis.title.y=element_blank(),
axis.text = element_text(size=12), axis.title = element_text(size=16),
legend.position="bottom", legend.title=element_blank(),
legend.text=element_text(size=15))
pathPlot <- paste(pathResults, "allPlot.png", sep="");
png(pathPlot, width=640, heigh=480)
print(barPlotAllResults)
dev.off()
############
# ONLY PDF
###########
allTotalResults <- data.frame(toolName=character(), measureName=character(), value=numeric())
#avgCorrect
dfAvgCorrect <- dfHolder[dfHolder$measure=="percCorrect",]
dfAvgCorrect <- dfAvgCorrect[dfAvgCorrect$format=="pdf",]
dfAvgCorrect <- dfAvgCorrect[!is.nan(dfAvgCorrect$value),]
dfAvgCorrect$value <- as.numeric(as.character(dfAvgCorrect$value))
totalResults <- dfAvgCorrect[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Xpdf", "Apache Tika v1.13", "DocToText", "icecite", "AbiWord"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgCorrect"
allTotalResults <- totalResults
barPlotAvgCorrect <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Percentage of correctly extracted text (avgCorrect)")
barPlotAvgCorrect
#avgOrder
dfAvgOrder <- dfHolder[dfHolder$measure=="orderPreserved",]
dfAvgOrder <- dfAvgOrder[dfAvgOrder$format=="pdf",]
dfAvgOrder <- dfAvgOrder[!is.nan(dfAvgOrder$value),]
dfAvgOrder$value <- as.logical(as.character(dfAvgOrder$value))
dfAvgOrder[dfAvgOrder$value==TRUE,]$value <- 1
dfAvgOrder[dfAvgOrder$value==FALSE,]$value <- 0
totalResults <- dfAvgOrder[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Xpdf", "Apache Tika v1.13", "DocToText", "icecite", "AbiWord"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgOrder"
allTotalResults <- rbind(allTotalResults, totalResults)
barPlotAvgOrder <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Percentage of files with correct order (avgOrder)")
barPlotAvgOrder
#avgLayout
dfAvgLayout <- dfHolder[dfHolder$measure=="percLayoutPreserved",]
dfAvgLayout <- dfAvgLayout[dfAvgLayout$format=="pdf",]
dfAvgLayout <- dfAvgLayout[!is.nan(dfAvgLayout$value),]
dfAvgLayout$value <- as.numeric(as.character(dfAvgLayout$value))
totalResults <- dfAvgLayout[,c(FALSE,TRUE,FALSE,TRUE)]
totalResults <- aggregate(value~toolName, totalResults, FUN = mean)
totalResults <- totalResults[totalResults$toolName %in% c("Xpdf", "Apache Tika v1.13", "DocToText", "icecite", "AbiWord"),]
totalResults <- transform(totalResults, toolName = reorder(toolName, -value))
totalResults$measureName <- "avgLayout"
allTotalResults <- rbind(allTotalResults, totalResults)
barPlotAvgLayout <- ggplot(totalResults, aes(x=toolName, y=value)) +
geom_bar(stat="identity", position="dodge", width = 0.7) +
geom_text(aes(label=round(value, digits = 3)), position = position_dodge(width=0.9),vjust=-0.25) +
scale_y_continuous(limits = c(0,1.00)) +
labs(x="Tool Name", y="Average percentage of snippets with preserved layout (avgLayout)")
barPlotAvgLayout
allTotalResults$measureName <- factor(allTotalResults$measureName, levels=c("avgCorrect", "avgOrder", "avgLayout"))
barPlotAllResults <- ggplot(allTotalResults, aes(x=toolName, y=value, fill=measureName)) +
geom_bar(stat="identity", position="dodge", width = 0.75, colour="gray25") +
geom_text(aes(label=round(value, digits = 2)), position = position_dodge(width=0.8), vjust=-0.5, size=5) +
scale_y_continuous(limits = c(0,1.00)) +
scale_fill_brewer() + theme_bw() +
theme(axis.title.x = element_blank(), axis.title.y=element_blank(),
axis.text = element_text(size=17), axis.title = element_text(size=20),
legend.position="bottom", legend.title=element_blank(),
legend.text=element_text(size=15))
barPlotAllResults
png(path, width=640, heigh=480)
##########################
# calculating the worst #
# 10 files for each tool #
##########################
tools <- c("Apache Tika v1.1", "Apache Tika v1.2", "Apache Tika v1.13", "DocToText", "AbiWord")
for (tool in tools) {
currentToolRes <- dfHolder[dfHolder$toolName==tool & dfHolder$measure=="percCorrect",]
currentToolRes$value <- as.numeric(as.character(currentToolRes$value))
currentToolRes <- currentToolRes[order(currentToolRes$value),]
write.table(currentToolRes[1:10,], paste(pathResults,tool,".tsv", sep=""), sep="\t",row.names=FALSE,
col.names = TRUE)
}