Skip to content

Commit

Permalink
ok this should do it for this one
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 31, 2023
1 parent ba87f8a commit 6cfc061
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/LarachainTokenCount.php
Expand Up @@ -4,15 +4,16 @@

class LarachainTokenCount
{

public function count(string $text) : int {
public function count(string $text): int
{
/**
* Per ChatGPT suggestion 🙏
*/
$words = preg_split('/\s+/', $text);
$wordCount = count($words);
$spaceCount = substr_count($text, ' ');
$punctuationCount = substr_count($text, '.');

return $wordCount + $spaceCount + $punctuationCount;
}
}
2 changes: 1 addition & 1 deletion tests/LarachainTokenCountTest.php
Expand Up @@ -3,7 +3,7 @@
use SundanceSolutions\LarachainTokenCount\Facades\LarachainTokenCount;

it('can count tokens', function () {
$text = "Your document text...";
$text = 'Your document text...';
$results = LarachainTokenCount::count($text);
expect($results)->toEqual(8);
});

0 comments on commit 6cfc061

Please sign in to comment.