-
Notifications
You must be signed in to change notification settings - Fork 33
/
any-merge.scm
executable file
·254 lines (207 loc) · 6.74 KB
/
any-merge.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#! /usr/bin/env guile
!#
;
; Atomspace deduplication repair script
;
; Due to bugs, the SQL backend can end up with multiple copies of
; atoms. This script will find them, merge them, and sum the counts
; on the associated count truth values. Its up to you to recompute
; anything else.
;
; This script focuses on accidentally having two ANY nodes.
; Viz if select * from atoms where type=89 and name='ANY';
; returns more than one row :-(
(load "common.scm")
; --------------------------------------------------------------
(define (get-all-atoms query colm)
"
get-all-atoms -- Execute the query, return all colm values.
colm should be the string column name; e.g. 'uuid'
Returns a list of the 'colm' entries
"
(define alist (list))
(define word-count 0)
(define row #f)
(dbi-query conxion query)
(display "Atom search connection status: ")
(display (dbi-get_status conxion)) (newline)
; Loop over table rows
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
; Extract the column value
(let* ((valu (cdr (assoc colm row))))
(set! alist (cons valu alist))
; Maintain a count, just for the hell of it.
(set! word-count (+ word-count 1))
; (display word) (newline)
(set! row (dbi-get_row conxion))
)
)
(display "For the query: ")(display query)(newline)
(display "The num rows was: ") (display word-count) (newline)
alist
)
; --------------------------------------------------------------
(define (get-all-evals alist anyid)
"
get-all-evals -- Get all of the EvaluationLinks that contain
a ListLink and the anyid uuid.
Returns a list of the EvaluationLink entries.
"
(define word-count 0)
(define elist (list))
; Get an evaluationLink
(define (get-eval uuid)
(define euid 0)
(define row #f)
(define qry (string-concatenate (list
"SELECT uuid FROM atoms WHERE type="
EvalLinkType
" AND outgoing="
(make-outgoing-str (list anyid uuid)))))
; (display qry)(newline)
(dbi-query conxion qry)
; Loop over table rows
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
; Extract the column value
(set! euid (cdr (assoc "uuid" row)))
; Maintain a count, just for the hell of it.
(set! word-count (+ word-count 1))
; (display word) (newline)
(set! row (dbi-get_row conxion))
)
euid
)
(set! elist (map get-eval alist))
(display "Number of EvaluationLinks: ") (display word-count) (newline)
elist
)
; --------------------------------------------------------------
; A list of all ListLinks
(define all-list-links (get-all-atoms
"SELECT uuid FROM atoms WHERE type=8" "uuid"))
(define (count-evlinks any-uuid)
(display "Numb of ") (display any-uuid) (display " evals: ")
(display (length (get-all-evals all-list-links any-uuid)))(newline))
;(display "Numb of 250-evals: ")
;(display (length (get-all-evals all-list-links 250)))(newline)
;(display "Numb of 152-evals: ")
;(display (length (get-all-evals all-list-links 152)))(newline)
; (map count-evlinks (list 152 250))
; (map count-evlinks (list 57 139 140 186 190 270))
; --------------------------------------------------------------
(define (relabel-evals alist bad-id good-id)
"
relabel-evals -- Change the oset of all of the EvaluationLinks
that use the bad ANY uuid; make it use the good ANY id.
Returns a list of the changed EvaluationLink entries.
"
(define word-count 0)
(define elist (list))
; Change an EvaluationLink
; euid == uuid of the evaluation link
; luid == uuid of the ListLink
; any-id == uuid to change it to.
(define (set-eval euid luid any-id)
(define row #f)
(define qry (string-concatenate (list
"UPDATE atoms SET outgoing="
(make-outgoing-str (list any-id luid))
" WHERE uuid="
(number->string euid))))
; (display qry)(newline)
(dbi-query conxion qry)
(flush-query)
)
; Change an EvaluationLink from the old bad ANY uuid to the new
; one. The argument is the uuid of the ListLink
(define (change-eval uuid)
(define euid 0)
(define row #f)
; First, get the uuid of the EvaluationLink
(define qry (string-concatenate (list
"SELECT uuid FROM atoms WHERE type="
EvalLinkType
" AND outgoing="
(make-outgoing-str (list bad-id uuid)))))
; (display qry)(newline)
(dbi-query conxion qry)
; Loop over table rows
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
; Extract the uuid of the EvaluationLink
(set! euid (cdr (assoc "uuid" row)))
; Maintain a count, just for the hell of it.
(set! word-count (+ word-count 1))
; Print status so we don't get bored.
(if (eq? 0 (modulo word-count 1000)) (begin
(display "Processed ")(display word-count)
(display " id-relabels")(newline))
(flush-output-port (current-output-port))
)
; (display word) (newline)
(set! row (dbi-get_row conxion))
)
; euid will be zero is the ListLink does not appear with
; the bad any-id
(if (< 0 euid)
(set-eval euid uuid good-id))
)
(set! elist (map change-eval alist))
(display "Relabel ANY uuid ") (display bad-id)
(display " to ") (display good-id)(newline)
(display "Relabeled uuid count was ") (display word-count) (newline)
(flush-output-port (current-output-port))
elist
)
; (relabel-evals all-list-links 250 152)
;(relabel-evals all-list-links 139 57)
;(relabel-evals all-list-links 140 57)
;(relabel-evals all-list-links 186 57)
;(relabel-evals all-list-links 190 57)
;(relabel-evals all-list-links 270 57)
; -----------------------------------------------
(define (get-all-non-any-evals any-id)
"
get-all-non-any-evals -- look for all EvalLinks that do NOT
hold the desired ANY node. At this point in the game, there
should not be any of these. But there are. WTF. Oh, it was
a bad conversion of int8 to long long in guile-dbi.
"
(define bad-list (list))
(define euid 0)
(define luid 0)
(define oset (list))
(define row #f)
(define qry (string-concatenate (list
"SELECT uuid,outgoing FROM atoms WHERE type="
EvalLinkType)))
(display qry)(newline)
(dbi-query conxion qry)
; Loop over table rows
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
; Extract the column value
(set! euid (cdr (assoc "uuid" row)))
(set! oset (cdr (assoc "outgoing" row)))
(set! luid (cadr oset))
(if (not (eq? (car oset) any-id)) (begin
(set! bad-list (cons luid bad-list))
;(display "Its bad: ")(display euid)
;(display " any: ")(display (car oset))(newline)
;(flush-output-port (current-output-port))
))
; (display word) (newline)
(set! row (dbi-get_row conxion))
)
; Return the list of bad EvaluationLinks
bad-list
)
(define bad-list (get-all-non-any-evals 57))
(display "Number of bad evals: ") (display (length bad-list))(newline)
;(relabel-evals bad-list 139 57)
;(relabel-evals bad-list 140 57)
;(relabel-evals bad-list 186 57)
;(relabel-evals bad-list 190 57)
;(relabel-evals bad-list 270 57)