Skip to content

Add function splitWords() and a test for the function #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions classes/Syllable.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,26 @@ public function splitWord($word)
return $this->parseWord($word);
}

/**
* 1. Split the text into an array of words
* 2. Split the specific words into arrays of syllables
* @param string $text
* @return array
*/
public function splitWords(string $text)
{
self::initEncoding();
$this->loadLanguage();

$text = explode(' ', $text);
$words = [];
foreach ($text as $word) {
$words[] = $this->parseWord($word);
}

return $words;
}

/**
* Split a text on where the hyphenation would go.
* @param string $text
Expand Down
37 changes: 37 additions & 0 deletions tests/SyllableTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,43 @@ public function testSplitWord()
$this->assertEquals(array('In', 'ex', 'plic', 'a', 'ble'), $this->object->splitWord('Inexplicable'));
}

/**
* @covers Syllable::splitWords
* @todo Implement testSplitWord()
*/
public function testSplitWords()
{
$this->object->setHyphen('-');
$this->object->setLanguage('en-us');

$test1_array = [
0 => [
0 => ';Re',
1 => 'dun',
2 => 'dant,',
],
1 => [
3 => 'punc',
4 => 'tu',
5 => 'a',
6 => 'tion...'
]
];

$test2_array = [
0 => [
0 => 'In',
1 => 'ex',
2 => 'plic',
3 => 'a',
4 => 'ble'
]
];

$this->assertEquals($test1_array, $this->object->splitWords(';Redundant, punctuation'));
$this->assertEquals($test2_array, $this->object->splitWords('Inexplicable'));
}

/**
* @covers Syllable::splitText
* @todo Implement testSplitText().
Expand Down