---
title: "revhelp"
output: html_document
date: "2023-11-28"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r library}
library(readxl)
library(ggplot2)
library(dplyr)
library(tidyr)
library(palettes)
library(data.table)
library(httr)
library(stringr)
library(xml2)
library(rvest)
library(stringr)
library(progress)
library(furrr)
library(future)
library(tidyverse)
library(remotes)
library(kml)
library(sf)
library(xml2)
library(e1071)
library(caret)
library(ModelMetrics)
library(maps)
library(mlrMBO)
library(mlr)
library(ggcorrplot)
library(zoo) 
library(tseries)
library(forecast)
library(patchwork)
library(yardstick)
library(neuralnet)
library(ggfittext)
library(readr)
library(stringi)
```

```{r}
data <- read.csv("C:/Users/leoni/OneDrive/Dokumente/Studium/IBA/oTree/revhelp/choice_sets_round11.csv")

data_text <- data %>%
  select(ReviewID, text)

data_unique <- unique((data_text))

write.csv2(data_unique, "C:/Users/leoni/OneDrive/Dokumente/Studium/IBA/oTree/revhelp/data_unique11.csv")

data_new <- read.csv2("C:/Users/leoni/OneDrive/Dokumente/Studium/IBA/oTree/revhelp/data_unique11.csv")

# data_new$both <- paste(data_new$ReviewID, data_new$text, sep=",")
# 
# data_new <- as.data.frame(str_split_fixed(data_new$both, ",", 2))
# 
# colnames(data_new) <- c("ReviewID", "text")
# 
# data_new$text <- gsub('"', "", data_new$text)
# data_new$text <- gsub("â€™", "'", data_new$text)
# data_new$text <- gsub("â€¦", "...", data_new$text)
# data_new$text <- gsub("â€œ", "", data_new$text)
# data_new$text <- gsub("â€\u009d", "", data_new$text)
# data_new$text <- gsub("â\u009d¤ï¸\u008f", "<3", data_new$text)
# data_new$text <- gsub(",$", "", data_new$text)

data_new$text_new <- data_new$text
data_new <- data_new %>%
  select(ReviewID, text_new)

final_df <- merge(x = data, y = data_new, by = "ReviewID", all.x = TRUE)

colnames(final_df) <- c(
  "ReviewID","X","prod_pos","prod_neg","cust_pos","cust_neg","pcond_pos","pcond_neg","seller_pos","seller_neg",
  "Comparison","Alternative","labels","author","rating","text_old","n_words","text"
)

final_df <- final_df %>%
  arrange(Alternative) %>%
  arrange(Comparison)

final_df$Comparison <- rep(seq(1:816), each = 2)
final_df$Alternative <- rep(seq(1:2), 816)

write_xlsx(final_df, "C:/Users/leoni/OneDrive/Dokumente/Studium/IBA/oTree/revhelp/Reviews11.csv", col_names = TRUE, col_types = "character", encoding = "UTF-8")
```


