DataSift_Pylon::analyze PHP Method

analyze() public method

Analyze the recording
public analyze ( array $parameters, string $filter = false, integer $start = false, integer $end = false, string $id = false ) : array
$parameters array the parameter array to be used to analyze the data set
$filter string additional CSDL filter
$start integer the start time of the pylon
$end integer the end time of the pylon
$id string If id is provided it will be set
return array Response from the compile
    public function analyze($parameters, $filter = false, $start = false, $end = false, $id = false)
    {
        if ($id) {
            $this->_id = $id;
        }
        //If parameters is not an array try and decode it
        if (!is_array($parameters)) {
            $parameters = json_decode($parameters);
        }
        if (empty($parameters)) {
            throw new DataSift_Exception_InvalidData('Parameters must be supplied as an array or valid JSON');
        }
        $params = array('id' => $this->_id, 'parameters' => $parameters);
        //Set optional request parameters
        if ($filter) {
            $params['filter'] = $filter;
        }
        if ($start) {
            $params['start'] = $start;
        }
        if ($end) {
            $params['end'] = $end;
        }
        return $this->_user->post('pylon/analyze', $params);
    }

Usage Example

Esempio n. 1
0
$user = new DataSift_User(USERNAME, API_KEY, false);
$csdl = '(fb.content any "coffee, tea" OR fb.hashtags in "tea") AND fb.language in "en"';
//Validate the CSDL
$validate = DataSift_Pylon::validate($user, $csdl);
echo "Definition has been successfully validated, DPUs: {$validate['dpu']} created at: {$validate['created_at']} \n\n";
//Create the PYLON object
$pylon_name = "My pylon test";
$pylon = new DataSift_Pylon($user);
$pylon->setName($pylon_name);
//Add CSDL to the PYLON
$pylon->setCsdl($csdl);
$pylon->compile();
//Start the pylon
$pylon->start();
//Stop after 10 seconds
sleep(10);
//Compile some new CSDL
$pylon->setCsdl('(fb.content any "coffee, tea, flour" OR fb.hashtags in "tea") AND fb.language in "en"');
$pylon->compile();
//Update the recording with the new definition
$pylon->update();
$pylon->stop();
//Set the analyze parameters
$parameters = array('analysis_type' => 'freqDist', 'parameters' => array('threshold' => 3, 'target' => 'fb.author.gender'), 'child' => array('analysis_type' => 'freqDist', 'parameters' => array('threshold' => 3, 'target' => 'fb.author.age'), 'child' => array('analysis_type' => 'freqDist', 'parameters' => array('threshold' => 3, 'target' => 'fb.author.highest_education'))));
//Choose a filter
$filter = 'fb.content contains "starbucks"';
//Analyze the recording
$analyze = $pylon->analyze($parameters, $filter);
$pylon->reload();
echo "There were a total of {$analyze['interactions']} interactions that matched this filter\n";
$reloaded_pylon = DataSift_Pylon::fromId($user, $pylon->getId());
All Usage Examples Of DataSift_Pylon::analyze