<commit_before>/*
 * opencog/embodiment/Control/OperationalAvatarController/LearningAgentModeHandler.cc
 *
 * Copyright (C) 2002-2009 Novamente LLC
 * All Rights Reserved
 * Author(s): <NAME>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "LearningAgentModeHandler.h"
#include <opencog/util/Logger.h>
#include "Pet.h"

#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>

using namespace OperationalAvatarController;

LearningAgentModeHandler::LearningAgentModeHandler( Pet* agent ) :
    BaseAgentModeHandler( agent ), modeName( "LEARNING_MODE" ), agent(agent)
{
}

void LearningAgentModeHandler::handleCommand( const std::string& name, const std::vector<std::string>& arguments )
{
    BaseAgentModeHandler::handleCommand( name, arguments );

    if ( name == "instruction" ) {
        if ( arguments.size( ) != 3 ) {
            logger().debug("LearningAgentModeHandler::%s - Invalid instruction. %d arguments", __FUNCTION__, arguments.size() );
            return;
        } // if
        std::vector<std::string> tokens;
        boost::split( tokens, arguments[0], boost::is_any_of(" ") );
        unsigned long timestamp = boost::lexical_cast<unsigned long>( arguments[1] );

        if ( tokens.size( ) == 3 && tokens[1] == "WILL" ) {            
            std::string exemplarAvatarId = tokens[0];
            if ( exemplarAvatarId == "I" ) {
                exemplarAvatarId = this->agent->getOwnerId( );
            } else {
                exemplarAvatarId = AtomSpaceUtil::getObjIdFromName( this->agent->getAtomSpace( ), exemplarAvatarId );
                if ( exemplarAvatarId.empty( ) ) {
                    logger().debug("LearningAgentModeHandler::%s - found no avatar with name %s", __FUNCTION__, tokens[0].c_str());
                    return;
                } // if
            } // else
            std::vector<std::string> commandStatement;
            commandStatement.push_back( tokens[2] );
            this->agent->startExemplar( commandStatement, timestamp );
            return;
<commit_msg>Make the learningAgentModeHandler less annoying<commit_after>/*
 * opencog/embodiment/Control/OperationalAvatarController/LearningAgentModeHandler.cc
 *
 * Copyright (C) 2002-2009 Novamente LLC
 * All Rights Reserved
 * Author(s): <NAME>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "LearningAgentModeHandler.h"
#include <opencog/util/Logger.h>
#include "Pet.h"

#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>

using namespace OperationalAvatarController;

LearningAgentModeHandler::LearningAgentModeHandler( Pet* agent ) :
    BaseAgentModeHandler( agent ), modeName( "LEARNING_MODE" ), agent(agent)
{
}

void LearningAgentModeHandler::handleCommand( const std::string& name, const std::vector<std::string>& arguments )
{
    BaseAgentModeHandler::handleCommand( name, arguments );

    if ( name == "instruction" ) {
        if ( arguments.size( ) != 3 ) {
            logger().debug("LearningAgentModeHandler::%s - Invalid instruction. %d arguments", __FUNCTION__, arguments.size() );
            return;
        } // if
        std::vector<std::string> tokens;
        boost::split( tokens, arguments[0], boost::is_any_of(" ") );
        unsigned long timestamp = boost::lexical_cast<unsigned long>( arguments[1] );

        if ( tokens.size( ) == 3 && (tokens[1] == "WILL" || tokens[1] == "DO" || tokens[1] == "DOES")) {
            std::string exemplarAvatarId = tokens[0];
            if ( exemplarAvatarId == "I" ) {
                exemplarAvatarId = this->agent->getOwnerId( );
            } else {
                exemplarAvatarId = AtomSpaceUtil::getObjIdFromName( this->agent->getAtomSpace( ), exemplarAvatarId );
                if ( exemplarAvatarId.empty( ) ) {
                    logger().debug("LearningAgentModeHandler::%s - found no avatar with name %s", __FUNCTION__, tokens[0].c_str());
                    return;
                } // if
            } // else
            std::vector<std::string> commandStatement;
            commandStatement.push_back( tokens[2] );
            this->agent->startExemplar( commandStatement, timestamp );
            return;

{'fraction_non_alphanumeric': 0.11392632524707996, 'fraction_numerical': 0.010422282120395327, 'mean_word_length': 3.122962962962963, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6892886', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1497, 'n_words': 446}