Overview

Namespaces

  • PHP
  • Sastrawi
    • Dictionary
    • Morphology
      • Disambiguator
    • Specification
    • Stemmer
      • Cache
      • ConfixStripping
      • Context
        • Visitor
      • Filter
    • StopWordRemover

Classes

  • StopWordRemover
  • StopWordRemoverFactory
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Sastrawi\StopWordRemover;
 4: 
 5: use Sastrawi\Dictionary\DictionaryInterface;
 6: 
 7: class StopWordRemover
 8: {
 9:     /**
10:      * @var \Sastrawi\Dictionary\DictionaryInterface
11:      */
12:     protected $dictionary;
13: 
14:     public function __construct(DictionaryInterface $dictionary)
15:     {
16:         $this->dictionary = $dictionary;
17:     }
18: 
19:     /**
20:      * @return \Sastrawi\Dictionary\DictionaryInterface
21:      */
22:     public function getDictionary()
23:     {
24:         return $this->dictionary;
25:     }
26: 
27:     /**
28:      * Remove stop words.
29:      *
30:      * @param  string $text The text which stop words to be removed
31:      * @return string The text after removal
32:      */
33:     public function remove($text)
34:     {
35:         $words = explode(' ', $text);
36: 
37:         foreach ($words as $i => $word) {
38:             if ($this->dictionary->contains($word)) {
39:                 unset($words[$i]);
40:             }
41:         }
42: 
43:         return implode(' ', $words);
44:     }
45: }
46: 
API documentation generated by ApiGen 2.8.0