Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import nltk
from unittest import TestCase
class SentenceStemmer(object):
# Example of Python-based string_types.
@classmethod
def create(cls, param):
return cls()
def __init__(self):
self._stemmer = nltk.stem.PorterStemmer()
def extract(self, text):
tokens = nltk.wordpunct_tokenize(text)
result = []
for t in tokens:
result.append((0, 0, self._stemmer.stem(t), 1.0))
return result
class SentenceStemmerTest(TestCase):
def test_extract(self):
ex = SentenceStemmer.create({})
sentence = ' The foxes JUMPED over dogs '
result = ex.extract(sentence)
self.assertEqual(['the', 'fox', 'jump', 'over', 'dog'], [x[2] for x in result])