<commit_before>;
; self-model.scm
;
; Model of Eva's current physical state, represented in the Atomspace.
;
; This attempts to maintain a model, in the atomspace, of what the robot
; is actually doing, from moment to moment.  This model is important for
; multiple reasons:
;
; -- It is needed for Action Orchestration, to make sure that multiple
;    conflicting command sources do not cause the robot to do incoherent
;    things (such as smile and frown at the same time, or move lips
;    without talking, etc.)
;
; -- It is needed for self-awareness, so that the chatbot can respond to
;    questions about what Eva is doing.
;
; Example usage:
; Load the needed modules.
; (use-modules (opencog) (opencog query) (opencog exec))
; (use-modules (opencog atom-types) (opencog python))
; (use-modules (opencog eva-model))
;;;; start roscore before doing the load below.
; (python-eval "execfile('atomic.py')")
;
; Examples and debugging hints:
; Some (but not all) state queries:
; (cog-evaluate! (DefinedPredicate "chatbot is talking"))
; (cog-evaluate! (DefinedPredicate "chatbot is listening"))
; (cog-evaluate! (DefinedPredicate "chatbot is happy"))
; (cog-evaluate! (DefinedPredicateNode "Did someone arrive?"))
; (cog-evaluate! (DefinedPredicateNode "Someone visible"))
; (cog-execute! (DefinedSchemaNode "Num visible faces"))
;
(add-to-load-path "/usr/local/share/opencog/scm")

(use-modules (opencog) (opencog query) (opencog exec))
(use-modules (opencog atom-types))

; XXX the nlp chatbot-eva does not really belong here; where does it belong?
; We need process-query, but this load-modules results in a circular
; dependency.
; (use-modules (opencog nlp chatbot-eva)) ; Needed for process-query


; ------------------------------------------------------
; State variables
; XXX FIXME There are a bunch of define-publics in here, they probably
; should not be; they're needed only by the behavior module.

; Soma: awake, agitated, excited, tired, manic, depressed
(define-public soma-state (AnchorNode "Soma State"))
(define-public soma-sleeping (ConceptNode "Sleeping"))
(define-public soma-awake (ConceptNode "Awake"))
(define-public soma-bored (ConceptNode "Bored"))

;; Assume Eva is sleeping at first
(StateLink soma-state soma-sleeping)

;; True if sleeping, else false.
(DefineLink
	(DefinedPredicate "Is sleeping?")
	(Equal (SetLink soma-sleeping)
		(Get (State soma-state (Variable "$x")))))

;; True if bored, else false
(DefineLink
	(DefinedPredicate "Is bored?")
	(Equal (SetLink soma-bored)
		(Get (State soma-state (Variable "$x")))))

; -----------
; The "emotional state" of the robot.  Corresponds to states declared
; in the `cfg-*.scm` file.
(define-public emotion-state (AnchorNode "Emotion State"))
(define-public emotion-neutral (ConceptNode "neutral"))

(StateLink emotion-state emotion-neutral)

; -----------
;; The eye-contact-state will be linked to the face-id of
;; person with whom we are making eye-contact with.
;; This is usually the same as the interaction-state, but not always:
;; If told to look away, she will break eye-contact but not break
;; interaction.
(define-public eye-contact-state (AnchorNode "Eye Contact State"))
(define-public no-interaction (ConceptNode "none"))

(StateLink eye-contact-state no-interaction)

; The face to glance at.
(define-public glance-state (AnchorNode "Glance State"))
(StateLink glance-state no-interaction)

;; Linked to face-id that needs immediate interaction.
;; Currently it is set from ROS
(define request-eye-contact-state (AnchorNode "Request Interaction"))
(StateLink request-eye-contact-state no-interaction)

;; The "look at neutral position" face. Used to tell the eye/head
;; movement subsystem to move to a neutral position.
(define neutral-face (ConceptNode "0"))

;; The person she is interacting with.
;; Not the same as eye-contact state, because she may have been
;; told to look the other way (i.e. break off eye contact)
(define-public interaction-state (AnchorNode "Interaction State"))
(StateLink interaction-state no-interaction)

