<commit_before><?php

namespace Sastrawi\Stemmer;

use Sastrawi\Dictionary\DictionaryInterface;

class Stemmer
{
    protected $dictionary;

    protected $visitors = array();

    protected $suffixVisitors = array();

    protected $prefixVisitors = array();

    public function __construct(DictionaryInterface $dictionary)
    {
        $this->dictionary = $dictionary;
        $this->initVisitors();
    }

    public function getDictionary()
    {
        return $this->dictionary;
    }

    protected function initVisitors()
    {
        $visitorProvider = new Visitor\VisitorProvider();

        $this->visitors       = $visitorProvider->getVisitors();
        $this->suffixVisitors = $visitorProvider->getSuffixVisitors();
        $this->prefixVisitors = $visitorProvider->getPrefixVisitors();
    }

    /**
     * Stem a sentence to common stem form of its words
     *
     * @param  string $sentence the sentence to stem, e.g : memberdayakan pembangunan
     * @return string common stem form, e.g : daya bangun
     */
    public function stem($sentence)
    {
        $filteredSentence = $this->filterSentence($sentence);
        
        $words = explode(' ', $filteredSentence);
        $stemmedWords = array();

        foreach ($words as $word) {
            $stemmedWords[] = $this->stemWord(strtolower($word));
        }

        return implode(' ', $stemmedWords);
    }

    /**
     * Stem a word to its common stem form
     *
     * @param  string $word the word to stem, e.g : mengalahkan
     * @return string common stem form, e.g : kalah
     */
    public function stemWord($word)
    {
        $context = new Context($word, $this->dictionary);<commit_msg>fix style stemmer<commit_after><?php

namespace Sastrawi\Stemmer;

use Sastrawi\Dictionary\DictionaryInterface;

class Stemmer
{
    protected $dictionary;

    protected $visitors = array();

    protected $suffixVisitors = array();

    protected $prefixVisitors = array();

    public function __construct(DictionaryInterface $dictionary)
    {
        $this->dictionary = $dictionary;
        $this->initVisitors();
    }

    public function getDictionary()
    {
        return $this->dictionary;
    }

    protected function initVisitors()
    {
        $visitorProvider = new Visitor\VisitorProvider();

        $this->visitors       = $visitorProvider->getVisitors();
        $this->suffixVisitors = $visitorProvider->getSuffixVisitors();
        $this->prefixVisitors = $visitorProvider->getPrefixVisitors();
    }

    /**
     * Stem a sentence to common stem form of its words
     *
     * @param  string $sentence the sentence to stem, e.g : memberdayakan pembangunan
     * @return string common stem form, e.g : daya bangun
     */
    public function stem($sentence)
    {
        $filteredSentence = $this->filterSentence($sentence);

        $words = explode(' ', $filteredSentence);
        $stemmedWords = array();

        foreach ($words as $word) {
            $stemmedWords[] = $this->stemWord(strtolower($word));
        }

        return implode(' ', $stemmedWords);
    }

    /**
     * Stem a word to its common stem form
     *
     * @param  string $word the word to stem, e.g : mengalahkan
     * @return string common stem form, e.g : kalah
     */
    public function stemWord($word)
    {
        $context = new Context($word, $this->dictionary);
{'fraction_non_alphanumeric': 0.11684460260972716, 'fraction_numerical': 0.0, 'mean_word_length': 2.599786552828175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3082043', 'n_tokens_mistral': 1013, 'n_tokens_neox': 951, 'n_words': 241}