The goal of the project is to build a predictive model for suggesting next word given a text input. In this report we will summarise data exploration for next word prediction model. Dataset consists of corpus in English, German and finnish.We will focus on english text for this project. We will use data from https://d396qusza40orc.cloudfront.net/dsscapstone/dataset/Coursera-SwiftKey.zip. Data consists of three corpora from blogs, new and twitter sites.
setwd("C:/Users/bfahs/OneDrive/Documents/datasciencecoursera/DF-Capstone")
# Define file paths
news_file <- "final/en_US/en_US.news.txt"
twitter_file <- "final/en_US/en_US.twitter.txt"
blogs_file <- "final/en_US/en_US.blogs.txt"
# Check if files exist
if (!file.exists(news_file) || !file.exists(twitter_file) || !file.exists(blogs_file)) {
stop("One or more files not found.")
}
# Read the files
newsText <- readLines(news_file, encoding = "UTF-8", warn = FALSE)
twitterText <- readLines(twitter_file, encoding = "UTF-8", warn = FALSE)
blogsText <- readLines(blogs_file, encoding = "UTF-8", warn = FALSE)
Lets check the no of lines, words and size of all three texts:
sizeTwitter <- file.info("en_US.twitter.txt")$size / 1024
sizeNews <- file.info("en_US.news.txt")$size / 1024
sizeblogs <- file.info("en_US.blogs.txt")$size / 1024
wordsTwitter <- stri_count_words(twitterText)
wordsNews <- stri_count_words(newsText)
wordsbolg <- stri_count_words(blogsText)
data.frame(Source = c("Twitter", "News", "Blogs"),
SizeMB = c(sizeTwitter, sizeNews, sizeblogs),
NoofLines = c(length(twitterText),length(newsText), length(blogsText)),
NoOfWords = c(sum(wordsTwitter),sum(wordsNews),sum(wordsbolg)))
## Source SizeMB NoofLines NoOfWords ## 1 Twitter NA 2360148 30093372 ## 2 News NA 77259 2674536 ## 3 Blogs NA 899288 37546250