-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathen-dict-comp.scm
executable file
·76 lines (65 loc) · 2.05 KB
/
en-dict-comp.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env -S guile
!#
;
; en-dict-comp.scm
; Compare parses produced by a given LG dictionary to those of
; the English dictionary.
;
; Usage:
; guile -s dict-comp.scm <dict-name> <sentence-file-name>
;
; <dict-name> should be a valid Link-Grammar dictionary
; <sentence-file-name> should be a file containing sentences
;
; Example:
; guile -s dict-comp.scm micro-fuzz sentences.txt
;
(use-modules (srfi srfi-1))
(use-modules (ice-9 rdelim))
(use-modules (opencog) (opencog nlp) (opencog learn))
; Check usage
(if (not (equal? 3 (length (program-arguments))))
(begin
(format #t
"Usage: ~A <dict-name> <sentence-file-name>\n"
(first (program-arguments)))
(exit #f)))
(define test-dict (second (program-arguments)))
(define sent-file (third (program-arguments)))
; Check file access
(if (not (equal? (stat:type (stat test-dict)) 'directory))
(begin
(format #t "Cannot find dictionary ~A\n" test-dict)
(exit #f)))
(if (not (access? sent-file R_OK))
(begin
(format #t "Cannot find sentence file ~A\n" sent-file)
(exit #f)))
; Perform comparison
(format #t "Verifying dictionary \"~A\" with sentences from \"~A\"\n"
test-dict sent-file)
;; Set #:INCLUDE-MISSING to #f to disable the processing of sentences
;; containing words that the dictionary does not know about (i.e. to
;; disable unknown-word guessing.)
(define compare
(make-lg-en-comparator (LgDictNode test-dict)
#:INCLUDE-MISSING #t))
(define (process-file PORT)
(define line (read-line PORT))
(if (not (eof-object? line))
(begin
; The # symbol is a comment-card
(if (and
(< 0 (string-length line))
; % is a comment for LG, ! is a directive for LG,
; * means "bad sentence" and # is a comment for python
(not (equal? #\# (string-ref line 0)))
(not (equal? #\! (string-ref line 0)))
(not (equal? #\* (string-ref line 0)))
(not (equal? #\% (string-ref line 0))))
(compare line))
(process-file PORT))
(compare #f)))
(process-file (open sent-file O_RDONLY))
(format #t "Finished verifying dictionary \"~A\" with sentences from \"~A\"\n"
test-dict sent-file)