예제 #1
0
 private static function getPhpInsightResult($text)
 {
     $returnObj = array();
     $sentiment = new Sentiment();
     $scores = $sentiment->score($text);
     $returnObj['likelihood'] = (object) array_change_key_case($scores, CASE_UPPER);
     $returnObj['label'] = strtoupper($sentiment->categorise($text));
     return (object) $returnObj;
 }
예제 #2
0
<?php

include 'sentiment.class.php';
$sentiment = new Sentiment();
$example1 = $sentiment->categorise('Today was rubbish');
//Neg
$example2 = $sentiment->categorise('Today was amazing');
// Pos
$example3 = $sentiment->categorise('Today was ok');
// Neu
?>
<html>
<head>
</head>

<body>
  <h1>phpInsight Example</h1>

  <h2>Example 1</h2>

  <p>Today was rubbish</p>
  <p>Classification - <?php 
echo $example1;
?>
</p>

  <h2>Example 2</h2>

  <p>Today was amazing</p>
  <p>Classification - <?php 
echo $example2;
예제 #3
0
 public function getSentiments()
 {
     $connection = parent::connect();
     $selectSQL = "SELECT * FROM SENTIMENT";
     $rows = $connection->query($selectSQL);
     $sentiments = array();
     foreach ($rows as $row) {
         $sentiment = new Sentiment();
         $sentiment->setSentimentId($row[0]);
         $sentiment->setSentimentSourceName($row[1]);
         $sentiment->setSentimentSourceLink($row[2]);
         $sentiment->setSentimentSourceLinkType($row[3]);
         $sentiments[] = $sentiment;
     }
     parent::disconnect($connection);
     return $sentiments;
 }
 /**
  * Get the shared instance of Sentiment
  *
  * @return Sentiment
  **/
 public static function instance()
 {
     // Initialize shared instance.
     if (!Sentiment::$_instance) {
         Sentiment::$_instance = new Sentiment();
     }
     return Sentiment::$_instance;
 }
예제 #5
0
<?php

include 'sentiment.class.php';
$sentiment = new Sentiment();
$examples = array(1 => 'Weather today is rubbish', 2 => 'This cake looks amazing', 3 => 'His skills are mediocre', 4 => 'He is very talented', 5 => 'She is seemingly very agressive', 6 => 'Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.', 7 => 'To be or not to be?', 8 => 'What The Hell !', 9 => 'Bitch');
foreach ($examples as $key => $value) {
    echo '<div class="example">';
    echo "<h2>Example {$key}</h2>";
    echo "<blockquote>{$value}</blockquote>";
    echo "Scores: <br />";
    $scores = $sentiment->score($value);
    echo "<ul>";
    foreach ($scores as $class => $score) {
        $string = "{$class} -- <i>{$score}</i>";
        if ($class == $sentiment->categorise($value)) {
            $string = "<b class=\"{$class}\">{$string}</b>";
        }
        echo "<ol>{$string}</ol>";
    }
    echo "</ul>";
    echo '</div>';
}
echo "Process Completed";
예제 #6
0
			}
			.pos {
				color:green;
			}
			.neg {
				color:red;
			}
			
		</style>
	</head>

	<body>
		<h1>phpInsight Example</h1>

		<?php 
$sentiment = new Sentiment();
$examples = array(1 => 'Weather today is rubbish', 2 => 'This cake looks amazing', 3 => 'His skills are mediocre', 4 => 'He is very talented', 5 => 'She is seemingly very agressive', 6 => 'Marie was enthusiastic about the upcoming trip. Her brother was also passionate about her leaving - he would finally have the house for himself.', 7 => 'To be or not to be?');
foreach ($examples as $key => $example) {
    echo '<div class="example">';
    echo "<h2>Example {$key}</h2>";
    echo "<blockquote>{$example}</blockquote>";
    echo "Scores: <br />";
    $scores = $sentiment->score($example);
    echo "<ul>";
    foreach ($scores as $class => $score) {
        $string = "{$class} -- <i>{$score}</i>";
        if ($class == $sentiment->categorise($example)) {
            $string = "<b class=\"{$class}\">{$string}</b>";
        }
        echo "<ol>{$string}</ol>";
    }
예제 #7
0
<?php

require_once "SentimentPDO.php";
require_once "Sentiment.php";
if (isset($_POST['submit'])) {
    $sentimentid = $_POST["sentimentid"];
    $sentimentsourcename = $_POST["sentimentsourcename"];
    // echo $username . "<br>\n";
    $sentimentsourcelink = $_POST["sentimentsourcelink"];
    //echo $password ."<br>\n";
    $sentimentsourcelinktype = $_POST["sentimentsourcelinktype"];
    if ($sentimentsourcename != '' && $sentimentsourcelink != '' && $sentimentsourcelinktype != '') {
        $sentimentPDO = new SentimentPDO();
        $sentiment = new Sentiment();
        $sentiment->setSentimentId($sentimentid);
        $sentiment->setSentimentSourceName($sentimentsourcename);
        $sentiment->setSentimentSourceLink($sentimentsourcelink);
        $sentiment->setSentimentSourceLinkType($sentimentsourcelinktype);
        $sentimentPDO->updateSentiment($sentiment);
        echo "<html>";
        echo "<head>";
        echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' >";
        echo "<link rel='stylesheet' type='text/css' href='menu.css'>";
        echo "<title>News Portal - Update Sentiment Source</title>";
        echo "</head>";
        echo "<body>";
        include "menu.php";
        echo "Updated a Sentiment Source </br>";
        echo "<a href='Home.php'> Back to Home</a>";
        echo "</body>";
        echo "</html";
예제 #8
0
<?php

require_once "SentimentPDO.php";
require_once "Sentiment.php";
if (isset($_POST['submit'])) {
    $sentimentsourcename = $_POST["sentimentsourcename"];
    // echo $username . "<br>\n";
    $sentimentsourcelink = $_POST["sentimentsourcelink"];
    //echo $password ."<br>\n";
    $sentimentsourcelinktype = $_POST["sentimentsourcelinktype"];
    if ($sentimentsourcename != '' && $sentimentsourcelink != '' && $sentimentsourcelinktype != '') {
        $sentimentPDO = new SentimentPDO();
        $sentiment = new Sentiment();
        $sentiment->setSentimentSourceName($sentimentsourcename);
        $sentiment->setSentimentSourceLink($sentimentsourcelink);
        $sentiment->setSentimentSourceLinkType($sentimentsourcelinktype);
        $sentimentPDO->insertSentiment($sentiment);
        echo "<html>";
        echo "<head>";
        echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' >";
        echo "<link rel='stylesheet' type='text/css' href='menu.css'>";
        echo "<title>News Portal - Insert Sentiment Source</title>";
        echo "</head>";
        echo "<body>";
        include "menu.php";
        echo "Created a Sentiment Source </br>";
        echo "<a href='index.php'> Back to Home</a>";
        echo "</body>";
        echo "</html";
    } else {
        echo "Please fill all of the fields" . "<br>\n";