This package was built mainly for academic purposes. It can be described ad an agnostic package that conforms with thephpleague.com specifications and uses the Test Driven Development process (PHPUnit)
-
Data: The main dictionary, a static associative array that contains urban words
-
Dictionary: CRUD implementations and Ranking System Implementation.
-
WordExistsException: Returns the associated exception message
-
WordNotFoundException: Returns the associated exception message
Require via composer like so:
composer require florence/dictionary
$dictionary = Data::$data;
$dictionary = new Dictionary($dictionary);
$dictionary->addSlang($slang, $description, $sentence);
$dictionary->findOne($slang);
$dictionary->findAll();
$dictionary->updateSlang($slang, $description, $sentence);
$dictionary->deleteOne($slang);
$dictionary->deleteAll();
The ranking system is implemented using the rankWords()
method.
You can now traverse through the Data array to get your desired output like so:
foreach(Data::$data as $row => $innerArray)
{
$res = $innerArray['Sample-sentence'];
$getRank = $ranker->rankAndSort($res);
$output = '';
foreach($getRank as $key => $value)
{
$output .= "$key => $value".', ';
}
$output = rtrim("[".$output,','."]")."<br>";
// print the final output
echo $output;
echo "<br>";
}
Sample Output:
[“Tight” => 3, “Prosper” => 2, “Yes” => 1, “Have” => 1, “you” => 1, “finished” => 1, “the” => 1, “curriculum?” => 1]