Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7d00848

Browse files
committed
now supports PHP 8.0
1 parent 9ddbc75 commit 7d00848

File tree

6 files changed

+51
-28
lines changed

6 files changed

+51
-28
lines changed

‎Dockerfile80

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM php:8.0-cli
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends zip libzip-dev libpspell-dev && \
5+
docker-php-ext-install zip pspell
6+
7+
RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
8+
9+
RUN mkdir -p /app
10+
11+
COPY ./ /app
12+
13+
RUN composer --working-dir=/app install
14+
15+
RUN cd /app && SKIP_TEST=1 ./vendor/bin/phpunit -d memory_limit=1G
16+
17+
CMD ["/bin/sh"]

‎composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"files": ["tests/TestBaseCase.php"]
2121
},
2222
"require" : {
23-
"php": "~7.4",
23+
"php": "~7.4|~8.0",
2424
"yooper/stop-words": "~1",
2525
"symfony/console": ">= 4.4",
2626
"wamania/php-stemmer": "~1",

‎src/Adapters/PspellAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PspellAdapter implements ISpelling
1313
{
1414
protected $pSpell = null;
1515

16-
public function __construct($language = 'en', $spelling = "", $jargon = "", $encoding = "", $mode = PSPELL_BAD_SPELLERS )
16+
public function __construct($language = 'en', $spelling = "", $jargon = "", $encoding = "", $mode = \PSPELL_BAD_SPELLERS )
1717
{
1818
$this->pSpell = pspell_new($language, $spelling, $jargon, $encoding, $mode);
1919
}

‎src/Sentiment/Vader.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,19 @@ public function __construct()
8383
* Add a new token and score to the lexicon
8484
* @param string $token
8585
* @param float $meanSentimentRating
86+
* @return void
8687
*/
87-
public function addToLexicon(string $token, float $meanSentimentRating)
88+
public function addToLexicon(string $token, float $meanSentimentRating) : void
8889
{
8990
$this->lexicon[$token] = $meanSentimentRating;
9091
}
9192

9293
/**
9394
* Remove a token from the lexicon
9495
* @param string $token
96+
* @return void
9597
*/
96-
public function deleteFromLexicon(string $token)
98+
public function deleteFromLexicon(string $token) : void
9799
{
98100
unset($this->lexicon[$token]);
99101
}
@@ -124,12 +126,13 @@ public function isNegated(array $tokens, bool $includeNt = true) : bool
124126
* approximates the max expected value
125127
* @param float $score
126128
* @param int $alpha
129+
* @return float
127130
*/
128-
public function normalize(float $score, int $alpha=15)
131+
public function normalize(float $score, int $alpha=15) : float
129132
{
130133
$normalizedScore = $score;
131134

132-
if (sqrt(($score^2) + $alpha > 0)) {
135+
if (sqrt(($score^2) + $alpha) > 1) {
133136
$normalizedScore = $score/sqrt(($score^2) + $alpha);
134137
}
135138

@@ -178,7 +181,7 @@ public function scalarIncDec(string $word, float $valence, bool $isCapDiff)
178181
public function getPolarityScores(array $tokens) : array
179182
{
180183
$sentiments = [];
181-
for($index = 0; $index < count($tokens); $index++)
184+
for($index = 0, $indexMax = count($tokens); $index < $indexMax; $index++)
182185
{
183186
$valence = 0.0;
184187
$lcToken = strtolower($tokens[$index]);
@@ -196,7 +199,7 @@ public function getPolarityScores(array $tokens) : array
196199
return $this->scoreValence($sentiments, $tokens);
197200
}
198201

199-
public function scoreValence(array $sentiments, array $tokens)
202+
public function scoreValence(array $sentiments, array $tokens): array
200203
{
201204
if ( !empty($sentiments)) {
202205
$sentimentSum = array_sum($sentiments);
@@ -247,7 +250,7 @@ public function getSentimentValence(float $valence, array $tokens, int $index)
247250
if(isset($this->getLexicon()[$lcToken]))
248251
{
249252
//get the sentiment valence
250-
$valence = $this->getLexicon()[$lcToken];
253+
$valence = (float)$this->getLexicon()[$lcToken];
251254
//check if sentiment laden word is in ALL CAPS (while others aren't)
252255
if ($ucToken and $isCapDiff) {
253256
if ($valence > 0) {
@@ -262,17 +265,17 @@ public function getSentimentValence(float $valence, array $tokens, int $index)
262265
if ($index > $startIndex && !isset($this->getLexicon()[ strtolower($tokens[$index-($startIndex+1)])]))
263266
{
264267
// dampen the scalar modifier of preceding words and emoticons
265-
// (excluding the ones that immediately preceed the item) based
268+
// (excluding the ones that immediately preceded the item) based
266269
// on their distance from the current item.
267270
$s = $this->scalarIncDec($tokens[$index-($startIndex+1)], $valence, $isCapDiff);
268-
if ($startIndex == 1 and $s != 0) {
271+
if ($startIndex === 1 and $s !== 0) {
269272
$s *= 0.95;
270-
} elseif ($startIndex == 2 and $s != 0 ) {
273+
} elseif ($startIndex === 2 and $s !== 0 ) {
271274
$s *= 0.9;
272275
}
273276
$valence += $s;
274277
$valence = $this->neverCheck($valence, $tokens, $startIndex, $index);
275-
if ($startIndex == 2) {
278+
if ($startIndex === 2) {
276279
$valence = $this->idiomsCheck($valence, $tokens, $index);
277280
}
278281

@@ -283,7 +286,7 @@ public function getSentimentValence(float $valence, array $tokens, int $index)
283286
// "cooking with gas": 2, "in the black": 2, "in the red": -2,
284287
// "on the ball": 2,"under the weather": -2}
285288
}
286-
$valence = $this->leastCheck($valence, $tokens, $index);
289+
$valence = $this->leastCheck((float)$valence, $tokens, $index);
287290
}
288291

289292
}
@@ -356,7 +359,7 @@ public function butCheck(array $tokens, array $sentiments)
356359
return $sentiments;
357360
}
358361

359-
for($i = 0; $i < count($sentiments); $i++)
362+
for($i = 0, $iMax = count($sentiments); $i < $iMax; $i++)
360363
{
361364
if( $index < $i) {
362365
$sentiments[$i] *= 0.5;
@@ -444,7 +447,7 @@ public function boostExclamationPoints(array $tokens) : float
444447
return 0.0;
445448
}
446449

447-
public function neverCheck(float $valence, array $tokens, int $startIndex, int $index)
450+
public function neverCheck(float $valence, array $tokens, int $startIndex, int $index): float
448451
{
449452
if($startIndex == 0 && $this->isNegated([$tokens[$index-1]])) {
450453
$valence *= self::N_SCALAR;
@@ -460,8 +463,8 @@ public function neverCheck(float $valence, array $tokens, int $startIndex, int $
460463
$valence *= self::N_SCALAR;
461464
}
462465
} elseif($startIndex == 2) {
463-
if ($tokens[$index-3] == "never" &&
464-
($tokens[$index-2] == "so" || $tokens[$index-2] == "this") ||
466+
if (($tokens[$index - 3] == "never" &&
467+
($tokens[$index - 2] == "so" || $tokens[$index - 2] == "this")) ||
465468
($tokens[$index-1] == "so" || $tokens[$index-1] == "this")) {
466469

467470
$valence *= 1.25;
@@ -487,9 +490,12 @@ public function boostQuestionMarks(array $tokens) : float
487490
}
488491
}
489492
return 0.0;
490-
}
491-
492-
493+
}
494+
495+
496+
/**
497+
* @throws \Exception
498+
*/
493499
protected function getTxtFilePath() : string
494500
{
495501
return get_storage_path('sentiment'.DIRECTORY_SEPARATOR.'vader_lexicon').DIRECTORY_SEPARATOR.'vader_lexicon.txt';

‎tests/TextAnalysis/Analysis/Keywords/RakeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function testRake()
2727
$tokens = (new GeneralTokenizer("\n\t\r"))->tokenize($testData);
2828
$tokenDoc = new TokensDocument($tokens);
2929
$tokenDoc->applyTransformation(new LowerCaseFilter())
30-
->applyTransformation(new StopWordsFilter($stopwords), false)
31-
->applyTransformation(new PunctuationFilter(['@',':','\/']), false)
32-
->applyTransformation(new CharFilter(), false);
30+
->applyTransformation(new StopWordsFilter($stopwords), true)
31+
->applyTransformation(new PunctuationFilter(['@',':','\/']), true)
32+
->applyTransformation(new CharFilter(), true);
3333

3434
$rake = new Rake($tokenDoc, 3);
3535
$results = $rake->getKeywordScores();
@@ -46,9 +46,9 @@ public function testSimplifiedRake()
4646
$tokens = (new GeneralTokenizer("\n\t\r"))->tokenize($testData);
4747
$tokenDoc = new TokensDocument($tokens);
4848
$tokenDoc->applyTransformation(new LowerCaseFilter())
49-
->applyTransformation(new StopWordsFilter($stopwords), false)
50-
->applyTransformation(new PunctuationFilter(['@',':','\/']), false)
51-
->applyTransformation(new CharFilter(), false);
49+
->applyTransformation(new StopWordsFilter($stopwords), true)
50+
->applyTransformation(new PunctuationFilter(['@',':','\/']), true)
51+
->applyTransformation(new CharFilter(), true);
5252

5353
$rake = rake($tokenDoc->toArray(), 3);
5454
$results = $rake->getKeywordScores();

‎tests/TextAnalysis/Sentiment/VaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testGetLexicon()
1919
}
2020

2121
$vader = new Vader;
22-
$this->assertCount(7503, $vader->getLexicon());
22+
$this->assertCount(7502, $vader->getLexicon());
2323
}
2424

2525
public function testAllCapDifferential()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /