As a first step, the required packages were loaded and the working directory was set.
#install.packages("tokenizers")
#install.packages("FSelectorRcpp")
library(NLP)
library(FSelectorRcpp)
library(tokenizers)
## Warning: package 'tokenizers' was built under R version 3.4.4
library(tm)
## Warning: package 'tm' was built under R version 3.4.3
library(SnowballC)
library(stats)
setwd("~/Google Drive/UM/Smart Services/Thesis/Thesis/Code")
Following, the Review Data was loaded into the R Studio environment.
Data <- read.csv("~/Google Drive/UM/Smart Services/Thesis/Thesis/Code/Data Cleaning/Feature Set 1/Input/Reviews.csv")
From the source data, the relevant columns “ID”, “Text” and “Score” were extracted.
Once the relevant data sections were extracted, the data cleaning process was initialized. For feature set 1, the following steps were taken.
In order to track the data cleaning process, a sample of the review text was printed before any cleaning steps.
#Prior Text State
print(head(Text,2))
## [1] "I am so angry that i made this post available via all possible sites i use when planing my trips so no one will make the mistake of booking this place I made my booking via booking com We stayed for 6 nights in this hotel from 11 to 17 July Upon arrival we were placed in a small room on the 2nd floor of the hotel It turned out that this was not the room we booked I had specially reserved the 2 level duplex room so that we would have a big windows and high ceilings The room itself was ok if you don t mind the broken window that can not be closed hello rain and a mini fridge that contained some sort of a bio weapon at least i guessed so by the smell of it I intimately asked to change the room and after explaining 2 times that i booked a duplex btw it costs the same as a simple double but got way more volume due to the high ceiling was offered a room but only the next day SO i had to check out the next day before 11 o clock in order to get the room i waned to Not the best way to begin your holiday So we had to wait till 13 00 in order to check in my new room what a wonderful waist of my time The room 023 i got was just as i wanted to peaceful internal garden view big window We were tired from waiting the room so we placed our belongings and rushed to the city In the evening it turned out that there was a constant noise in the room i guess it was made by vibrating vent tubes or something it was constant and annoying as hell AND it did not stop even at 2 am making it hard to fall asleep for me and my wife I have an audio recording that i can not attach here but if you want i can send it via e mail The next day the technician came but was not able to determine the cause of the disturbing sound so i was offered to change the room once again the hotel was fully booked and they had only 1 room left the one that was smaller but seems newer Only the park outside of the hotel was beautiful "
## [2] "No Negative No real complaints the hotel was great great location surroundings rooms amenities and service Two recommendations however firstly the staff upon check in are very confusing regarding deposit payments and the staff offer you upon checkout to refund your original payment and you can make a new one Bit confusing Secondly the on site restaurant is a bit lacking very well thought out and excellent quality food for anyone of a vegetarian or vegan background but even a wrap or toasted sandwich option would be great Aside from those minor minor things fantastic spot and will be back when i return to Amsterdam "
As a first step, punctuation was removed from the review text.
#Remove Punctuation
Clean.Text <- removePunctuation(Text)
print(head(Clean.Text,2))
## [1] "I am so angry that i made this post available via all possible sites i use when planing my trips so no one will make the mistake of booking this place I made my booking via booking com We stayed for 6 nights in this hotel from 11 to 17 July Upon arrival we were placed in a small room on the 2nd floor of the hotel It turned out that this was not the room we booked I had specially reserved the 2 level duplex room so that we would have a big windows and high ceilings The room itself was ok if you don t mind the broken window that can not be closed hello rain and a mini fridge that contained some sort of a bio weapon at least i guessed so by the smell of it I intimately asked to change the room and after explaining 2 times that i booked a duplex btw it costs the same as a simple double but got way more volume due to the high ceiling was offered a room but only the next day SO i had to check out the next day before 11 o clock in order to get the room i waned to Not the best way to begin your holiday So we had to wait till 13 00 in order to check in my new room what a wonderful waist of my time The room 023 i got was just as i wanted to peaceful internal garden view big window We were tired from waiting the room so we placed our belongings and rushed to the city In the evening it turned out that there was a constant noise in the room i guess it was made by vibrating vent tubes or something it was constant and annoying as hell AND it did not stop even at 2 am making it hard to fall asleep for me and my wife I have an audio recording that i can not attach here but if you want i can send it via e mail The next day the technician came but was not able to determine the cause of the disturbing sound so i was offered to change the room once again the hotel was fully booked and they had only 1 room left the one that was smaller but seems newer Only the park outside of the hotel was beautiful "
## [2] "No Negative No real complaints the hotel was great great location surroundings rooms amenities and service Two recommendations however firstly the staff upon check in are very confusing regarding deposit payments and the staff offer you upon checkout to refund your original payment and you can make a new one Bit confusing Secondly the on site restaurant is a bit lacking very well thought out and excellent quality food for anyone of a vegetarian or vegan background but even a wrap or toasted sandwich option would be great Aside from those minor minor things fantastic spot and will be back when i return to Amsterdam "
Following numbers and stopwords were removed and the text was converted to lower case.
#Remove Numbers
Clean.Text <- removeNumbers(Clean.Text)
#Create List of Stopwords
stop <- stopwords(kind="en")
#Remove Stopwords
Clean.Text <- removeWords(Clean.Text,stop)
#Convert to lower case
Clean.Text <- tolower(Clean.Text)
print(head(Clean.Text,2))
## [1] "i angry made post available via possible sites use planing trips one will make mistake booking place i made booking via booking com we stayed nights hotel july upon arrival placed small room nd floor hotel it turned room booked i specially reserved level duplex room big windows high ceilings the room ok don t mind broken window can closed hello rain mini fridge contained sort bio weapon least guessed smell i intimately asked change room explaining times booked duplex btw costs simple double got way volume due high ceiling offered room next day so check next day o clock order get room waned not best way begin holiday so wait till order check new room wonderful waist time the room got just wanted peaceful internal garden view big window we tired waiting room placed belongings rushed city in evening turned constant noise room guess made vibrating vent tubes something constant annoying hell and stop even making hard fall asleep wife i audio recording can attach want can send via e mail the next day technician came able determine cause disturbing sound offered change room hotel fully booked room left one smaller seems newer only park outside hotel beautiful "
## [2] "no negative no real complaints hotel great great location surroundings rooms amenities service two recommendations however firstly staff upon check confusing regarding deposit payments staff offer upon checkout refund original payment can make new one bit confusing secondly site restaurant bit lacking well thought excellent quality food anyone vegetarian vegan background even wrap toasted sandwich option great aside minor minor things fantastic spot will back return amsterdam "
In order to remove special characters such as [!“#$%&’()*+,-./:;<=>?@[]^_`{|}~.] the regular expression [[:punct:]] was used.
Clean.Text <-gsub("[[:punct:]]", "",Clean.Text)
print(head(Clean.Text,2))
## [1] "i angry made post available via possible sites use planing trips one will make mistake booking place i made booking via booking com we stayed nights hotel july upon arrival placed small room nd floor hotel it turned room booked i specially reserved level duplex room big windows high ceilings the room ok don t mind broken window can closed hello rain mini fridge contained sort bio weapon least guessed smell i intimately asked change room explaining times booked duplex btw costs simple double got way volume due high ceiling offered room next day so check next day o clock order get room waned not best way begin holiday so wait till order check new room wonderful waist time the room got just wanted peaceful internal garden view big window we tired waiting room placed belongings rushed city in evening turned constant noise room guess made vibrating vent tubes something constant annoying hell and stop even making hard fall asleep wife i audio recording can attach want can send via e mail the next day technician came able determine cause disturbing sound offered change room hotel fully booked room left one smaller seems newer only park outside hotel beautiful "
## [2] "no negative no real complaints hotel great great location surroundings rooms amenities service two recommendations however firstly staff upon check confusing regarding deposit payments staff offer upon checkout refund original payment can make new one bit confusing secondly site restaurant bit lacking well thought excellent quality food anyone vegetarian vegan background even wrap toasted sandwich option great aside minor minor things fantastic spot will back return amsterdam "
Removing text elements, created whitespace in the review text. This whitespace was removed in the following step.
#Remove Space
Clean.Text <- stripWhitespace(Clean.Text)
print(head(Clean.Text,2))
## [1] "i angry made post available via possible sites use planing trips one will make mistake booking place i made booking via booking com we stayed nights hotel july upon arrival placed small room nd floor hotel it turned room booked i specially reserved level duplex room big windows high ceilings the room ok don t mind broken window can closed hello rain mini fridge contained sort bio weapon least guessed smell i intimately asked change room explaining times booked duplex btw costs simple double got way volume due high ceiling offered room next day so check next day o clock order get room waned not best way begin holiday so wait till order check new room wonderful waist time the room got just wanted peaceful internal garden view big window we tired waiting room placed belongings rushed city in evening turned constant noise room guess made vibrating vent tubes something constant annoying hell and stop even making hard fall asleep wife i audio recording can attach want can send via e mail the next day technician came able determine cause disturbing sound offered change room hotel fully booked room left one smaller seems newer only park outside hotel beautiful "
## [2] "no negative no real complaints hotel great great location surroundings rooms amenities service two recommendations however firstly staff upon check confusing regarding deposit payments staff offer upon checkout refund original payment can make new one bit confusing secondly site restaurant bit lacking well thought excellent quality food anyone vegetarian vegan background even wrap toasted sandwich option great aside minor minor things fantastic spot will back return amsterdam "
Finally, the text elements were stemmed using a function based on Porter’s stemming algorithm, the state-of-the-art approach to document stemming.
Clean.Text <-stemDocument(Clean.Text)
print(head(Clean.Text,2))
## [1] "i angri made post avail via possibl site use plane trip one will make mistak book place i made book via book com we stay night hotel juli upon arriv place small room nd floor hotel it turn room book i special reserv level duplex room big window high ceil the room ok don t mind broken window can close hello rain mini fridg contain sort bio weapon least guess smell i intim ask chang room explain time book duplex btw cost simpl doubl got way volum due high ceil offer room next day so check next day o clock order get room wane not best way begin holiday so wait till order check new room wonder waist time the room got just want peac intern garden view big window we tire wait room place belong rush citi in even turn constant nois room guess made vibrat vent tube someth constant annoy hell and stop even make hard fall asleep wife i audio record can attach want can send via e mail the next day technician came abl determin caus disturb sound offer chang room hotel fulli book room left one smaller seem newer onli park outsid hotel beauti"
## [2] "no negat no real complaint hotel great great locat surround room amen servic two recommend howev first staff upon check confus regard deposit payment staff offer upon checkout refund origin payment can make new one bit confus second site restaur bit lack well thought excel qualiti food anyon vegetarian vegan background even wrap toast sandwich option great asid minor minor thing fantast spot will back return amsterdam"
Once preprocessed, the review text was exported as a csv.
df <- data.frame(ID,Clean.Text,Score)
write.csv(x = df,file = "Clean Data.csv")