Example #1
0
-->

<?php 
// service, text
require dirname(__FILE__) . "/RestUtils.php";
include dirname(__FILE__) . "/../core/classification/MultinomialNaiveBayes.php";
include_once "DB.php";
include_once dirname(__FILE__) . "/../core/util/dbauth/DBAuthManager.php";
$maxHits = 500;
$premiumHits = 1111;
//PERMISSIONS
$granted = true;
$premium = false;
// Check number of queries
$callerIP = $_SERVER['REMOTE_ADDR'];
$db = DB::connect(getConnection() . getPrefixID() . '_NLPToolsAPI');
if (DB::isError($db)) {
    throw new Exception("REST API: " . "DB connection error! " . $db->getMessage() . "\n");
} else {
    // check if it exists
    // Table schema: IPaddress Hits
    $itExists = $db->getOne("SELECT Hits FROM Users WHERE IPaddress = '{$callerIP}';");
    if (!is_null($itExists)) {
        // check premium IP
        if ($itExists == $premiumHits) {
            // OK, proceed
            $premium = true;
        } elseif ($itExists >= $maxHits) {
            // check range not allowed, limit reached
            $granted = false;
        } else {
 /**
  * @see Classifier#setDatabase($name)
  */
 public function setDatabase($name)
 {
     $name = (string) $name;
     if (getPrefixID() != "") {
         $this->theDBName = getPrefixID() . "_" . $name;
     } else {
         $this->theDBName = $name;
     }
 }