Esempio n. 1
0
 /**
  * Stem all tokens in the input array using the Porter stemming algorithm
  * @param $tokens array of tokens to stem
  * @return array Array of the stemmed tokens
  */
 protected function stem(array $tokens)
 {
     return array_map(function ($token) {
         if (in_array($token, $this->stopWords)) {
             return $token;
         }
         return \Porter::Stem($token);
     }, $tokens);
 }
Esempio n. 2
0
 public function split_sentence_into_words($sentence)
 {
     $raw = preg_split('#\\s+#', $sentence);
     $result = [];
     foreach ($raw as $key => $word) {
         if (strlen(trim($word)) > 0) {
             $result[] = \Porter::stem($word);
         }
     }
     return $result;
 }
Esempio n. 3
0
 protected function stem(array &$tokens)
 {
     foreach ($tokens as $idx => $token) {
         if (trim($token)) {
             $tokens[$idx] = \Porter::stem($token);
         } else {
             unset($tokens[$idx]);
         }
     }
     return $tokens;
 }
Esempio n. 4
0
<?php

require 'vendor/autoload.php';
use ZendSearch\Lucene\Lucene;
use ZendSearch\Lucene\MultiSearcher;
use ZendSearch\Lucene\Search\QueryParser;
$stem = function ($e) {
    return \Porter::Stem($e);
};
$q = isset($_GET['q']) ? $_GET['q'] : null;
$q = htmlentities($q);
$q = implode('+', array_map($stem, explode(' ', $q)));
header('Content-Type: application/json');
$output = array();
if ($q) {
    $indexer = Lucene::open('../_index');
    $search = new MultiSearcher(array($indexer));
    $query = QueryParser::parse($q);
    $result = $search->find($query);
    foreach ($result as $hit) {
        $title = strtolower(str_replace('-', ' ', $hit->name));
        $resultUrl = '../' . $hit->fileName;
        $output[] = array('href' => $resultUrl, 'name' => ucfirst($title), 'preview' => $query->htmlFragmentHighlightMatches(substr(preg_replace("/\\s+|{$title}/i", " ", $hit->body), 0, 300) . '...'));
    }
}
echo json_encode($output);
Esempio n. 5
0
<?php

include 'data.php';
$exported = Porter::exportData(User::getLyrics());
?>
<html>
  <head>
    <title>The Plague's KPop Fan Page - Export Songs</title>
  </head>
  <body>
    <p>The text below are your exported songs. Just have your friend copy-paste said text into the 
      <a href="import.php">import page</a>!</p>
    <p><?php 
echo "<pre>" . $exported . "</pre>";
?>
</p>
  </body>
</html>