YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeChatBotDevice.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "FakeChatBotDevice.h"
7#include <yarp/os/Log.h>
8#include <yarp/os/LogStream.h>
9
10YARP_LOG_COMPONENT(FAKECHATBOTDEVICE, "yarp.devices.FakeChatBotDevice")
11
12using namespace yarp::dev;
13
15 m_fallback{"Sorry, I did not get that. Can you repeat?"},
16 m_noInput{"I heard nothing. Can you please speak up?"},
17 m_status{"greetings"},
18 m_qAndA{
19 {"greetings",
20 {{"Hello!","Hello there."},{"Who are you?","I am just a fake chatbot"},
21 {"Goodbye!", "Already? Ok... bye."}}
22 },
23 {"chatting",
24 {{"Hello!","Hello again."},{"Who are you?","I am just a fake chatbot"},
25 {"Goodbye!", "Bye bye!"}}
26 }
27 }
28{}
29
30ReturnValue FakeChatBotDevice::interact(const std::string& messageIn, std::string& messageOut)
31{
32 if(messageIn.empty())
33 {
34 messageOut = m_noInput;
35 return ReturnValue_ok;
36 }
37 if(m_qAndA[m_status].count(messageIn) < 1)
38 {
39 messageOut = m_fallback;
40 return ReturnValue_ok;
41 }
42
43 messageOut = m_qAndA[m_status][messageIn];
44
45 if(m_status == std::string("greetings"))
46 {
47 m_status = "chatting";
48 }
49
50 return ReturnValue_ok;
51}
52
53ReturnValue FakeChatBotDevice::setLanguage(const std::string& language)
54{
55 if (language != "eng")
56 {
57 yCError(FAKECHATBOTDEVICE) << "Unsupported language. Only English is supported for the moment being";
58 return ReturnValue::return_code::return_value_error_method_failed;
59 }
60 m_language = language;
61
62 return ReturnValue_ok;
63}
64
66{
67 language = m_language;
68 return ReturnValue_ok;
69}
70
72{
73 status = m_status;
74 return ReturnValue_ok;
75}
76
78{
79 m_status = "greetings";
80 return ReturnValue_ok;
81}
82
84{
85 if (!this->parseParams(config)) {return false;}
86 return true;
87}
88
90{
91 return true;
92}
const yarp::os::LogComponent & FAKECHATBOTDEVICE()
#define ReturnValue_ok
Definition ReturnValue.h:77
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
fakeChatBotDevice : a fake device which implements the IChatBot interface for testing purposes.
yarp::dev::ReturnValue getStatus(std::string &status) override
Gets the current status of the bot.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current chatbot language.
yarp::dev::ReturnValue interact(const std::string &messageIn, std::string &messageOut) override
Sends a message to the chatbot.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue setLanguage(const std::string &language) override
Sets the chat bot language.
yarp::dev::ReturnValue resetBot() override
Resets the chatbot.
A base class for nested structures that can be searched.
Definition Searchable.h:31
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
The main, catch-all namespace for YARP.
Definition dirs.h:16