-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathexport-mi.scm
63 lines (55 loc) · 1.48 KB
/
export-mi.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
;
; export-mi.scm
;
; The hacky and ugly code below looks for every EvaluationLink
; containing a ListLink with two WordNodes in the atomspace,
; then prints that word-pair's FMI to file.
; For research purposes only.
;
;
(use-modules (opencog sheaf))
(define-public (export-mi cnt-mode)
"
Export the word-pairs fMI for
every possible pair in the corpus, to allow analysis
of the MI-based MST-parser
The format is:
word#1 word#2 pair-mi
word#5 word#3 pair-mi
...
"
(define pair-obj
(if (equal? cnt-mode "any")
(make-any-link-api)
(make-clique-pair-api)
)
)
(define mi-source (add-pair-freq-api pair-obj))
(define scorer (make-score-fn mi-source 'pair-fmi))
(define file-port-fmi (open-file "mi-pairs.txt" "w"))
; Print an mi-pair
(define (print-mi EL)
(let ([l-node (gar (gdr EL))] [r-node (gdr (gdr EL))])
(if
(and (equal? 'WordNode (cog-type l-node))
(equal? 'WordNode (cog-type r-node))
)
(display
(format #f "~a ~a ~a\n"
(cog-name l-node)
(cog-name r-node)
(scorer l-node r-node 1)
)
file-port-fmi
)
)
)
)
; Print MI-info
(for-each
(lambda (e)
(print-mi e))
(cog-get-atoms 'EvaluationLink)
)
(close-port file-port-fmi)
)