Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopwords #2

Closed
emilorol opened this issue Jan 14, 2019 · 2 comments
Closed

Stopwords #2

emilorol opened this issue Jan 14, 2019 · 2 comments

Comments

@emilorol
Copy link
Contributor

Thank you for sharing your work.

How can I implement stopwords?

@noogen
Copy link
Contributor

noogen commented Jan 17, 2019

You can pass in your own tokenizer function in the constructor. Something like.

// array containing stopwords
$stopwords = array("der", "die", "das", "the");

// escape the stopword array and implode with pipe
$s = '~^\W*('.implode("|", array_map("preg_quote", $stopwords)).')\W+\b|\b\W+(?1)\W*$~i';

$options['tokenizer'] = function($text)  use ($s) {
            // convert everything to lowercase
            $text = mb_strtolower($text);

            // remove stop words
            $text = preg_replace($s, '', $text);

            // split the words
            preg_match_all('/[[:alpha:]]+/u', $text, $matches);
            // first match list of words
            return $matches[0];
        };

$classifier = new \niiknow\Bayes($options);

@emilorol
Copy link
Contributor Author

Perfect. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants