-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAB_RankingTexte.R
83 lines (64 loc) · 2.51 KB
/
AB_RankingTexte.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
library(readxl)
library(dplyr)
# Liste der Metriken für beide Skalen
scale_1_metrics <- c("Honesty", "Correctness", "ContextAdherent", "Relevancy", "Completeness")
scale_2_metrics <- c("Comprehensible", "Readability", "Fluency", "Understandability", "NonRedundancy")
# Funktion zur Zählung der Siege pro Metrik oder Skala
count_wins <- function(metric_columns, data) {
win_counts <- rep(0, 8) # Initialisiere den Zähler für die Siege für jeden Text (1 bis 8)
for (i in 1:nrow(data)) {
for (col in metric_columns) {
value <- as.numeric(data[[col]][i])
if (!is.na(value) && value > 0) {
win_counts[value] <- win_counts[value] + 1
}
}
}
return(win_counts)
}
# 1. Metriken
metrics <- c(scale_1_metrics, scale_2_metrics)
for (metric in metrics) {
metric_columns <- grep(metric, names(df), value = TRUE)
win_counts <- count_wins(metric_columns, df)
win_df <- data.frame(Text = 1:8, Wins = win_counts)
win_df <- win_df %>% arrange(desc(Wins))
# Ausgabe der Rangliste für diese Metrik
cat("Ranking for", metric, ":\n")
print(win_df)
cat("\n")
}
# 2. Skala Honesty
scale_1_columns <- grep(paste(scale_1_metrics, collapse="|"), names(df), value = TRUE)
scale_1_win_counts <- count_wins(scale_1_columns, df)
scale_1_df <- data.frame(Text = 1:8, Wins = scale_1_win_counts)
scale_1_df <- scale_1_df %>% arrange(desc(Wins))
cat("Ranking for Skala 1 (Honesty):\n")
print(scale_1_df)
cat("\n")
# 3. Skala Comprehensibility
scale_2_columns <- grep(paste(scale_2_metrics, collapse="|"), names(df), value = TRUE)
scale_2_win_counts <- count_wins(scale_2_columns, df)
scale_2_df <- data.frame(Text = 1:8, Wins = scale_2_win_counts)
scale_2_df <- scale_2_df %>% arrange(desc(Wins))
cat("Ranking for Skala 2 (Comprehensibility):\n")
print(scale_2_df)
cat("\n")
#4. Total
# Liste der Metriken, die analysiert werden sollen
metrics <- c("Honesty", "Correctness", "ContextAdherent", "Relevancy",
"Completeness", "Comprehensible", "Readability", "Fluency",
"Understandability", "NonRedundancy")
metric_columns <- grep(paste(metrics, collapse="|"), names(df), value = TRUE)
win_counts <- rep(0, 8)
for (i in 1:nrow(df)) {
for (col in metric_columns) {
value <- as.numeric(df[[col]][i])
if (!is.na(value) && value > 0) {
win_counts[value] <- win_counts[value] + 1
}
}
}
win_df <- data.frame(Text = 1:8, Wins = win_counts)
win_df <- win_df %>% arrange(desc(Wins))
print(win_df)