-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
74 lines (56 loc) · 1.9 KB
/
server.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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(data.table)
#Load datasets
load(file = "bigrams_dt")
load(file = "trigrams_dt")
load(file = "quadgrams_dt")
load(file = "pentagrams_dt")
#Set keys and order for performance
setkey(bigrams_dt, word1, word2, Frequency)
setorder(bigrams_dt)
setkey(trigrams_dt, word1, word2, word3, Frequency)
setorder(trigrams_dt)
setkey(quadgrams_dt, word1, word2, word3, word4, Frequency)
setorder(quadgrams_dt)
setkey(pentagrams_dt, word1, word2, word3, word4, word5, Frequency)
setorder(pentagrams_dt)
#Load list of swearwords
sw_con <- file("mxm_profanity_list.txt")
swearwords <- readLines(sw_con)
close(sw_con)
#Source prediction function
source("prediction.R", local = TRUE)
# Shiny server logic to predict next words
shinyServer(function(input, output) {
output$words <- renderTable({
input_string <- input$input_string
alpha <- input$alpha
num_results <- input$num_results
verbose <- input$verbose
verbosity_level <- input$verbosity_level
swearwords <- input$swearwords
remove_stopwords <- input$stopwords
showScores <- input$showScores
#########################################
Predictions <- predict_word(input_string,
num_results = num_results,
remove_stopwords = remove_stopwords,
remove_swearwords = swearwords,
alpha = alpha)
if(input_string == ""){
Predictions <- c("I predict that you will enter some text", "0")
names(Predictions) <- c("Predictions", "Score")
}
if(!showScores)
Predictions$Score <- NULL
print(as.data.frame(Predictions))
})
})