Lux.Prisms.SentimentAnalysisPrism (Lux v0.5.0)

View Source

A prism that performs sentiment analysis on text using Python's NLTK library.

This prism uses NLTK's VADER (Valence Aware Dictionary and sEntiment Reasoner) sentiment analyzer, which is specifically attuned to sentiments expressed in social media. It's able to handle:

  • Conventional text
  • Slang and abbreviations
  • Emojis and emoticons
  • Emphasis through capitalization and punctuation

Examples

iex> Lux.Prisms.SentimentAnalysisPrism.run(%{
...>   text: "Great product, I love it!",
...>   language: "en"
...> })
{:ok, %{
  sentiment: "positive",
  confidence: 0.8402,
  details: %{
    "pos" => 0.814,
    "neg" => 0.0,
    "neu" => 0.186,
    "compound" => 0.8402
  }
}}

Summary

Functions

Analyzes the sentiment of the given text.

Returns the Prism struct for this module.

Functions

handler(input, ctx)

Analyzes the sentiment of the given text.

Parameters

  • text - The text to analyze
  • language - The language of the text (currently only "en" is supported)

Returns

  • {:ok, result} - Where result contains sentiment analysis
  • {:error, reason} - If analysis fails

run(input, context \\ nil)

view()

Returns the Prism struct for this module.