-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpair-api.scm
100 lines (87 loc) · 2.81 KB
/
pair-api.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;
; pair-api.scm
;
; Define a matrix-API object for accessing word pairs.
;
; Copyright (c) 2013, 2014, 2017 Linas Vepstas
;
; ---------------------------------------------------------------------
; OVERVIEW
; --------
; The object below defines an API to access pairs of natural language
; word-pairs, stored in the AtomSpace, as a rank-2 matrix, i.e. as a
; matrix of (left, right) word pairs. This provides exactly the API
; needed for use with the `(use-modules (opencog matrix))` statistical
; analysis subsystem.
;
; The specific Atomese uses this structure:
;
; EdgeLink
; BondNode "ANY"
; ListLink
; WordNode "left-word"
; WordNode "right-word"
;
; The above is meant to be a special case of a general, generic form
; of item pairs; for example:
;
; EvaluationLink
; PredicateNode "*-Item pairs-*"
; ListLink
; ItemNode "left item"
; ItemNode "right item"
;
; The generic form can be created with the `make-evaluation-pair-api`
; object. The special-case form is used because EdgeLinks require less
; RAM than EvaluationLinks.
; ---------------------------------------------------------------------
;
(use-modules (srfi srfi-1))
(use-modules (opencog))
(use-modules (opencog matrix))
; ---------------------------------------------------------------------
(define-public (make-any-link-api)
"
make-any-link-api -- Word-pair access methods.
This implements a word-pair object, where the two words are connected
with a BondNode \"ANY\", in an EdgeLink.
That is, a word pair is represented as:
EdgeLink
BondNode \"ANY\"
ListLink
WordNode \"word\"
WordNode \"bird\"
The above provides a location for storing various counts, frequencies,
entropies, etc pertaining to this particular pair.
The 'get-pair method returns the above EdgeLink, if it exists.
The 'make-pair method will create it, if it does not exist.
Left-side counts, frequencies, etc. such as N(*,y) P(*,y) or
log_2 P(*,y) will be placed on the left-marginal, which is returned
by the 'left-wildcard method:
EdgeLink
BondNode \"ANY\"
ListLink
AnyNode \"left-word\"
WordNode \"bird\"
The corresponding N(x,*) P(x,*) etc are hung on the right-marginal,
returned by the 'right-wildcard method:
EdgeLink
BondNode \"ANY\"
ListLink
WordNode \"word\"
AnyNode \"right-word\"
Finally, the 'left-type and 'right-type methods return the type
of the the two sides of the pair.
"
; Just use the generic code to implement the above.
(make-edge-pair-api
'EdgeLink
(BondNode "ANY")
'WordNode
'WordNode
(AnyNode "left-word")
(AnyNode "right-word")
"ANY"
"Link Grammar ANY link Word Pairs")
)
; ---------------------------------------------------------------------