function analyzeProjectData($initialTexts) { // Initializes new session with the serializer object and the keys. $session = new \Semantria\Session(CONSUMER_KEY, CONSUMER_SECRET, NULL, NULL, TRUE); // Initialize session callback handler $callback = new SessionCallbackHandler(); $session->setCallbackHandler($callback); foreach ($initialTexts as $text) { // Creates a sample document which need to be processed on Semantria // Unique document ID // Source text which need to be processed $commentsText = $this->clean_view($text["comments"]); if ($text["comments"] != null && $text["comments"] != "") { $doc = array("id" => $text["id"] . "____" . $text["project_id"], "text" => $commentsText); // Queues document for processing on Semantria service $status = $session->queueDocument($doc); // Check status from Semantria service if ($status == 202) { echo "Document ", $doc["id"], " queued successfully.", "\r\n"; } } } // Count of the sample documents which need to be processed on Semantria $length = count($initialTexts); $results = array(); $sementriaTimes = 0; //while (count($results) < $length) { echo "Please wait 10 sec for documents ...", "\r\n"; // As Semantria isn't real-time solution you need to wait some time before getting of the processed results // In real application here can be implemented two separate jobs, one for queuing of source data another one for retreiving // Wait ten seconds while Semantria process queued document sleep(10); $sementriaTimes .= $sementriaTimes + 1; // Requests processed results from Semantria service $status = $session->getProcessedDocuments(); // Check status from Semantria service if (is_array($status)) { $results = array_merge($results, $status); } if ($sementriaTimes > 2) { $length = count($results); } echo count($status), " documents received successfully.", "\r\n"; //} $analyzedArray = array(); foreach ($results as $data) { // Printing of document sentiment score //echo "Document ", $data["id"], " Sentiment score: ", $data["sentiment_score"], "\r\n"; $analyzedArray[] = array('id' => $data["id"], 'score' => $data["sentiment_score"]); } return $analyzedArray; }
//$s = json_encode($args); //echo "COLLS AUTORESPONSE: ", htmlspecialchars($s), "\r\n"; } } // Initializes new session with the serializer object and the keys. $session = new \Semantria\Session(CONSUMER_KEY, CONSUMER_SECRET, NULL, NULL, TRUE); // Initialize session callback handler $callback = new SessionCallbackHandler(); $session->setCallbackHandler($callback); foreach ($initialTexts as $text) { // Creates a sample document which need to be processed on Semantria // Unique document ID // Source text which need to be processed $doc = array("id" => uniqid(''), "text" => $text); // Queues document for processing on Semantria service $status = $session->queueDocument($doc); // Check status from Semantria service if ($status == 202) { echo "Document ", $doc["id"], " queued successfully.", "\r\n"; } } // Count of the sample documents which need to be processed on Semantria $length = count($initialTexts); $results = array(); while (count($results) < $length) { echo "Please wait 10 sec for documents ...", "\r\n"; // As Semantria isn't real-time solution you need to wait some time before getting of the processed results // In real application here can be implemented two separate jobs, one for queuing of source data another one for retreiving // Wait ten seconds while Semantria process queued document sleep(20); // Requests processed results from Semantria service
$job_documents[$job_id][] = array('id' => uniqid('', TRUE), 'text' => $line, 'job_id' => $job_id); } if (!feof($file)) { echo "Error: unexpected fgets() fail\n"; } fclose($file); // Initializes new session with the serializer object and the keys. $session = new \Semantria\Session(CONSUMER_KEY, CONSUMER_SECRET, NULL, NULL, TRUE); // Initialize session callback handler $callback = new SessionCallbackHandler(); $session->setCallbackHandler($callback); switch ($data_sending_mode) { case 0: foreach ($job_documents as $job_id => $documents) { foreach ($documents as $document) { $session->queueDocument($document); } $length = count($document); print "{$length} documents queued for {$job_id} job ID\n"; } break; case 1: foreach ($job_documents as $job_id => $documents) { $session->queueBatch($documents); $length = count($documents); print "{$length} documents queued for {$job_id} job ID\n"; } break; default: $full_batch = array(); foreach ($job_documents as $job_id => $documents) {
} else { if ($configuration['name'] == 'AutoResponseTest') { $autoresponse_config = $configuration; } } } if ($autoresponse_config == NULL) { $session->addConfigurations(array(array('name' => 'AutoResponseTest', 'language' => 'English', 'is_primary' => TRUE, 'auto_response' => TRUE))); } else { $autoresponse_config['is_primary'] = TRUE; $session->updateConfigurations(array($autoresponse_config)); } // Queues documents for analysis one by one $doc_counter = 0; foreach ($documents as $doc) { $session->queueDocument(array('id' => uniqid('', TRUE), 'text' => $doc)); $doc_counter += 1; usleep(100000); $results_len = count($results); print "Documents queued/received rate: {$doc_counter}/{$results_len}\n"; } // The final call to get remained data from server, Just for demo purposes. sleep(1); while (count($results) < count($documents)) { $result = $session->getProcessedDocuments(); foreach ($result as $item) { $results[] = $item; } usleep(500000); } $results_len = count($results);