Skip to content

Commit b436f21

Browse files
committed
bug fixes
1 parent 892d543 commit b436f21

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/Sentiment/Vader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ public function idiomsCheck(float $valence, array $tokens, int $index)
285285
*/
286286
public function leastCheck(float $valence, array $tokens, int $index) : float
287287
{
288+
if($index === 0) {
289+
return $valence;
290+
}
291+
288292
$inLexicon = isset($this->getLexicon()[strtolower($tokens[$index-1])]);
289293

290294
if($inLexicon) {

src/helpers/storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
function get_storage_path( $subDirName = null )
88
{
9-
$path = dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR;
9+
$path = 'storage' . DIRECTORY_SEPARATOR;
1010

1111
if ( ! empty( $path ) ) {
1212
$path .= $subDirName;

tests/TextAnalysis/Sentiment/VaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
class VaderTest extends \PHPUnit_Framework_TestCase
1212
{
13+
1314
public function testGetLexicon()
1415
{
1516
if( getenv('SKIP_TEST')) {
@@ -105,5 +106,12 @@ public function testGetPolarityScores()
105106
}
106107

107108
}
109+
110+
public function testIssue44OffsetError()
111+
{
112+
$vader = new Vader;
113+
$result = $vader->getPolarityScores([ 'great', 'for', 'the', 'jawbone']);
114+
$this->assertEquals(0.577, $result['pos']);
115+
}
108116

109117
}

textconsole

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?php
33
// application.php
44

5-
require __DIR__.'/vendor/autoload.php';
5+
require 'vendor/autoload.php';
66

77
use TextAnalysis\Console\Commands\NltkPackageListCommand;
88
use TextAnalysis\Console\Commands\NltkPackageInstallCommand;
@@ -19,4 +19,4 @@ $app->add(new StopWordsCommand());
1919
$app->add(new VocabSizeCommand());
2020
$app->add(new NltkPackageInstallAllCommand());
2121

22-
$app->run();
22+
$app->run();

0 commit comments

Comments
 (0)