<commit_before>/*
 * @file opencog/dynamics/openpsi/PsiDemandUpdaterAgent.h
 *
 * @author <NAME> <<EMAIL>>
 * @date   2011-11-22
 *
 * 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.
 */

#ifndef PSIDEMANDUPDATERAGENT_H
#define PSIDEMANDUPDATERAGENT_H

#include <opencog/server/Agent.h>
#include <opencog/atomspace/AtomSpace.h>

class PsiDemandUpdaterAgentUTest;

namespace opencog {

/**
 * @class
 *
 * @brief Agent of updating Demands
 *
 * Updates the demands (for example, how hungry the agent is)
 *
 * The format of DemandSchema in AtomSpace is
 *
 * AtTimeLink
 *     TimeNode "timestamp"
 *     SimilarityLink (stv 1.0 1.0)
 *         NumberNode: "demand_value"
 *         ExecutionOutputLink
 *             GroundedSchemaNode: xxxDemandUpdater
 *             ListLink (empty)
 *
 * The connection of Demand and Goal is represented as:
 *
 * SimultaneousEquivalenceLink
 *     EvaluationLink
 *         (SimpleTruthValue indicates how well the demand is satisfied)
 *         (ShortTermInportance indicates the urgency of the demand)
 *         PredicateNode: "demand_name_goal"
 *         ListLink (empty)
 *     EvaluationLink
 *         GroundedPredicateNode: "fuzzy_within"
 *         ListLink
 *             NumberNode: "min_acceptable_value"
 *             NumberNode: "max_acceptable_value"
 *             ExecutionOutputLink
 *                 GroundedSchemaNode: "demand_schema_name"
 *                 ListLink (empty)
 *
*/
class PsiDemandUpdaterAgent : public opencog::Agent
{
    friend class::PsiDemandUpdaterAgentUTest;

private:

    /**
     * Inner class for Demand
     */
    class Demand
    {
    public:

        Demand(const std::string & demandName, Handle hDemandGoal, Handle hFuzzyWithin) :
            demandName(demandName), hDemandGoal(hDemandGoal), hFuzzyWithin(hFuzzyWithin)
        {};

        inline const std::string & getDemandName() const
        {
            return this->demandName;
        }

        inline double getDemandValue() const
        {
            return this->currentDemandValue;
        }

        inline double getDemandTruthValue() const
        {
            return this->currentDemandTruthValue;
        }

        inline Handle getHandleDemandGoal() const
        {
            return this->hDemandGoal;
        }

        inline Handle getHandleFuzzyWithin() const
        {
            return this->hFuzzyWithin;
        }

        /**
         * Update the Demand Value
         *
         * @return return true if update successfully, otherwise false
         */
        bool runUpdater(AtomSpace & atomSpace);

        /**
         * Update the truth value of Demand Goal
         *
         * @return return true if update successfully, otherwise false
         *
         * TODO: Only current (latest) demand value is considered, also take previous demand values in future
         *
         * @note This function does three jobs as follows:
         *
         *       1. Create a new NumberNode and SimilarityLink to store the result,
         *          and then time stamp the SimilarityLink.
         *
         *          Since OpenCog would forget (remove) those Nodes and Links gradually,
         *          unless you create them to be permanent, don't worry about the overflow of memory.
         *
         *          AtTimeLink
         *              TimeNode "timestamp"
         *              SimilarityLink (stv 1.0 1.0)
         *                  NumberNode: "demand_value"
         *                  ExecutionOutputLink
         *                      GroundedSchemaNode: xxxDemandUpdater
         *                      ListLink (empty)
         *
         *       2. Run the procedure named "FuzzyWithin", and then set the result to the truth value of
         *         both EvaluationLink of Demand Goal and FuzzyWithin
         *
         *       3. Update corresponding LatestLink
         *
         *          LatestLink
         *              AtTimeLink
         *                  TimeNode "latestTimestamp"
         *                  EvaluationLink (stv denotes the satisfaction level of the demand)
         *                      PredicateNode "xxxDemand"
         */
        bool updateDemandGoal(AtomSpace & atomSpace, const unsigned long timeStamp);

    private:

