Skip to content

Commit

Permalink
rector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
indy2kro committed Jul 21, 2024
1 parent 710605f commit c881f1b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: gd

- name: Get Composer Cache Directory
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion src/NlpTools/Documents/WordDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WordDocument implements DocumentInterface

protected array $after = [];

public function __construct(array $tokens, $index, $context)
public function __construct(array $tokens, int $index, int $context)
{
$this->word = $tokens[$index];
for ($start = max($index - $context, 0); $start < $index; $start++) {
Expand Down
2 changes: 1 addition & 1 deletion src/NlpTools/Similarity/Simhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected static function md5(string $w): string
return str_replace(self::$search, self::$replace, md5($w));
}

public function __construct(protected int $length, protected $h = 'self::md5')
public function __construct(protected int $length, protected $h = [self::class, 'md5'])
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/NlpTools/Clustering/ClusteringTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getColor($t): array
/**
* Return a gd handle with a visualization of the clustering or null in case gd is not present.
*/
protected function drawClusters(TrainingSet $trainingSet, $clusters, $centroids = null, $lines = false, $emphasize = 0, $w = 300, $h = 200): null|\GdImage|false
protected function drawClusters(TrainingSet $trainingSet, $clusters, $centroids = null, $lines = false, $emphasize = 0, $w = 300, $h = 200): mixed
{
if (!function_exists('imagecreate')) {
return null;
Expand Down
4 changes: 3 additions & 1 deletion tests/NlpTools/Clustering/KmeansTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use NlpTools\Documents\EuclideanPoint;
use NlpTools\Similarity\Euclidean;
use NlpTools\Clustering\CentroidFactories\Euclidean as EuclidCF;
use PHPUnit\Framework\Attributes\Group;

class KmeansTest extends ClusteringTestBase
{
Expand All @@ -23,6 +24,7 @@ protected function setUp(): void
}
}

#[Group('Slow')]
public function testEuclideanClustering(): void
{
$kMeans = new KMeans(
Expand Down Expand Up @@ -56,7 +58,7 @@ public function testEuclideanClustering(): void
false // lines or not
);

if ($im !== null) {
if ($im !== null && $im !== false) {
imagepng($im, TEST_DATA_DIR . "/Clustering/KmeansTest/clusters.png");
}

Expand Down
13 changes: 5 additions & 8 deletions tests/NlpTools/Documents/TransformationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use NlpTools\Documents\TrainingDocument;
use NlpTools\Documents\WordDocument;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class TransformationsTest extends TestCase
{
Expand All @@ -17,9 +18,7 @@ public static function provideTokens(): array
return [[["1", "2", "3", "4", "5", "6", "7"]]];
}

/**
* @dataProvider provideTokens
*/
#[DataProvider('provideTokens')]
public function testTokensDocument(array $tokens): void
{
$tokensDocument = new TokensDocument($tokens);
Expand All @@ -42,21 +41,19 @@ public function testTokensDocument(array $tokens): void
);
}

/**
* @dataProvider provideTokens
*/
#[DataProvider('provideTokens')]
public function testWordDocument(array $tokens): void
{
$identityTransformer = new IdentityTransformer();
$wordDocument = new WordDocument($tokens, count($tokens) / 2, 2);
$wordDocument = new WordDocument($tokens, (int) (count($tokens) / 2), 2);
$correct = $wordDocument->getDocumentData();
$wordDocument->applyTransformation($identityTransformer);
$this->assertEquals(
$correct,
$wordDocument->getDocumentData()
);

$trainingDocument = new TrainingDocument("", new WordDocument($tokens, count($tokens) / 2, 2));
$trainingDocument = new TrainingDocument("", new WordDocument($tokens, (int) (count($tokens) / 2), 2));
$trainingDocument->applyTransformation($identityTransformer);
$this->assertEquals(
$correct,
Expand Down
7 changes: 3 additions & 4 deletions tests/NlpTools/Models/LdaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use NlpTools\Documents\TokensDocument;
use NlpTools\FeatureFactories\DataAsFeatures;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Group;

/**
* Functional testing of the Latent Dirichlet Allocation
Expand Down Expand Up @@ -63,10 +64,8 @@ protected function setUp(): void
$this->loadData();
}

/**
* @group Slow
* @group VerySlow
*/
#[Group('Slow')]
#[Group('VerySlow')]
public function testLda(): void
{
$lda = new Lda(
Expand Down
6 changes: 4 additions & 2 deletions tests/NlpTools/Stemmers/PorterStemmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace NlpTools\Stemmers;

use NlpTools\Stemmers\PorterStemmer;
use PHPUnit\Framework\Attributes\Group;

/**
* Check the correctness of the porter stemmer implementation
*
Expand All @@ -15,9 +18,8 @@ class PorterStemmerTest extends StemmerTestBase
/**
* Load a set of words and their stems and check if the stemmer
* produces the correct stems
*
* @group Slow
*/
#[Group('Slow')]
public function testStemmer(): void
{
$words = new \SplFileObject(TEST_DATA_DIR . '/Stemmers/PorterStemmerTest/words.txt');
Expand Down
5 changes: 2 additions & 3 deletions tests/NlpTools/Stemmers/TransformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use NlpTools\Documents\TokensDocument;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class TransformationTest extends TestCase
{
Expand All @@ -17,9 +18,7 @@ public static function provideStemmers(): array
];
}

/**
* @dataProvider provideStemmers
*/
#[DataProvider('provideStemmers')]
public function testStemmer(Stemmer $stemmer): void
{
$tokens = explode(" ", "this renowned monster who had come off victorious in a hundred fights with his pursuers was an old bull whale of prodigious size and strength from the effect of age or more probably from a freak of nature a singular consequence had resulted he was white as wool");
Expand Down

0 comments on commit c881f1b

Please sign in to comment.