Skip to content

Commit

Permalink
bug fix for case when blank element passed to sentence parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Spannbauer, Adam M committed Dec 11, 2017
1 parent 6fae0c5 commit 1c964a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions R/sentenceParse.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ sentenceParse <- function(text, docId = "create") {
} else if(length(docId)==length(text)) {
createDocIds <- FALSE
} else if(length(docId)!=length(text)) stop("docId vector must be same length as text vector")



sentences <- sentence_parser(text)
sentenceDfList <- lapply(seq_along(sentences), function(i) {
sentVec <- trimws(sentences[[i]])
if (length(sentVec) == 0) sentVec = ""
if(createDocIds) {
data.frame(docId=i, sentenceId=paste0(i,"_",seq_along(sentVec)), sentence=sentVec, stringsAsFactors = FALSE)
out = data.frame(docId=i, sentenceId=paste0(i,"_",seq_along(sentVec)), sentence=sentVec, stringsAsFactors = FALSE)
} else if(!createDocIds) {
data.frame(docId=docId[i], sentence=sentVec, stringsAsFactors = FALSE)
out = data.frame(docId=docId[i], sentence=sentVec, stringsAsFactors = FALSE)
}

out
})
sentenceDf <- do.call('rbind', sentenceDfList)
sentenceDfList <- split(sentenceDf, sentenceDf$docId)
Expand Down

0 comments on commit 1c964a1

Please sign in to comment.