app/django/utils/stopwords.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Wed, 01 Oct 2008 09:43:25 +0000
changeset 244 da80c6519eea
parent 54 03e267d67478
permissions -rw-r--r--
Fixed models based on output from graph.py script and comments on http://groups.google.com/group/melange-soc-dev/browse_thread/thread/fb532a7db1f19ea7

# Performance note: I benchmarked this code using a set instead of
# a list for the stopwords and was surprised to find that the list
# performed /better/ than the set - maybe because it's only a small
# list.

stopwords = '''
i
a
an
are
as
at
be
by
for
from
how
in
is
it
of
on
or
that
the
this
to
was
what
when
where
'''.split()

def strip_stopwords(sentence):
    "Removes stopwords - also normalizes whitespace"
    words = sentence.split()
    sentence = []
    for word in words:
        if word.lower() not in stopwords:
            sentence.append(word)
    return u' '.join(sentence)