Skip to content

Commit

Permalink
add arabic stopwords list / fix issue ArabicStemmer AttributeError nl…
Browse files Browse the repository at this point in the history
  • Loading branch information
greenat92 committed Oct 13, 2017
1 parent 0477ceb commit 2414fbc
Show file tree
Hide file tree
Showing 2 changed files with 255 additions and 3 deletions.
7 changes: 5 additions & 2 deletions nltk/stem/snowball.py
Expand Up @@ -31,7 +31,7 @@
from nltk import compat
from nltk.corpus import stopwords
from nltk.stem import porter
from nltk.stem.util import suffix_replace, prefix_replace
from nltk.stem.util import suffix_replace, prefix_replace, arabic_stopwords

from nltk.stem.api import StemmerI

Expand Down Expand Up @@ -516,7 +516,7 @@ def __Suffix_Verb_Step1(self, token):

def __Suffix_Verb_Step2a(self, token):
for suffix in self.__suffix_verb_step2a:
if token.endswith(suffix):
if token.endswith(suffix) and len(token) > 3:
if suffix == '\u062a' and len(token) >= 4:
token = token[:-1]
self.suffix_verb_step2a_success = True
Expand Down Expand Up @@ -744,6 +744,9 @@ def stem(self, word):
self.prefix_step3a_noun_success = False
self.prefix_step3b_noun_success = False

# Avoid stopwords
if word in arabic_stopwords:
return word
modified_word = word
# guess type and properties
# checks1
Expand Down
251 changes: 250 additions & 1 deletion nltk/stem/util.py
Expand Up @@ -19,4 +19,253 @@ def prefix_replace(original, old, new):
:param new: string
:return: string
"""
return new + original[len(old):]
return new + original[len(old):]

arabic_stopwords = ['إذ',
'إذا',
'إذما',
'إذن',
'أف',
'أقل',
'أكثر',
'ألا',
'إلا',
'التي',
'الذي',
'الذين',
'اللاتي',
'اللائي',
'اللتان',
'اللتيا',
'اللتين',
'اللذان',
'اللذين',
'اللواتي',
'إلى',
'إليك',
'إليكم',
'إليكما',
'إليكن',
'أم',
'أما',
'إما',
'أن',
'إن',
'إنا',
'أنا',
'أنت',
'أنتم',
'أنتما',
'أنتن',
'إنما',
'إنه',
'أنى',
'أنى',
'آه',
'آها',
'أو',
'أولاء',
'أولئك',
'أوه',
'آي',
'أي',
'أيها',
'إي',
'أين',
'أين',
'أينما',
'إيه',
'بخ',
'بس',
'بعد',
'بعض',
'بك',
'بكم',
'بكم',
'بكما',
'بكن',
'بل',
'بلى',
'بما',
'بماذا',
'بمن',
'بنا',
'به',
'بها',
'بهم',
'بهما',
'بهن',
'بي',
'بين',
'بيد', # though
'تلك',
'تلكم',
'تلكما',
'ته',
'تي',
'تين',
'تينك',
'ثم',
'ثمة',
'حاشا',
'حبذا',
'حتى',
'حيث',
'حيثما',
'حين',
'خلا',
'دون',
'ذا',
'ذات',
'ذاك',
'ذان',
'ذانك',
'ذلك',
'ذلكم',
'ذلكما',
'ذلكن',
'ذه',
'ذو',
'ذوا',
'ذواتا',
'ذواتي',
'ذي',
'ذين',
'ذينك',
'ريث',
'سوف',
'سوى', # except
'شتان',
'عدا',
'عسى',
'عل',
'على',
'عليك',
'عليه',
'عما',
'عن',
'عند',
'غير', # except
'فإذا',
'فإن',
'فلا',
'فمن',
'في',
'فيم',
'فيما',
'فيه',
'فيها',
'قبل',
'قد',
'كأن',
'كأنما',
'كأي',
'كأين',
'كذا',
'كذلك',
'كل',
'كلا',
'كلاهما',
'كلتا',
'كلما',
'كليكما',
'كليهما',
'كم',
'كما',
'كي',
'كيت',
'كيف',
'كيفما',
'لا',
'لاسيما',
'لدى',
'لست',
'لستم',
'لستما',
'لستن',
'لسن',
'لسنا',
'لعل',
'لك',
'لكم',
'لكما',
'لكن',
'لكنما',
'لكي',
'لكيلا',
'لم',
'لما',
'لن',
'لنا',
'له',
'لها',
'لهم',
'لهما',
'لهن',
'لو',
'لولا',
'لوما',
'لي',
'لئن',
'ليت',
'ليس',
'ليسا',
'ليست',
'ليستا',
'ليسوا',
'ما',
'ماذا',
'متى', # when
'مذ',
'مع',
'مما',
'ممن',
'من',
'منه',
'منها',
'منذ',
'مه',
'مهما',
'نحن',
'نحو',
'نعم',
'ها',
'هاتان',
'هاته',
'هاتي',
'هاتين',
'هاك',
'هاهنا',
'هذا',
'هذان',
'هذه',
'هذي',
'هذين',
'هكذا',
'هل',
'هلا',
'هم',
'هما',
'هن',
'هنا',
'هناك',
'هنالك',
'هو',
'هؤلاء',
'هي',
'هيا',
'هيت',
'هيهات',
'والذي',
'والذين',
'وإذ',
'وإذا',
'وإن',
'ولا',
'ولكن',
'ولو',
'وما',
'ومن',
'وهو',
'يا'
]

0 comments on commit 2414fbc

Please sign in to comment.