PHP code example of celestial / lexicology

1. Go to this page and download the library: Download celestial/lexicology library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

celestial / lexicology example snippets




  use Celestial\Lexicology\Suggestion;
  
  $suggestionOptions = [
    'string',  
    'new string',  
    'value',  
    'variable'  
  ];
  
  $suggestion = new Suggestion();
  $suggestions = $suggestion->getSuggestions('string', $suggestionOptions);
  
  print_r($suggestions);
  
//Array
//(
//    [0] => string
//    [1] => new string
//)




  use Celestial\Lexicology\Suggestion;
  
  $suggestionOptions = [
    'string',  
    'new string',  
    'value',  
    'variable'  
  ];
  
  $suggestion = new Suggestion();
  $suggestions = $suggestion->getSingleSuggestion('string', $suggestionOptions);
  print_r($suggestions);
    // ['string']


    use Celestial\Lexicology\Suggestion;
    $suggestion = new Suggestion();
    $suggestions = $suggestion->getSingleSuggestion('string',[], null, 'meta');
    print_r($suggestions);
    // ['meta']


  use Celestial\Lexicology\Method\AbstractMethod;
  use Celestial\Lexicology\Method\Interfaces\FilterInterface;
  use Celestial\Lexicology\Method\Interfaces\SortInterface;
  
  class CustomMethod extends AbstractMethod implements SortInterface, FilterInterface
  {
      use \Celestial\Lexicology\Method\Traits\SortTrait;
      
      /**
       * Return a sort value if either a or b match.
       * 
       * @inheritdoc 
       */
      public function sortPair($a, $b) {
        if ($a === $b) {
            return 0;
        } elseif ($a === $this->getField()) {
            return 1;
        } elseif ($b === $this->getField()) {
            return -1;
        }
        return null;
      }
      
      /**
       * Return a filter array of string that have more than 5 characters
       * 
       * @inheritdoc
       */
      public function filter($possibleValues) {
        return array_values(array_filter($possibleValues, function($value){
            return (strlen($value) > 5);
        }));
      }
  
  }




  use Celestial\Lexicology\Suggestion;
  use Lexicology\Test\Method\CustomMethod;
  
  $suggestionOptions = [
    'string',  
    'strings',  
    'new string',  
    'value',  
    'variable'  
  ];
  
  $suggestion = new Suggestion();
  $suggestions = $suggestion->getSuggestions('string', $suggestionOptions, CustomMethod::class);
  
  print_r($suggestions);
  
//Array
//(
//    [0] => new string
//    [1] => strings
//    [2] => variable
//    [3] => string
//)