<commit_before>;
; Helper functions used by all sorts of psi scheme scripts
;
; @author <NAME> <<EMAIL>>
; @date   2011-11-25
;

; Initialize seed of pseudo-random generator using current time
(let ( (time (gettimeofday) )
     )
    (set! *random-state*
         (seed->random-state
             (+ (car time) (cdr time) )
         )
    )
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Fuzzy logic related functions
;

; Return the probability of x equals to t (the target number)
; fuzzy_equal(x,t,a) = 1/(1+a(x-t)^2)
; a is the  parameter, the bigger a, the closer to crisp set
; After plotting via gnuplot for a while, it seems for t falls in [0,1], a=100 is a good choice 
(define (fuzzy_equal x t a)
    (/ 1
        (+ 1
            (* a (- x t) (- x t)) 
        )  
    )     
)

; Ruturn the probability x falls in [min, max] 
; a is the parameter, the bigger a, the closer to crisp set
; For x falls in [0,1], a=100 seems a good choice
(define (fuzzy_within x min_value max_value a)
    (if (< x min_value) 
        (fuzzy_equal x min_value a)

        (if (> x max_value)
            (+ 0.999
               (* (random:uniform) 0.001) 
            )
            
            (+ 0.99 
               (* (random:uniform) 0.01) 
            )
        ); if

    ); if
)

; Ruturn the probability x is smaller than t, 
; a is the parameter, the bigger a, the closer to crisp set
(define (fuzzy_less_than x t a)
    (if (> x t)
        (fuzzy_equal x t a) 
        1
    ) 
)

(define (fuzzy_low x t a)
    (fuzzy_less_than x t a) 
)

; Ruturn the probability x is greater than t, 
; a is the parameter, the bigger a, the closer to crisp set
(define (fuzzy_greater_than x t a)
    (if (< x t)
        (fuzzy_equal x t a)
        1
    ) 
)

(define (fuzzy_high x t a)
    (fuzzy_greater_than x t a) 
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Helper functions of processing query AtomSpace via pattern matcher
;

; Return the scheme list of querying result given the ListLink containing it, 
; this function will delete the ListLink once return
(define (unpack_query_result query_result_list_link)
    (let* ( (query_result_list (cog-outgoing-set query_result_list_link) )
          )

          (cog-delete query_result_list_link)

          query_result_list 
    ) 
)

; Return the scheme list of querying result given BindLink (using cog-bind), 
; return an empty list if fails
(define (query_atom_space bind_link)
    (let* ( (query_result_list_link (cog-bind bind_link) )
          )
          
          (unpack_query_result query_result_list_link)
    ) 
)

; Same as above. Return the scheme list of querying result given
; BindLink (using cog-bind-crisp),  return an empty list if fails
(define (query_atom_space_crisp bind_link)
<<<<<<< HEAD
    (let* ( (query_rusult_list_link (cog-bind bind_link) )
=======
    (let* ( (query_result_list_link (cog-bind-crisp bind_link) )
>>>>>>> Rename rusult -> result in variable name
          )
          
          (unpack_query_result query_result_list_link)
    ) 
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Helper functions for numbers
;

; Return the normalized value ( falls in [0, 1] ) of x, given min and max values
(define (normalize x min_value max_value)
    (/ (- x min_value)
       (- max_value min_value) 
    ) 
)<commit_msg>Actually rename rusult -> result in variable name<commit_after>;
; Helper functions used by all sorts of psi scheme scripts
;
; @author <NAME> <<EMAIL>>
; @date   2011-11-25
;

; Initialize seed of pseudo-random generator using current time
(let ( (time (gettimeofday) )
     )
    (set! *random-state*
         (seed->random-state
             (+ (car time) (cdr time) )
         )
    )
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Fuzzy logic related functions
;

; Return the probability of x equals to t (the target number)
; fuzzy_equal(x,t,a) = 1/(1+a(x-t)^2)
; a is the  parameter, the bigger a, the closer to crisp set
; After plotting via gnuplot for a while, it seems for t falls in [0,1], a=100 is a good choice 
(define (fuzzy_equal x t a)
    (/ 1
        (+ 1
            (* a (- x t) (- x t)) 
        )  
    )     
)

; Ruturn the probability x falls in [min, max] 
; a is the parameter, the bigger a, the closer to crisp set
; For x falls in [0,1], a=100 seems a good choice
(define (fuzzy_within x min_value max_value a)
    (if (< x min_value) 
        (fuzzy_equal x min_value a)

        (if (> x max_value)
            (+ 0.999
               (* (random:uniform) 0.001) 
            )
            
            (+ 0.99 
               (* (random:uniform) 0.01) 
            )
        ); if

    ); if
)

; Ruturn the probability x is smaller than t, 
; a is the parameter, the bigger a, the closer to crisp set
(define (fuzzy_less_than x t a)
    (if (> x t)
        (fuzzy_equal x t a) 
        1
    ) 
)

(define (fuzzy_low x t a)
    (fuzzy_less_than x t a) 
)

; Ruturn the probability x is greater than t, 
; a is the parameter, the bigger a, the closer to crisp set
(define (fuzzy_greater_than x t a)
    (if (< x t)
        (fuzzy_equal x t a)
        1
    ) 
)

(define (fuzzy_high x t a)
    (fuzzy_greater_than x t a) 
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Helper functions of processing query AtomSpace via pattern matcher
;

; Return the scheme list of querying result given the ListLink containing it, 
; this function will delete the ListLink once return
(define (unpack_query_result query_result_list_link)
    (let* ( (query_result_list (cog-outgoing-set query_result_list_link) )
          )

          (cog-delete query_result_list_link)

          query_result_list 
    ) 
)

; Return the scheme list of querying result given BindLink (using cog-bind), 
; return an empty list if fails
(define (query_atom_space bind_link)
    (let* ( (query_result_list_link (cog-bind bind_link) )
          )
          
          (unpack_query_result query_result_list_link)
    ) 
)

; Same as above. Return the scheme list of querying result given
; BindLink (using cog-bind-crisp),  return an empty list if fails
(define (query_atom_space_crisp bind_link)
    (let* ( (query_result_list_link (cog-bind bind_link) )
          )
          
          (unpack_query_result query_result_list_link)
    ) 
)

;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;
; Helper functions for numbers
;

; Return the normalized value ( falls in [0, 1] ) of x, given min and max values
(define (normalize x min_value max_value)
    (/ (- x min_value)
       (- max_value min_value) 
    ) 
)
{'fraction_non_alphanumeric': 0.15983424596714518, 'fraction_numerical': 0.01213556311972769, 'mean_word_length': 2.627482555018787, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, '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': '6936585', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2346, 'n_words': 725}