-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathprint-dict.scm
58 lines (48 loc) · 1.38 KB
/
print-dict.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
48
49
50
51
52
53
54
55
56
57
58
;
; print-dict.scm -- print Link-Grammar dictionary to file.
;
; Copyright (c) 2021 - Linas Vepstas
;
; --------------------------------------------------------
; OVERVIEW:
; Print Link Grammar dictionaries to a file. The print format is the
; standard `4.0.dict` utf-8 file format.
;
; Example Usage:
; --------------
; Print dict to stdout.
; (print-LG-flat #t dict)
;
; Print dict to file.
; (define port (open-file "/tmp/4.0.dict" "w"))
; (print-LG-flat port dict)
; (fsync port) (close port)
;
(use-modules (srfi srfi-1))
; --------------------------------------------------------
; Print dictionary.
(define-public (print-LG-flat DEST DICT)
"
print-LG-flat DEST DICT - print a Link-Grammar style dictionary.
Prints a flat-file style dictionary. That is a \"4.0.dict\" style
file. This does NOT print the file boilerplate, it only prints
the raw dictionary contents.
The DEST must be the destination file-handle, or #t to print to
stdout, or #f to print to string.
The DICT must be a dictionary.
"
(define (prt-wordlist WL)
(string-join
(map (lambda (WORD) (format #f "~A" WORD)) WL)))
(define (prt-junct CL)
(string-join
(map (lambda (CON) (format #f "~A" CON)) CL) " or "))
(for-each
(lambda (ENTRY)
(format DEST "\n~A: ~A;\n"
(prt-wordlist (first ENTRY))
(prt-junct (second ENTRY)))
)
DICT)
)
; --------------------------------------------------------