public function testAllSubstrings()
 {
     $text = 'abc';
     $expected = ['a', 'ab', 'abc', 'b', 'bc', 'c'];
     $substrings = String::getAllSubStrings($text);
     $this->assertCount(6, $substrings);
     $this->assertEquals($expected, $substrings);
 }
 /**
  * Returns the Longest common substring
  * @param string $text1
  * @param string $text2
  * @return string
  */
 public function similarity($text1, $text2)
 {
     $intersection = array_intersect(String::getAllSubStrings($text1), String::getAllSubStrings($text2));
     $max = 0;
     $lcs = '';
     foreach ($intersection as $substr) {
         if (strlen($substr) > $max) {
             $max = strlen($substr);
             $lcs = $substr;
         }
     }
     return $lcs;
 }
 /**
  * @return DateTime[]
  */
 public function getDates()
 {
     // return the cached copy
     if (empty($this->dates)) {
         $getDateFunc = function ($sentence) {
             $date = String::findDate($sentence);
             return new DateTime("{$date['year']}-{$date['month']}-{$date['day']}");
         };
         $this->dates = array_map($getDateFunc, $this->sentences);
         // re-index so nulls and offsets are correct.
         $this->dates = array_values(array_filter($this->dates));
     }
     return $this->dates;
 }