<commit_before>;
; rule.scm
; Utilities for defining and working with OpenPsi rules.
;
; Copyright (C) 2016 OpenCog Foundation
; Copyright (C) 2017 MindCloud
;
; Design Notes:
; Aliases: Rules can be given a "name", called an "alias", below.
; Certain parts of the design assume that a rule has only one name,
; but other parts of the code pass around lists of names. This can
; lead to crazy bugs, due to a lack of checking or enforcement of a
; one-name-per-rule policy.  Also -- each rule should, in principle
; have a unique name; however, the current chatbot uses the same name
; for all chat rules.

; --------------------------------------------------------------
; Used as a key for naming rules
(define psi-rule-name-predicate-node (Predicate "alias"))
; Used to declare the set of actions.
(define psi-action-node (Concept "action"))
; Used to declare the set of goals.
(define psi-goal-node (Concept "goal"))
; Key used to declare the desired-goal-value
(define dgv-key (Predicate "desired-goal-value"))

; --------------------------------------------------------------
(define (psi-set-gv! goal gv)
"
  psi-set-gv! GOAL GV

  Set the goal-value of GOAL to GV. GV is a number.
"
  (cog-set-value! goal (Predicate "value") (FloatValue gv))
)

; --------------------------------------------------------------
(define (psi-goal-value goal)
"
  psi-goal-value GOAL

  Return the present value of GOAL.
"
  (cog-value-ref (cog-value goal (Predicate "value")) 0)
)

; --------------------------------------------------------------
(define (psi-set-dgv! goal num)
"
  psi-set-dgv! GOAL NUM

  Returns GOAL after setting its desired-goal-value to NUM.
"
  (cog-set-value! goal dgv-key (FloatValue num))
)

; --------------------------------------------------------------
(define (psi-dgv goal)
"
  psi-dgv GOAL

  Returns the present desired-goal-value for GOAL. GOAL is a node
  representin the goal concerned.
"
  (cog-value-ref (cog-value goal dgv-key) 0)
)
<commit_msg>Check if the values of a goal exist<commit_after>;
; rule.scm
; Utilities for defining and working with OpenPsi rules.
;
; Copyright (C) 2016 OpenCog Foundation
; Copyright (C) 2017 MindCloud
;
; Design Notes:
; Aliases: Rules can be given a "name", called an "alias", below.
; Certain parts of the design assume that a rule has only one name,
; but other parts of the code pass around lists of names. This can
; lead to crazy bugs, due to a lack of checking or enforcement of a
; one-name-per-rule policy.  Also -- each rule should, in principle
; have a unique name; however, the current chatbot uses the same name
; for all chat rules.

; --------------------------------------------------------------
; Used as a key for naming rules
(define psi-rule-name-predicate-node (Predicate "alias"))
; Used to declare the set of actions.
(define psi-action-node (Concept "action"))
; Used to declare the set of goals.
(define psi-goal-node (Concept "goal"))
; Key used to declare the desired-goal-value
(define dgv-key (Predicate "desired-goal-value"))

; --------------------------------------------------------------
(define (psi-set-gv! goal gv)
"
  psi-set-gv! GOAL GV

  Set the goal-value of GOAL to GV. GV is a number.
"
  (cog-set-value! goal (Predicate "value") (FloatValue gv))
)

; --------------------------------------------------------------
(define (psi-goal-value goal)
"
  psi-goal-value GOAL

  Return the present value of GOAL.
"
  (define gv (cog-value goal (Predicate "value")))
  (if (null? gv)
    (error (format #f "Goal \"~a\" has not been created?" (cog-name goal)))
    (cog-value-ref gv 0))
)

; --------------------------------------------------------------
(define (psi-set-dgv! goal num)
"
  psi-set-dgv! GOAL NUM

  Returns GOAL after setting its desired-goal-value to NUM.
"
  (cog-set-value! goal dgv-key (FloatValue num))
)

; --------------------------------------------------------------
(define (psi-dgv goal)
"
  psi-dgv GOAL

  Returns the present desired-goal-value for GOAL. GOAL is a node
  representin the goal concerned.
"
  (define gv (cog-value goal dgv-key))
  (if (null? gv)
    (error (format #f "Goal \"~a\" has not been created?" (cog-name goal)))
    (cog-value-ref gv 0))
)

{'fraction_non_alphanumeric': 0.24666666666666667, 'fraction_numerical': 0.004761904761904762, 'mean_word_length': 1.9668079096045197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4789709', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1250, 'n_words': 489}