-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrecalculate_ic.sql
executable file
·46 lines (39 loc) · 1.5 KB
/
recalculate_ic.sql
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
/** test in simplewiki: CALL recalculate_ic(426077); */
DROP PROCEDURE IF EXISTS recalculate_ic//
CREATE PROCEDURE recalculate_ic (
IN category_size INT(10) /** Number of passed categories and articles */
)
COMMENT 'Recalculate IC'
proc:
BEGIN
DECLARE done, error BOOL DEFAULT FALSE;
DECLARE cur_hyponyms MEDIUMINT UNSIGNED;
DECLARE cur_ic FLOAT;
DECLARE cur_title VARCHAR(255);
DECLARE LOG_CATEGORY_SIZE FLOAT;
DECLARE cur
CURSOR FOR
SELECT n_hyponyms, page_title FROM cat_count;
DECLARE
CONTINUE HANDLER FOR
SQLSTATE '02000'
SET done = TRUE;
SET LOG_CATEGORY_SIZE = LOG(category_size);
OPEN cur;
IF error THEN SELECT 'ERROR OPEN CURSOR failed in PROCEDURE recalculate_ic'; LEAVE proc; END IF;
myLoop: LOOP
FETCH cur INTO cur_hyponyms, cur_title;
IF done THEN
CLOSE cur;
LEAVE myLoop;
END IF;
IF cur_hyponyms > 0 THEN
/** if 0 hyponyms then ic = -1, remain it */
/** information content of the category*/
SET cur_ic = 1 - (LOG(cur_hyponyms + 1)) / LOG_CATEGORY_SIZE;
UPDATE cat_count SET
ic=cur_ic
WHERE page_title=cur_title;
END IF;
END LOOP;
END; //