New to Elixir, I built three functions that give me the number of times one of a list of special words occurs in each car dealership review scraped from the internet. Scraped responses look like this before applying the functions:
[
{"July 03, 2021",
"We had been looking for a 2021 Suburban for about 6 months and no one could find exactly what we wanted! We contacted Adrian at McKaig and he told us he could order one for us! Our Suburban was delivered in 4 weeks and had everything on it that we wanted! Adrian, Brandon, Dennis and Freddie all worked with us to get exactly what we wanted! They made phone calls and deals for us right on the spot and we drove out with a beautiful black Suburban! We will definitely use Adrian and McKaig Chevrolet again! Thank you for a fun car buying experience!"},
{"July 03, 2021",
"Adrian first educated me on trade ins. And Joe helped me have a car with a better fit and one I can feel good about! "},
{"July 03, 2021",
"Adrian was able to finally help my fiance get the truck he needed for quite some time now! We left Mckaig extremely happy and grateful! As always customer service was amazing especially Adrian’s and Joe’s!"},... ]
The number of occurrences only looks at the second element (the review text itself) and is saved in key titled score
. I’m trying to keep the date included to act as an ID. but can’t figure out how to include ID in the comprehension without screwing it up.
Here is the code and current result as well as desired result:
def list_conv() do
input = get_body()
new_input = Enum.map(input, fn n -> elem(n,1) end)
for n <- new_input do
String.downcase(n)
|> String.split(" ", trim: true)
end
end
def special_words() do
special_words = ["extremely", "definitely","amazing","very","best","great","excellent","awesome","incredibly","beyond","loved","really","highly"]
input = list_conv()
for i <- input do
{Enum.count(i, &(&1 in special_words)), i}
end
def spec_map() do
nl = special_words()
for {score, x} <- nl do
%{score: score,
}
end
end
Result:
[
%{score: 0},
%{score: 1},
%{score: 0}, ...]
Desired Result:
[
%{score: 0, id: "July 10, 2021"},
%{score: 1,id: "July 03, 2021"},
%{score: 0, id: "July 03, 2021"}... ]
Thank you!