-
Notifications
You must be signed in to change notification settings - Fork 33
/
check-oset.scm
executable file
·133 lines (107 loc) · 3.24 KB
/
check-oset.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
#! /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 checks for orphaned UUID's
(load "common.scm")
; --------------------------------------------------------------
(define (get-atoms-of-height height)
"
get-atms-of-height -- gt all atoms of a given height
"
(define row #f)
(define uuid 0)
(define atom-list (list))
; Find all the EvaluationLinks
(define qry (string-append
"SELECT * FROM atoms WHERE height="
(number->string height)))
(display qry)(newline)
(dbi-query conxion qry)
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
(set! uuid (cdr (assoc "uuid" row)))
(set! atom-list (cons uuid atom-list))
; Get the next row
(set! row (dbi-get_row conxion))
)
atom-list
)
; --------------------------------------------------------------
(define (look-for-orphans uuid-list)
"
look-for-orphans -- look for osets that don't have atoms
Given a list of uuid's that are links, fetch the outgoing set
of each link, and then look to see if the atoms in the outgoing
set are in the database. Return a list of the links that have
outgoing sets that fail to refer to atoms.
"
(define orphan-list (list))
; Given a single uuid, return #t if it is in the atomspace,
; else retun #f
(define (check-atom uuid)
(define row #f)
(define have #f)
; Find the oset
(define qry (string-append
"SELECT * FROM atoms WHERE uuid="
(number->string uuid)))
; (display qry)(newline)
(dbi-query conxion qry)
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
(set! have #t)
; Get the next row
(set! row (dbi-get_row conxion))
)
(if (not have) (begin
(display "Cannot find uuid ")(display uuid)(newline))
)
have
)
; Given a single uuid, look at its oset.
(define (check-oset uuid)
(define row #f)
(define oset-list (list))
; Find the oset
(define qry (string-append
"SELECT outgoing FROM atoms WHERE uuid="
(number->string uuid)))
; (display qry)(newline)
(dbi-query conxion qry)
(set! row (dbi-get_row conxion))
(while (not (equal? row #f))
(set! oset-list (cdr (assoc "outgoing" row)))
; Get the next row
(set! row (dbi-get_row conxion))
)
; now check the oset
(if (any (lambda (x) (not x)) (map check-atom oset-list))
(begin
(display "oh nooo!! bad link is ")(display uuid)(newline)
(set! orphan-list (cons uuid orphan-list))
)
)
)
(for-each check-oset uuid-list)
orphan-list
)
; --------------------------------------------------------------
(define h3 (get-atoms-of-height 3))
(display "Number of atoms of height 3: ") (display (length h3))(newline)
(define h2 (get-atoms-of-height 2))
(display "Number of atoms of height 2: ") (display (length h2))(newline)
(define o2 (look-for-orphans h2))
(display "Orphan h2 links: ") (display (length o2))(newline)
; (delete-atoms o2 0)
(define h1 (get-atoms-of-height 1))
(display "Number of atoms of height 1: ") (display (length h1))(newline)
(define o1 (look-for-orphans h1))
(display "Orphan h1 links: ") (display (length o1))(newline)
; (delete-atoms o1 0)