<commit_before><?php
/**
 * Example of API Client for Datumbox Machine Learning API.
 * 
 * @author <NAME>
 * @link   http://www.datumbox.com/
 * @copyright Copyright (c) 2013, Datumbox.com
 */
class DatumboxAPI {
    const version='1.0';
    
    protected $api_key;
    
    /**
    * Constructor
    * 
    * @param string $api_key
    * @return DatumboxAPI
    */
    public function __construct($api_key) {
        $this->api_key=$api_key;
    }
    
    /**
    * Calls the Web Service of Datumbox
    * 
    * @param string $api_method
    * @param array $POSTparameters
    * 
    * @return string $jsonreply
    */
    protected function CallWebService($api_method,$POSTparameters) {
        $POSTparameters['api_key']=$this->api_key;
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://api.datumbox.com/'.self::version.'/'.$api_method.'.json');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTparameters);

        $jsonreply = curl_exec ($ch);
        curl_close ($ch);
        unset($ch);

        return $jsonreply;
    }
    
    /**
    * Parses the API Reply
    * 
    * @param mixed $jsonreply
    * 
    * @return mixed
    */
    protected function ParseReply($jsonreply) {
        $jsonreply=json_decode($jsonreply,true);
        
        if(isset($jsonreply['output']['status']) && $jsonreply['output']['status']==1) {
            return $jsonreply['output']['result'];
        }
        
        if(isset($jsonreply['error']['ErrorCode']) && isset($jsonreply['error']['ErrorMessage'])) {
            echo $jsonreply['error']['ErrorMessage'].' (ErrorCode: '.$jsonreply['error']['ErrorCode'].')';
        }
        
        return false;
    }
    
    /**
    * Performs Sentiment Analysis.
    * 
    * @param string $text The clear text (no HTML tags) that we evaluate.
    * 
    * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail.
    */
    public function SentimentAnalysis($text) {
        $parameters=array(
            'text'=>$text,
        );
        
        $jsonreply=$this->CallWebService('SentimentAnalysis',$parameters);
        
        return $this->ParseReply($jsonreply);
    }
    
    /**
    * Performs Sentiment Analysis on Twitter.
    * 
    * @param string $text The tweet that we evaluate.
    * 
    * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail.
    */
    public function TwitterSentimentAnalysis($text) {
        $parameters=array(
            'text'=>$text,
        );
        
        $jsonreply=$this->CallWebService('TwitterSentimentAnalysis',$parameters);
        
        return $this->ParseReply($jsonreply);
    }
    
    /**
    * Performs Subjectivity Analysis.
    * 
    * @param string $text The clear text (no HTML tags) that we evaluate.
    * 
    * @return string|false. It returns "objective" or "subjective" on success and false on fail.
    */
    public function SubjectivityAnalysis($text) {<commit_msg>Correcting comment<commit_after><?php
/**
 * Example of API Client for Datumbox Machine Learning API.
 * 
 * @author <NAME>
 * @link   http://www.datumbox.com/
 * @copyright Copyright (c) 2013, Datumbox.com
 */
class DatumboxAPI {
    const version='1.0';
    
    protected $api_key;
    
    /**
    * Constructor
    * 
    * @param string $api_key
    * @return DatumboxAPI
    */
    public function __construct($api_key) {
        $this->api_key=$api_key;
    }
    
    /**
    * Calls the Web Service of Datumbox
    * 
    * @param string $api_method
    * @param array $POSTparameters
    * 
    * @return string $jsonreply
    */
    protected function CallWebService($api_method,$POSTparameters) {
        $POSTparameters['api_key']=$this->api_key;
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://api.datumbox.com/'.self::version.'/'.$api_method.'.json');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTparameters);

        $jsonreply = curl_exec ($ch);
        curl_close ($ch);
        unset($ch);

        return $jsonreply;
    }
    
    /**
    * Parses the API Reply
    * 
    * @param mixed $jsonreply
    * 
    * @return mixed
    */
    protected function ParseReply($jsonreply) {
        $jsonreply=json_decode($jsonreply,true);
        
        if(isset($jsonreply['output']['status']) && $jsonreply['output']['status']==1) {
            return $jsonreply['output']['result'];
        }
        
        if(isset($jsonreply['error']['ErrorCode']) && isset($jsonreply['error']['ErrorMessage'])) {
            echo $jsonreply['error']['ErrorMessage'].' (ErrorCode: '.$jsonreply['error']['ErrorCode'].')';
        }
        
        return false;
    }
    
    /**
    * Performs Sentiment Analysis.
    * 
    * @param string $text The clear text (no HTML tags) that we evaluate.
    * 
    * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail.
    */
    public function SentimentAnalysis($text) {
        $parameters=array(
            'text'=>$text,
        );
        
        $jsonreply=$this->CallWebService('SentimentAnalysis',$parameters);
        
        return $this->ParseReply($jsonreply);
    }
    
    /**
    * Performs Sentiment Analysis on Twitter.
    * 
    * @param string $text The text of the tweet that we evaluate.
    * 
    * @return string|false It returns "positive", "negative" or "neutral" on success and false on fail.
    */
    public function TwitterSentimentAnalysis($text) {
        $parameters=array(
            'text'=>$text,
        );
        
        $jsonreply=$this->CallWebService('TwitterSentimentAnalysis',$parameters);
        
        return $this->ParseReply($jsonreply);
    }
    
    /**
    * Performs Subjectivity Analysis.
    * 
    * @param string $text The clear text (no HTML tags) that we evaluate.
    * 
    * @return string|false. It returns "objective" or "subjective" on success and false on fail.
    */
    public function SubjectivityAnalysis($text) {
{'fraction_non_alphanumeric': 0.13785659213569776, 'fraction_numerical': 0.002158828064764842, 'mean_word_length': 2.419082762256194, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2524741', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1925, 'n_words': 424}