I am trying to do a sentiment analysis on a fiction novel by passing each sentence to the analyze function in the external library Sentient. I am repeatedly getting the following error:
(Enum.EmptyError) empty error
(elixir) lib/enum.ex:1590: Enum.reduce/2
(elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
(sentiment) lib/sentiment.ex:23: Sentiment.analyze/1
(sentiment) lib/sentiment.ex:6: Sentiment.run/1
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/code.ex:168: Code.eval_string/3
To the best of my knowledge, I am not passing an empty string to my function. I have been using a test file that contains the following:
This is a test. This sentence is sad. This sentence is happy. The end.
This is my code:
defmodule Sentiment do
def run(file) do
file
|> fileread
|> analyze
|>IO.inspect
end
def fileread(file) do
file
|> File.stream!
|> Stream.map(&String.trim_trailing(&1))
|> Enum.map(&String.replace(&1, ~r/[-@#$%^&*()=_+|;':",<>']/, ""))
|> Stream.map(&String.split(&1,~r/[\p{P}\p{S}]+/, trim: true))
|> Enum.to_list
|> List.flatten
|> IO.inspect
end
def analyze(list) do
list
|> Enum.map(&Sentient.analyze(&1))
|> IO.inspect
end
end
I put an IO.inspect at the end of my fileread function in order to check if there was an empty entry in the list. There is not, this is the result of my fileread
function:
mix run -e 'Sentiment.run("test.txt")'
["This is a test", " This sentence is sad", " This sentence is happy",
" The end"]
So, I'm really not sure why I'm getting this error. Anyone have any suggestions?
Enum.EmptyError
is raised byEnum.map/2
and not by&Sentient.analyze(&1)
. Are you 100% positive thatlist
inanalyze/1
is the list of arrays you show in your question? - Daniel ZendejasSentient.analyze()
on each of those 4 sentences manually iniex -S mix
? Does any of them raise any error? - Dogbert