Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Created November 15, 2014 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simkimsia/9ace6002cc758d5a303a to your computer and use it in GitHub Desktop.
Save simkimsia/9ace6002cc758d5a303a to your computer and use it in GitHub Desktop.
sent_detect function using Maxent_Sent_Token_Annotator
sent_detect <- function(text, language) {
# Function to compute sentence annotations using the Apache OpenNLP Maxent sentence detector employing the default model for language 'en'.
sentence_token_annotator <- Maxent_Sent_Token_Annotator(language)
# Convert text to class String from package NLP
text <- as.String(text)
# Sentence boundaries in text
sentence.boundaries <- annotate(text, sentence_token_annotator)
# Extract sentences
sentences <- text[sentence.boundaries]
# return sentences
return(sentences)
}
tiny <- sent_detect("hi i am Apple", language = "en")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment