-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prediction.R
32 lines (24 loc) · 958 Bytes
/
Prediction.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
require(RTextTools)
require(sqldf)
fetch_sim<-function(tag)
{
tag<-toString(tag)
titles<-paste0("SELECT title FROM training_data_set where tag1='",tag,"' FETCH FIRST 5 ROWS ONLY")
result<-sqldf(titles,dbname='training_data',user="CASH",password="1992")
return(result)
}
prediction <- function(Title, Body){
tryCatch({
documents <- Body
documents <- Corpus(VectorSource(documents))
documents = tm_map(documents, content_transformer(tolower))
documents = tm_map(documents, removeWords, stopwords("english"))
predSize = 1
predMatrix <- create_matrix(documents[[1]]$content, originalMatrix=dtMatrix)
predictionContainer <- create_container(predMatrix, labels=rep(0,predSize), testSize=1:predSize, virgin=FALSE)
result <- classify_model(predictionContainer, model)
return(as.numeric(as.character(result$SVM_LABEL)))
}, error = function(e) {
return("Body is too short to predict a tag")
})
}