|
|
|
|
|
|
|
|
math.randomseed(os.time()) |
|
|
|
|
|
|
|
|
local memory = {} |
|
|
|
|
|
|
|
|
local knowledge = { |
|
|
greetings = {"Hello!", "Hi there!", "Hey!", "Greetings!"}, |
|
|
farewell = {"Goodbye!", "See you later!", "Take care!"}, |
|
|
weather = {"It looks sunny today!", "Might rain later, take an umbrella!"}, |
|
|
technology = {"AI is fascinating!", "Technology evolves rapidly!"}, |
|
|
activities = {"What do you like to do for fun?", "I enjoy chatting with you!"} |
|
|
} |
|
|
|
|
|
|
|
|
local function get_response(category) |
|
|
if knowledge[category] then |
|
|
return knowledge[category][math.random(#knowledge[category])] |
|
|
else |
|
|
return "I am not sure about that." |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function update_memory(input) |
|
|
for word in string.gmatch(input, "[%w']+") do |
|
|
memory[word] = (memory[word] or 0) + 1 |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
local function match_category(input) |
|
|
for category, phrases in pairs(knowledge) do |
|
|
for _, phrase in ipairs(phrases) do |
|
|
if string.find(string.lower(input), string.lower(phrase)) then |
|
|
return category |
|
|
end |
|
|
end |
|
|
end |
|
|
return nil |
|
|
end |
|
|
|
|
|
|
|
|
while true do |
|
|
io.write("You: ") |
|
|
local input = io.read() |
|
|
if input:lower() == "exit" then break end |
|
|
|
|
|
update_memory(input) |
|
|
local category = match_category(input) |
|
|
local response = category and get_response(category) or "I am still learning!" |
|
|
|
|
|
print("Voltage: " .. response) |
|
|
end |
|
|
|