        std::string demandName; // The name of the Demand<commit_msg>change paramater type to avoid implicit casting<commit_after>/*
 * @file opencog/dynamics/openpsi/PsiDemandUpdaterAgent.h
 *
 * @author <NAME> <<EMAIL>>
 * @date   2011-11-22
 *
 * 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.
 */

#ifndef PSIDEMANDUPDATERAGENT_H
#define PSIDEMANDUPDATERAGENT_H

#include <opencog/server/Agent.h>
#include <opencog/atomspace/AtomSpace.h>

class PsiDemandUpdaterAgentUTest;

namespace opencog {

/**
 * @class
 *
 * @brief Agent of updating Demands
 *
 * Updates the demands (for example, how hungry the agent is)
 *
 * The format of DemandSchema in AtomSpace is
 *
 * AtTimeLink
 *     TimeNode "timestamp"
 *     SimilarityLink (stv 1.0 1.0)
 *         NumberNode: "demand_value"
 *         ExecutionOutputLink
 *             GroundedSchemaNode: xxxDemandUpdater
 *             ListLink (empty)
 *
 * The connection of Demand and Goal is represented as:
 *
 * SimultaneousEquivalenceLink
 *     EvaluationLink
 *         (SimpleTruthValue indicates how well the demand is satisfied)
 *         (ShortTermInportance indicates the urgency of the demand)
 *         PredicateNode: "demand_name_goal"
 *         ListLink (empty)
 *     EvaluationLink
 *         GroundedPredicateNode: "fuzzy_within"
 *         ListLink
 *             NumberNode: "min_acceptable_value"
 *             NumberNode: "max_acceptable_value"
 *             ExecutionOutputLink
 *                 GroundedSchemaNode: "demand_schema_name"
 *                 ListLink (empty)
 *
*/
class PsiDemandUpdaterAgent : public opencog::Agent
{
    friend class::PsiDemandUpdaterAgentUTest;

private:

    /**
     * Inner class for Demand
     */
    class Demand
    {
    public:

        Demand(const std::string & demandName, Handle hDemandGoal, Handle hFuzzyWithin) :
            demandName(demandName), hDemandGoal(hDemandGoal), hFuzzyWithin(hFuzzyWithin)
        {};

        inline const std::string & getDemandName() const
        {
            return this->demandName;
        }

        inline double getDemandValue() const
        {
            return this->currentDemandValue;
        }

        inline double getDemandTruthValue() const
        {
            return this->currentDemandTruthValue;
        }

        inline Handle getHandleDemandGoal() const
        {
            return this->hDemandGoal;
        }

        inline Handle getHandleFuzzyWithin() const
        {
            return this->hFuzzyWithin;
        }

        /**
         * Update the Demand Value
         *
         * @return return true if update successfully, otherwise false
         */
        bool runUpdater(AtomSpace & atomSpace);

        /**
         * Update the truth value of Demand Goal
         *
         * @return return true if update successfully, otherwise false
         *
         * TODO: Only current (latest) demand value is considered, also take previous demand values in future
         *
         * @note This function does three jobs as follows:
         *
         *       1. Create a new NumberNode and SimilarityLink to store the result,
         *          and then time stamp the SimilarityLink.
         *
         *          Since OpenCog would forget (remove) those Nodes and Links gradually,
         *          unless you create them to be permanent, don't worry about the overflow of memory.
         *
         *          AtTimeLink
         *              TimeNode "timestamp"
         *              SimilarityLink (stv 1.0 1.0)
         *                  NumberNode: "demand_value"
         *                  ExecutionOutputLink
         *                      GroundedSchemaNode: xxxDemandUpdater
         *                      ListLink (empty)
         *
         *       2. Run the procedure named "FuzzyWithin", and then set the result to the truth value of
         *         both EvaluationLink of Demand Goal and FuzzyWithin
         *
         *       3. Update corresponding LatestLink
         *
         *          LatestLink
         *              AtTimeLink
         *                  TimeNode "latestTimestamp"
         *                  EvaluationLink (stv denotes the satisfaction level of the demand)
         *                      PredicateNode "xxxDemand"
         */
        bool updateDemandGoal(AtomSpace & atomSpace, const octime_t timeStamp);

    private:

        std::string demandName; // The name of the Demand
{'fraction_non_alphanumeric': 0.06625012397104037, 'fraction_numerical': 0.006148963602102549, 'mean_word_length': 1.9693757361601885, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '2133768', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2607, 'n_words': 860}