Hello, I am learning elixir and I am not managing to populate my variables at runtime … inside a loop … Why do the variables go blank again every time?
def teste do
t = String.split("sentence [sentence] <sem-s> N F S @NPHR §DENOM #3->0", " ", trim: true)
token = ""
lemma = ""
syntax = ""
role = ""
child = ""
root = ""
tags = []
attrs = []
t
|> Enum.with_index()
|> Enum.each(fn {e, i} ->
if i == 0 do
token = e
else
# Verb
if i == 1 do
lemma = e
else
# Syntax
if i == Enum.count(t) - 3 do
syntax = e
else
# Role
if i == Enum.count(t) - 2 do
role = e
else
# Dependency
if i == Enum.count(t) - 1 do
e = String.replace(e, "#", "")
e = String.replace(e, "-", "")
child = Text.mid(e, String.slice(e, 0..0), ">")
root = Text.mid(e, ">")
# ===================================================
#Last Index >> Get All Variables and Inser in Mnesia
# ===================================================
IO.puts ">> #{token} >> #{lemma} >> #{syntax} >> #{role}"
else
# Tags
if String.contains?(e, ["<", ">"]) == true do
[e | tags]
else
# Attributes
[e | attrs]
end
end
end
end
end
end
end)
end