-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_graphs_types.R
44 lines (40 loc) · 2.36 KB
/
rules_graphs_types.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
consequent_type_chart(rules_albacete1day, albacete_reltypes, "albacete1day", "Albacete (1 day)")
consequent_type_chart(rules_albacete1week, albacete_reltypes, "albacete1week", "Albacete (7 days)")
consequent_type_chart(rules_antequera1day, antequera_reltypes, "antequera1day", "Antequera (1 day)")
consequent_type_chart(rules_segovia1day, segovia_reltypes, "segovia1day", "Segovia (1 day)")
consequent_type_chart(rules_segovia2days, segovia_reltypes, "segovia2days", "Segovia (2 days)")
consequent_type_chart(rules_segovia7days, segovia_reltypes, "segovia7days", "Segovia (7 days)")
consequent_type_chart(rules_sevilla1day, sevilla_reltypes, "sevilla1day", "Sevilla (1 day)")
antequera_reltypes <- unique(data.frame(ADDITIONAL_TEXT = antequera$ADDITIONAL_TEXT, EVENT_TYPE = antequera$EVENT_TYPE))
albacete_reltypes <- unique(data.frame(ADDITIONAL_TEXT = albacete$ADDITIONAL_TEXT, EVENT_TYPE = albacete$EVENT_TYPE))
segovia_reltypes <- unique(data.frame(ADDITIONAL_TEXT = segovia$ADDITIONAL_TEXT, EVENT_TYPE = segovia$EVENT_TYPE))
sevilla_reltypes <- unique(data.frame(ADDITIONAL_TEXT = sevilla$ADDITIONAL_TEXT, EVENT_TYPE = sevilla$EVENT_TYPE))
consequent_type_chart <- function(ruleset, translationdf, name, title="", path="graphs/consequent_types") {
if (nrow(ruleset) != 0) {
translationdf <- translationdf[translationdf$EVENT_TYPE != "",]
translationdf$EVENT_TYPE <- factor(translationdf$EVENT_TYPE)
ruleset <- ruleset[ruleset$precision > 0.5,]
dir.create(path, showWarnings = FALSE)
rules <- as.character(ruleset$rule)
consequents <- sapply(rules, getconsequent)
consequents <- data.frame(consequent = consequents)
consequent_types <- merge(consequents,translationdf, by.x = "consequent", by.y ="ADDITIONAL_TEXT")
numtypes <- table(consequent_types$EVENT_TYPE)
proptypes <- prop.table(numtypes)
filename <- paste(path,"/",name,"_conseqtypes.png",sep="")
png(filename, res=150, height=1000, width=1000)
par(mar=c(16,5,5,5))
bp <- barplot(numtypes, col=rainbow(length(names(numtypes))), main=paste("Distribution by consequent type for",title), las=3)
text(x=bp,y=c(numtypes),labels=c(numtypes),cex=1.25,pos=3,xpd=TRUE)
dev.off()
}
}
getconsequent <- function(rule) {
cons <- strsplit(rule,"\\{")
cons <- cons[[1]]
cons <- cons[[length(cons)]]
cons <- strsplit(cons,"\\}")
cons <- cons[[1]]
cons <- cons[[1]]
return(cons)
}