-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7. Add CustomSet words and phrases container + coverage
- Loading branch information
1 parent
c2fe70a
commit 5e0a8da
Showing
8 changed files
with
229 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace detox\dataset; | ||
|
||
|
||
use detox\exceptions\BadDictException; | ||
|
||
class CustomSet implements SetContract | ||
{ | ||
private $words = []; | ||
private $phrases = []; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getWords() : array | ||
{ | ||
return $this->words; | ||
} | ||
|
||
/** | ||
* @param array $words | ||
* @throws BadDictException | ||
*/ | ||
public function setWords(array $words) : void | ||
{ | ||
$this->checkDict($words); | ||
$this->words = $words; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getPhrases() : array | ||
{ | ||
return $this->phrases; | ||
} | ||
|
||
/** | ||
* @param array $phrases | ||
* @throws BadDictException | ||
*/ | ||
public function setPhrases(array $phrases) : void | ||
{ | ||
$this->checkDict($phrases); | ||
$this->phrases = $phrases; | ||
} | ||
|
||
/** | ||
* @param array $dict | ||
* @throws BadDictException | ||
*/ | ||
private function checkDict(array $dict) | ||
{ | ||
foreach ($dict as $score => $words) { | ||
if (is_numeric($score) === false) { | ||
throw new BadDictException('Keys of dict array must be string representation of float number, ex.: 0.9, 1.0 etc'); | ||
} | ||
foreach ($words as $word) { | ||
if (is_string($word) === false) { | ||
throw new BadDictException('Values in dict sub-array must be of type string'); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace detox\exceptions; | ||
|
||
|
||
class BadDictException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.