Browse Source

Learn / Unlearn posts as spam + synchronize dba

yumi 1 month ago
parent
commit
f591d096d3
3 changed files with 88 additions and 2 deletions
  1. 58
    2
      bin/admin.php
  2. 1
    0
      bin/install.php
  3. 29
    0
      patch/b8-sync.patch

+ 58
- 2
bin/admin.php View File

@@ -22,17 +22,20 @@ PRINT <<<BANNER
22 22
 BANNER;
23 23
 
24 24
 do { $answer = ask([
25
-'Continuities',
25
+'Content',
26 26
 'News',
27
+'Spam',
27 28
 'Bans',
28 29
 'Post Details',
29 30
 'Miscellany',
30 31
 'Quit'
31 32
 ]); switch ($answer) {
32
-	case 'Continuities':
33
+	case 'Content':
33 34
 	$answer = ask([
34 35
 	'Metrics',
35 36
 	'Post Info',
37
+	'Mark / Learn as Spam',
38
+	'Unmark / Unlearn as Spam',
36 39
 	'Delete a Post',
37 40
 	'Create a Continuity',
38 41
 	'Delete a Continuity'
@@ -40,12 +43,27 @@ do { $answer = ask([
40 43
 		case 'Metrics':
41 44
 		break;
42 45
 
46
+		case 'Mark / Learn as Spam':
47
+		break;
48
+
49
+		case 'Unmark / Unlearn as Spam':
50
+		$iterator->select(prompt('Continuity'),
51
+			prompt('Year'),
52
+			prompt('Topic'),
53
+			prompt('Id'));
54
+		if ($iterator->Post->unlearn())
55
+			print "Successfully unlearned!\n";
56
+		else
57
+			print "Failure: post was never learned as spam\n";
58
+		break;
59
+
43 60
 		case 'Post Info':
44 61
 		$iterator->select(prompt('Continuity'),
45 62
 			prompt('Year'),
46 63
 			prompt('Topic'),
47 64
 			prompt('Id'));
48 65
 		$iterator->Post->InfoText();
66
+		break;
49 67
 
50 68
 		case 'Delete a Post':
51 69
 		$iterator->select(prompt('Continuity'),
@@ -69,6 +87,44 @@ do { $answer = ask([
69 87
 		], $iterator);
70 88
 		if (prompt('Are you sure? (Y/n) ') == 'Y') $C->destroy();
71 89
 	} break;
90
+	case 'Spam':
91
+		$answer = ask([
92
+		'Train Filter',
93
+		]); switch ($answer) {
94
+		case 'Train Filter':
95
+			$b8 = $RM->getb8();
96
+			$iterator->selectUnlearned();
97
+			for ($i = 0; $i < sizeof($iterator->Selection); $i++) {
98
+				$post = $iterator->Selection[$i];
99
+				$spamminess = $b8->classify($RM->asHtml(
100
+					$post->Content));
101
+
102
+				printf("(%d posts remain)\n", sizeof($iterator->Selection) - $i);
103
+				print $post->renderAsText(false);
104
+				switch(prompt("Is this spam? (Y/n) (Score: $spamminess)")) {
105
+					case 'Y':
106
+					case 'y':
107
+						if ($spamminess > 0.8) {
108
+							print "That's what I figured!\n";
109
+							$post->b8GuessWasCorrect(\b8::SPAM);
110
+						} else {
111
+							print "I'll make a note of that...\n";
112
+							$post->learn(\b8::SPAM);
113
+						} break;
114
+					case 'N':
115
+					case 'n':
116
+						if ($spamminess < 0.6) {
117
+							print "That's what I figured!\n";
118
+							$post->b8GuessWasCorrect(\b8::HAM);
119
+						} else {
120
+							print "I'll make a note of that...\n";
121
+							$post->learn(\b8::HAM);
122
+						} break;
123
+					default:
124
+						print "Skipping...";
125
+				} print "\n";
126
+			}
127
+		} break;
72 128
 	case 'Bans':
73 129
 	$answer = ask([
74 130
 	'Flame a User',

+ 1
- 0
bin/install.php View File

@@ -144,6 +144,7 @@ CMD;
144 144
 	rm $tmpfile ; \
145 145
 	rm -r {$tmp}/b8-0.6.2
146 146
 	patch -p0 -d $installto < ${ROOT}patch/b8-abspath-fix.patch
147
+	patch -p0 -d $installto < ${ROOT}patch/b8-sync.patch
147 148
 CMD;
148 149
 	system($cmd);
149 150
 }

+ 29
- 0
patch/b8-sync.patch View File

@@ -0,0 +1,29 @@
1
+--- b8.php	2019-02-08 14:51:36.000000000 -0500
2
++++ b8.php	2019-07-14 22:24:44.196134209 -0400
3
+@@ -405,6 +405,11 @@
4
+         return $this->_processText($text, $category, self::UNLEARN);
5
+     }
6
+ 
7
++	public function sync()
8
++	{
9
++		return $this->storage->sync();
10
++	}
11
++
12
+     /**
13
+      * Does the actual interaction with the storage backend for learning or unlearning texts
14
+      *
15
+ 
16
+
17
+--- storage/storage_dba.php	2014-09-03 09:07:31.000000000 -0400
18
++++ storage/storage_dba.php	2019-07-14 22:24:49.676134195 -0400
19
+@@ -102,6 +102,10 @@
20
+         dba_close($this->_db);
21
+     }
22
+ 
23
++	function sync() {
24
++		dba_sync($this->_db);
25
++	}
26
++
27
+     /**
28
+      * Does the actual interaction with the database when fetching data.
29
+      *