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 "ERROR: ", htmlspecialchars($s), "\r\n"; } function onDocsAutoResponse($sender, $args) { //$s = json_encode($args); //echo "DOCS AUTORESPONSE: ", htmlspecialchars($s), "\r\n"; } function onCollsAutoResponse($sender, $args) { //$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"; } }
$file = fopen("source.txt", "r"); if (!$file) { print "File not found\n"; exit(1); } while (($line = fgets($file)) !== FALSE) { $job_id = $job_ids[rand(0, $unique_jobid_count - 1)]; $jobs[$job_id] += 1; $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) {
print "Reading collection from file...\n"; $documents = array(); $file = fopen("C:\\wamp\\www\\batchJobs_2\\source.txt", "r"); if (!$file) { print ""; exit(1); } while (($line = fgets($file)) !== FALSE) { $documents[] = $line; } 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); // Queues collection for analysis using default configuration $collection_id = uniqid('', true); $status = $session->queueCollection(array('id' => $collection_id, 'documents' => $documents)); if ($status != 202 && $status != 200) { print "Error\n"; exit(1); } print "{$collection_id} collection queued successfully.\n"; // Retreives analysis results for queued collection $results = NULL; do { sleep(1);
$documents = array(); $file = fopen("source.txt", "r"); if (!$file) { print "File not found."; exit(1); } while (($line = fgets($file)) !== FALSE) { $documents[] = $line; } if (!feof($file)) { echo "Error: unexpected fgets() fail\n"; } fclose($file); $total_docs = count($documents); // 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); $configurations = $session->getConfigurations(); $primary_config = NULL; $autoresponse_config = NULL; foreach ($configurations as $configuration) { if ($configuration['is_primary']) { $primary_config = $configuration; } else { if ($configuration['name'] == 'AutoResponseTest') { $autoresponse_config = $configuration; } } }
{ //$s = json_encode($args); //echo "DOCS AUTORESPONSE: ", htmlspecialchars($s), "\r\n"; } function onCollsAutoResponse($sender, $args) { //$s = json_encode($args); //echo "COLLS AUTORESPONSE: ", htmlspecialchars($s), "\r\n"; } } function queuedComparator($value) { return $value == TASK_STATUS_QUEUED; } // 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); $subscription = $session->getSubscription(); // A dictionary that keeps IDs of sent documents and their statuses. // It's required to make sure that we get correct documents from the API. $tracker = array(); $documets = array(); print "Reading collection from file...\n"; $file = fopen("source.txt", "r"); if (!$file) { print ""; exit(1); } while (($line = fgets($file)) !== FALSE) {