-
-
Save bobpoekert/e3da144cf0f6ee998b00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def nlp | |
(let [props (new java.util.Properties)] | |
(.setProperty props "annotators" "tokenize,ssplit,parse,sentiment") | |
(new edu.stanford.nlp.pipeline.StanfordCoreNLP props))) | |
(defn find-sentiment | |
"Determines the sentiment of each sentence in a given glob of text. Results in a collection of integers ranging from [0-4]: where 0 is 'Very negative', 2 is 'neutral', and 4 is 'Very positive'" | |
[^String glob] | |
(let [main-sentiment 0 | |
longest 0] | |
(if (and (not (nil? glob)) (> (count glob) 0)) | |
(let [annotation (.process nlp glob)] | |
(for [sentence (.get annotation edu.stanford.nlp.ling.CoreAnnotations$SentencesAnnotation)] | |
(let [tree (.get sentence edu.stanford.nlp.sentiment.SentimentCoreAnnotations$AnnotatedTree) | |
sentiment (edu.stanford.nlp.neural.rnn.RNNCoreAnnotations/getPredictedClass tree) | |
part-text (.toString sentence)] | |
(if (> (.length part-text) longest) | |
(int sentiment))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment