| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" ); 4 5 define("TOKEN_DEFAULT_PROBABILITY", 0.4); 6 7 define("TOKEN_SEPARATOR_MARK", "#"); 8 define("TOKEN_TOPIC_MARK", "Topic" . TOKEN_SEPARATOR_MARK); 9 define("TOKEN_URL_MARK", "Url" . TOKEN_SEPARATOR_MARK); 10 define("TOKEN_USER_NAME_MARK", "UserName" . TOKEN_SEPARATOR_MARK); 11 define("TOKEN_USER_EMAIL_MARK", "UserEmail" . TOKEN_SEPARATOR_MARK); 12 define("TOKEN_USER_URL_MARK", "UserUrl" . TOKEN_SEPARATOR_MARK); 13 14 /** 15 * \ingroup DAO 16 * 17 * Represents a record form the plog_filtered_content table 18 * 19 * The key of this class is the regexp that will be used to match 20 * words against it. 21 */ 22 class BayesianToken extends DbObject 23 { 24 25 var $_id; 26 var $_blogId; 27 var $_token; 28 var $_spamOccurrences; 29 var $_nonSpamOccurrences; 30 var $_prob; 31 32 /** 33 * -- Add function info here -- 34 */ 35 function BayesianToken($blogId, $token, $spamOccurrences, $nonSpamOccurrences, $prob, $id = -1) 36 { 37 $this->DbObject(); 38 39 $this->_id = $id; 40 $this->_blogId = $blogId; 41 $this->_token = $token; 42 $this->_spamOccurrences = $spamOccurrences; 43 $this->_nonSpamOccurrences = $nonSpamOccurrences; 44 $this->_prob = $prob; 45 } 46 47 /** 48 * -- Add function info here -- 49 */ 50 function getId() 51 { 52 return $this->_id; 53 } 54 55 /** 56 * -- Add function info here -- 57 */ 58 function getBlogId() 59 { 60 return $this->_blogId; 61 } 62 63 /** 64 * -- Add function info here -- 65 */ 66 function getToken() 67 { 68 return $this->_token; 69 } 70 71 /** 72 * -- Add function info here -- 73 */ 74 function getSpamOccurrences() 75 { 76 return $this->_spamOccurrences; 77 } 78 79 /** 80 * -- Add function info here -- 81 */ 82 function getNonSpamOccurrences() 83 { 84 return $this->_nonSpamOccurrences; 85 } 86 87 /** 88 * -- Add function info here -- 89 */ 90 function getProb() 91 { 92 return $this->_prob; 93 } 94 95 /** 96 * -- Add function info here -- 97 */ 98 function setProb($prob) 99 { 100 $this->_prob = $prob; 101 } 102 103 /** 104 * -- Add function info here -- 105 */ 106 function isSignificant() 107 { 108 return ((2 * $this->getNonSpamOccurrences()) + $this->getSpamOccurrences()) > 5; 109 } 110 111 /** 112 * -- Add function info here -- 113 */ 114 function isValid($token = false) 115 { 116 $config =& Config::getConfig(); 117 118 if ($token === false) 119 { 120 $token = $this->getToken(); 121 } 122 123 $valid = !ereg("^[0-9-]+$", $token); 124 125 if ($config->getValue("bayesian_filter_min_length_token") > 0) 126 { 127 $valid = $valid && strlen($token) >= $config->getValue("bayesian_filter_min_length_token"); 128 } 129 130 if ($config->getValue("bayesian_filter_max_length_token") > 0) 131 { 132 $valid = $valid && strlen($token) <= $config->getValue("bayesian_filter_max_length_token"); 133 } 134 135 return $valid; 136 } 137 138 /** 139 * -- Add function info here -- 140 */ 141 function degenerate($token = false) 142 { 143 if ($token === false) 144 { 145 $token = $this->getToken(); 146 } 147 148 $degenerations = array(); 149 $curToken = $token; 150 $prefix = true; 151 152 while ($prefix) 153 { 154 if (ereg("^(" . TOKEN_TOPIC_MARK . "|" . 155 TOKEN_URL_MARK . "|" . 156 TOKEN_USER_NAME_MARK . "|" . 157 TOKEN_USER_EMAIL_MARK . "|" . 158 TOKEN_USER_URL_MARK . ")(.*)$", $curToken, $regs)) 159 { 160 $curToken = $regs[2]; 161 $prefix = $regs[1]; 162 } 163 else 164 { 165 $prefix = ""; 166 } 167 168 $degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($curToken, $prefix)); 169 170 if (ereg("([^!]+!)!+$", $curToken, $regs)) 171 { 172 $degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($regs[1], $prefix)); 173 } 174 175 if (ereg("([^!]+)!+$", $curToken, $regs)) 176 { 177 $degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($regs[1], $prefix)); 178 } 179 180 if ($prefix == "" && $curToken == $token) 181 { 182 foreach ($degenerations as $degeneration) 183 { 184 array_push($degenerations, TOKEN_TOPIC_MARK . $degeneration); 185 array_push($degenerations, TOKEN_URL_MARK . $degeneration); 186 array_push($degenerations, TOKEN_USER_NAME_MARK . $degeneration); 187 array_push($degenerations, TOKEN_USER_EMAIL_MARK . $degeneration); 188 array_push($degenerations, TOKEN_USER_URL_MARK . $degeneration); 189 } 190 } 191 } 192 193 return array_unique($degenerations); 194 } 195 196 /** 197 * -- Add function info here -- 198 */ 199 function getBasicsDegeneration($token = false, $prefix = "") 200 { 201 if ($token === false) 202 { 203 $token = $this->getToken(); 204 } 205 206 $degenerations = array(); 207 208 $lower = strtolower($token); 209 array_push($degenerations, $prefix . $token); 210 array_push($degenerations, $prefix . strtoupper($token)); 211 array_push($degenerations, $prefix . $lower); 212 array_push($degenerations, $prefix . ucFirst($lower)); 213 214 return $degenerations; 215 } 216 } 217 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|