Exemple #1
0
<?php

include 'Opinion.php';
$op = new Opinion();
$op->addToIndex(__DIR__ . '/rt-polarity.neg', 'neg');
$op->addToIndex(__DIR__ . '/rt-polarity.pos', 'pos');
$text = "did we really act this way twenty years ago ? of course not";
$sentences = explode(".", $text);
$score = array('pos' => 0, 'neg' => 0);
foreach ($sentences as $sentence) {
    if (strlen(trim($sentence))) {
        $polarity = $op->classify($sentence);
        $score[$polarity]++;
    }
}
var_dump($score);
//$string = "This movie was noting else but a huge disappointment.";
//echo "Classifying '$string' - " . $op->classify($string) . "\n";
//$string = "Twilight was an atrocious movie, filled with stumbling, awful dialogue, and ridiculous story telling.";
//echo "Classifying '$string' - " . $op->classify($string) . "\n";
//$string = "Loving this wheater";
//echo "Classifying '$string' - " . $op->classify($string) . "\n";
Exemple #2
0
<?php

require_once __DIR__ . '/Opinion.php';
$op = new Opinion();
$op->addToIndex(__DIR__ . '/opinion/rt-polaritydata/rt-polarity.neg', 'neg');
$op->addToIndex(__DIR__ . '/opinion/rt-polaritydata/rt-polarity.pos', 'pos');
$string = "Avatar had a surprisingly decent plot, and genuinely incredible special effects";
echo "Classifying '{$string}' - " . $op->classify($string) . "\n";
$string = "Twilight was an atrocious movie, filled with stumbling, awful dialogue, and ridiculous story telling.";
echo "Classifying '{$string}' - " . $op->classify($string) . "\n";
$string = "Loving this wheater";
echo "Classifying '{$string}' - " . $op->classify($string) . "\n";
echo "<div id='guion'><span>" . $nom . "</span></div>";
//echo '<a href="../guion-vis.html">Generar visualización</a>';
echo "<input type='submit' id='loadVis' value='Cargar seleccionado'>";
$pelicula = new SimpleXMLElement($nom, null, true);
// colores base
$colorNegativo = "#FF0000";
$colorPositivo = "#00FF00";
$util = new Util();
//PERSONAJES
$personajes = [];
foreach ($pelicula->chars->char as $char) {
    array_push($personajes, $char->attributes()['name']);
}
//print_r($personajes);
$op = new Opinion();
$op->addToIndex('opinion/rt-polaritydata/rt-polarity.neg', 'neg');
$op->addToIndex('opinion/rt-polaritydata/rt-polarity.pos', 'pos');
$ruta = 'opinion/rt-polaritydata/neg/';
//recorremos el directorio de neg
if ($dir = opendir($ruta)) {
    while (($archivo = readdir($dir)) !== false) {
        if (!is_dir($archivo)) {
            $archivoRutaCompleta = $ruta . $archivo;
            $op->addToIndex($archivoRutaCompleta, 'neg');
        }
    }
}
$ruta = 'opinion/rt-polaritydata/pos/';
//recorremos el directorio de pos
if ($dir = opendir($ruta)) {
    while (($archivo = readdir($dir)) !== false) {
Exemple #4
0
                $classScores[$class] *= ($count + 1) / ($this->classTokCounts[$class] + $this->tokCount);
            }
            $classScores[$class] = $this->prior[$class] * $classScores[$class];
        }
        arsort($classScores);
        return key($classScores);
    }
    private function tokenise($document)
    {
        $document = strtolower($document);
        preg_match_all('/\\w+/', $document, $matches);
        return $matches[0];
    }
}
$op = new Opinion();
$op->addToIndex('neg_trainset.txt', 'neg');
$op->addToIndex('pos_trainset.txt', 'pos');
$utf_path = "./OpinionsUTF";
//Optional
$xmlPath = './OpinionsXML';
//Optional
$TP = 0;
$TN = 0;
$FP = 0;
$FN = 0;
$boc = 1;
print "Loading opinions list...";
$ar1 = array();
$hndIn1 = fopen("op_utf_diff.lst", "r");
while (($buffer = fgets($hndIn1, 4096)) !== false) {
    $buffer = trim($buffer);