-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.scm
48 lines (40 loc) · 1.48 KB
/
custom.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Custom definition required for our personal assitant project ;;
;; Required because domain specific requirment. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set! previous_token_to_words token_to_words)
(define (token_to_words token name)
"In case of a real number, will pronounce the digits one by one excluding the decimal point"
(cond
(
(string-matches name "[0-9]+\\.[0-9]+" )
(mapcar num-to-literal (filter is_digit (symbolexplode name))) ; ;; (utf8explode utf8string) ?
)
(
t
(previous_token_to_words token name)
)
)
)
(define (num-to-literal num)
"Returns the literal word of numeric characters"
(car
(cdr
(assoc (parse-number num)
'((1 one) (2 two) (3 three) (4 four) (5 five) (6 six) (7 seven) (8 eight) (9 nine) (0 zero)))))
)
(define (filter pred lst)
"A new list is returned containing only the item matching the predicate"
(reverse (filter-help pred lst '())))
(define (filter-help pred lst res)
(cond ((null? lst) res)
((pred (car lst))
(filter-help pred (cdr lst) (cons (car lst) res)))
(t
(filter-help pred (cdr lst) res))))
(define (is_digit input)
"Is input a single digit number?"
(string-matches input "[0-9]")
)