; --------------------------------------------------------
; Chatbot-related stuff.  In the current design, the chatbot talks
; whenever it feels like it; we are simply told when it is talking
; when it has stopped talking, and what emotions we should display,
; so that it's consistent with the speech emotions.

; Chat state. Is the robot talking (vocalizing), or not, right now?
; NB the python code in put_atoms.py uses these defines!
; This is a state-machine, valid transitions are:
; listening -> started talking
; started talking -> talking
; talking -> stoped talking
; stopped talking -> listening.
(define-public chat-state (AnchorNode "Chat State"))
(define-public chat-listen (ConceptNode "Listening"))
(define-public chat-start  (ConceptNode "Start Talking"))
(define-public chat-talk   (ConceptNode "Talking"))
(define-public chat-stop   (ConceptNode "Stop Talking"))
(StateLink chat-state chat-stop)

(DefineLink
	(DefinedPredicate "chatbot started talking")
	(Equal (Set chat-start)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot is talking")
	(Equal (Set chat-talk)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot stopped talking")
	(Equal (Set chat-stop)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot is listening")
	(Equal (Set chat-listen)
		(Get (State chat-state (Variable "$x")))))

; Chat affect. Is the robot happy about what its saying?
; Right now, there are only two affects: happy and not happy.
; NB the python code uses these defines!
; XXX FIXME: Note also: we currently fail to distinguish the affect
; that was perceived, from our own state. There is a ROS message that
; informs us about what the perceived affect was: it sets this state.
;
(define chat-affect (AnchorNode "Chat Affect"))
(define chat-happy (ConceptNode "Happy"))
(define chat-negative (ConceptNode "Negative"))
(StateLink chat-affect chat-happy)<commit_msg>Fix for bug #35<commit_after>;
; self-model.scm
;
; Model of Eva's current physical state, represented in the Atomspace.
;
; This attempts to maintain a model, in the atomspace, of what the robot
; is actually doing, from moment to moment.  This model is important for
; multiple reasons:
;
; -- It is needed for Action Orchestration, to make sure that multiple
;    conflicting command sources do not cause the robot to do incoherent
;    things (such as smile and frown at the same time, or move lips
;    without talking, etc.)
;
; -- It is needed for self-awareness, so that the chatbot can respond to
;    questions about what Eva is doing.
;
; Example usage:
; Load the needed modules.
; (use-modules (opencog) (opencog query) (opencog exec))
; (use-modules (opencog atom-types) (opencog python))
; (use-modules (opencog eva-model))
;;;; start roscore before doing the load below.
; (python-eval "execfile('atomic.py')")
;
; Examples and debugging hints:
; Some (but not all) state queries:
; (cog-evaluate! (DefinedPredicate "chatbot is talking"))
; (cog-evaluate! (DefinedPredicate "chatbot is listening"))
; (cog-evaluate! (DefinedPredicate "chatbot is happy"))
; (cog-evaluate! (DefinedPredicateNode "Did someone arrive?"))
; (cog-evaluate! (DefinedPredicateNode "Someone visible"))
; (cog-execute! (DefinedSchemaNode "Num visible faces"))
;
(add-to-load-path "/usr/local/share/opencog/scm")

(use-modules (opencog) (opencog query) (opencog exec))
(use-modules (opencog atom-types))

; XXX the nlp chatbot-eva does not really belong here; where does it belong?
; We need process-query, but this load-modules results in a circular
; dependency.
; (use-modules (opencog nlp chatbot-eva)) ; Needed for process-query


; ------------------------------------------------------
; State variables
; XXX FIXME There are a bunch of define-publics in here, they probably
; should not be; they're needed only by the behavior module.

; Soma: awake, agitated, excited, tired, manic, depressed
(define-public soma-state (AnchorNode "Soma State"))
(define-public soma-sleeping (ConceptNode "Sleeping"))
(define-public soma-awake (ConceptNode "Awake"))
(define-public soma-bored (ConceptNode "Bored"))

;; Assume Eva is sleeping at first
(StateLink soma-state soma-sleeping)

;; True if sleeping, else false.
(DefineLink
	(DefinedPredicate "Is sleeping?")
	(Equal (SetLink soma-sleeping)
		(Get (State soma-state (Variable "$x")))))

;; True if bored, else false
(DefineLink
	(DefinedPredicate "Is bored?")
	(Equal (SetLink soma-bored)
		(Get (State soma-state (Variable "$x")))))

; -----------
; The "emotional state" of the robot.  Corresponds to states declared
; in the `cfg-*.scm` file.
(define-public emotion-state (AnchorNode "Emotion State"))
(define-public emotion-neutral (ConceptNode "neutral"))

(StateLink emotion-state emotion-neutral)

; -----------
;; The eye-contact-state will be linked to the face-id of
;; person with whom we are making eye-contact with.
;; This is usually the same as the interaction-state, but not always:
;; If told to look away, she will break eye-contact but not break
;; interaction.
(define-public eye-contact-state (AnchorNode "Eye Contact State"))
(define-public no-interaction (ConceptNode "none"))

(StateLink eye-contact-state no-interaction)

; The face to glance at.
(define-public glance-state (AnchorNode "Glance State"))
(StateLink glance-state no-interaction)

;; Linked to face-id that needs immediate interaction.
;; Currently it is set from ROS
(define request-eye-contact-state (AnchorNode "Request Interaction"))
(StateLink request-eye-contact-state no-interaction)

;; The "look at neutral position" face. Used to tell the eye/head
;; movement subsystem to move to a neutral position.
(define neutral-face (ConceptNode "0"))

;; The person she is interacting with.
;; Not the same as eye-contact state, because she may have been
;; told to look the other way (i.e. break off eye contact)
(define-public interaction-state (AnchorNode "Interaction State"))
(StateLink interaction-state no-interaction)

; --------------------------------------------------------
; Chatbot-related stuff.  In the current design, the chatbot talks
; whenever it feels like it; we are simply told when it is talking
; when it has stopped talking, and what emotions we should display,
; so that it's consistent with the speech emotions.

; Chat state. Is the robot talking (vocalizing), or not, right now?
; NB the python code in put_atoms.py uses these defines!
; This is a state-machine, valid transitions are:
; listening -> started talking
; started talking -> talking
; talking -> stoped talking
; stopped talking -> listening.
(define-public chat-state (AnchorNode "Chat State"))
(define-public chat-listen (ConceptNode "Listening"))
(define-public chat-start  (ConceptNode "Start Talking"))
(define-public chat-talk   (ConceptNode "Talking"))
(define-public chat-stop   (ConceptNode "Stop Talking"))
(StateLink chat-state chat-stop)

(DefineLink
	(DefinedPredicate "chatbot started talking")
	(Equal (Set chat-start)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot is talking")
	(Equal (Set chat-talk)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot stopped talking")
	(Equal (Set chat-stop)
		(Get (State chat-state (Variable "$x")))))

(DefineLink
	(DefinedPredicate "chatbot is listening")
	(Equal (Set chat-listen)
		(Get (State chat-state (Variable "$x")))))

; Chat affect. Is the robot happy about what its saying?
; Right now, there are only two affects: happy and not happy.
; NB the python code uses these defines!
; XXX FIXME: Note also: we currently fail to distinguish the affect
; that was perceived, from our own state. There is a ROS message that
; informs us about what the perceived affect was: it sets this state.
;
(define-public chat-affect (AnchorNode "Chat Affect"))
(define-public chat-happy (ConceptNode "Happy"))
(define-public chat-negative (ConceptNode "Negative"))
(StateLink chat-affect chat-happy)
{'fraction_non_alphanumeric': 0.13275876357006713, 'fraction_numerical': 0.00033148255573050466, 'mean_word_length': 4.2310359774599045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7366621', 'n_tokens_mistral': 3610, 'n_tokens_neox': 3513, 'n_words': 1416}