Overview

Namespaces

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

Classes

  • ArrayDictionary

Interfaces

  • DictionaryInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Sastrawi (https://github.com/sastrawi/sastrawi)
 4:  *
 5:  * @link      http://github.com/sastrawi/sastrawi for the canonical source repository
 6:  * @license   https://github.com/sastrawi/sastrawi/blob/master/LICENSE The MIT License (MIT)
 7:  */
 8: 
 9: namespace Sastrawi\Dictionary;
10: 
11: /**
12:  * Implementation of the DictionaryInterface using Array
13:  */
14: class ArrayDictionary implements DictionaryInterface
15: {
16:     /**
17:      * @var string[]
18:      */
19:     protected $words = array();
20: 
21:     public function __construct(array $words = array())
22:     {
23:         $this->addWords($words);
24:     }
25: 
26:     /**
27:      * {@inheritdoc}
28:      */
29:     public function contains($word)
30:     {
31:         return isset($this->words[$word]);
32:     }
33: 
34:     /**
35:      * {@inheritdoc}
36:      */
37:     public function count()
38:     {
39:         return count($this->words);
40:     }
41: 
42:     /**
43:      * Add multiple words to the dictionary
44:      *
45:      * @param  array $words
46:      * @return void
47:      */
48:     public function addWords(array $words)
49:     {
50:         foreach ($words as $word) {
51:             $this->add($word);
52:         }
53:     }
54: 
55:     /**
56:      * Add a word to the dictionary
57:      *
58:      * @param  string $word
59:      * @return void
60:      */
61:     public function add($word)
62:     {
63:         if ($word === '') {
64:             return;
65:         }
66: 
67:         $this->words[$word] = $word;
68:     }
69: }
70: 
API documentation generated by ApiGen 2.8.0