GithubHelp home page GithubHelp logo

adhaamehab / textblob-ar Goto Github PK

View Code? Open in Web Editor NEW
82.0 8.0 25.0 4.34 MB

Arabic support for textblob

Home Page: https://github.com/sloria/TextBlob

License: MIT License

Python 100.00%
nlp natural-language-processing machine-learning sentiment-analysis part-of-speech-tagger text-classification arabic-language arabic-nlp textblob text-similarity

textblob-ar's Introduction

textblob-ar [WIP]

image

Arabic language support for TextBlob.

Features

  • Tokenizer
  • Sentiment analysis
  • Stanford Arabic POS
  • Spelling Correction
  • Text similarity
  • Fasttext arabic word2vec interface

Usage

Tokenizer

>>> from textblob_ar import TextBlob
>>> blob = TextBlob(u"""هندسة البرمجيات هي دراسة تصميم وتنفيذ وتعديل البرمجيات بما يضمن توفر هذه البرمجيات بجودة عالية وتكلفة معقولة متاحة للجميع وقابلة للتطوير فيما بعد وسريعة للبناء. وهندسة البرمجيات تقوم على أسس ونظريات من الهندسة وعلوم الحاسب كمبدأ ال Functional Structure من الهندسة والذي يعتمد على مبدأ تصميم أجزاء صغيرة تتجانس في العمل مع بعضها لتشكل عمل الكل.""")
>>> blob.tokens
WordList(['هندسة', 'البرمجيات', 'هي', 'دراسة', 'تصميم', 'وتنفيذ', 'وتعديل', 'البرمجيات', 'بما', 'يضمن', 'توفر', 'هذه', 'البرمجيات', 'بجودة', 'عالية', 'وتكلفة', 'معقولة', 'متاحة', 'للجميع', 'وقابلة', 'للتطوير', 'فيما', 'بعد', 'وسريعة', 'للبناء', '.', 'وهندسة', 'البرمجيات', 'تقوم', 'على', 'أسس', 'ونظريات', 'من', 'الهندسة', 'وعلوم', 'الحاسب', 'كمبدأ', 'ال', 'Functional', 'Structure', 'من', 'الهندسة', 'والذي', 'يعتمد', 'على', 'مبدأ', 'تصميم', 'أجزاء', 'صغيرة', 'تتجانس', 'في', 'العمل', 'مع', 'بعضها', 'لتشكل', 'عمل', 'الكل', '.'])

Sentiment

>>> from textblob_ar import TextBlob
>>> blob = TextBlob('اعجبني هذا الكتاب. اعترض قليلا مع بعض افكاره لكن مضمونه رائع')
>>> blob.sentiment
Sentiment(polarity=0.8, subjectivity=0.9)
>>> blob = TextBlob('لم يعجبني هذا الكتاب. مضمونه سئ')
>>> blob.sentiment
Sentiment(polarity=-0.6999999999999998, subjectivity=0.6666666666666666)

Stanford POS

Note that Stanford POS is the defualt one untill the main one is released .. code-block:: python

>>> from textblob_ar import TextBlob >>> from textblob_ar.pos_tagger import StanfordPOSTagger >>> tagg = StanfordPOSTagger() >>> text = """ في أنظمة التشغيل متعددة المهام مثل اليونكس عفريت النظام هو برنامج يعمل في خلفية النظام بعيدا عن التحكم المباشر من المستحدم وغالبا ما يبدأ عمله كعملية خلفية مع بداية تشغيل النظام.""" >>> blob = TextBlob(text, pos_tagger=tagger) >>> print(blob.tags) [('', 'في/IN'), ('', 'أنظمة/NN'), ('', 'التشغيل/DTNN'), ('', 'متعددة/JJ'), ('', 'المهام/DTNN'), ('', 'مثل/NN'), ('', 'اليونكس/DTNNP'), ('', 'عفريت/NNP'), ('', 'النظام/DTNN'), ('', 'هو/PRP'), ('', 'برنامج/NN'), ('', 'يعمل/VBP'), ('', 'في/IN'), ('', 'خلفية/NN'), ('', 'النظام/DTNN'), ('', 'بعيدا/JJ'), ('', 'عن/IN'), ('', 'التحكم/DTNN'), ('', 'المباشر/DTJJ'), ('', 'من/IN'), ('', 'المستحدم/DTNN'), ('', 'وغالبا/NN'), ('', 'ما/WP'), ('', 'يبدأ/VBP'), ('', 'عمله/NN'), ('', 'كعملية/JJ'), ('', 'خلفية/NN'), ('', 'مع/NN'), ('', 'بداية/NN'), ('', 'تشغيل/NN'), ('', 'النظام/DTNN')]

Text Correction

Thanks for Peter Norvig http://norvig.com/spell-correct.html

>>> from textblob_ar import TextBlob
>>> from textblob_ar.correction import TextCorrection
>>> text = 'الاذدهاز'
>>> TextCorrection().correct(text)
{'الاذهان', 'الازدهار', 'الادهان', 'الاندهاش'}
>>> TextCorrection().correct(text, top=True)
'الازدهاز'

Text Similarity

Based on gensim and Fasttext pretrained word2vec model

The procedure used in calculating similarity is calculating mean feature vector for each sentence. Then calculate the cosine distance between those two vectors.

>>> from textblob_ar import TextSimilarity
>>> sim = TextSimilarity()
# takes around 12 second (macbook pro 2017) to load the pretrained word2vec
>>> sent1 = u'الإرهابي الصالح هي رواية خيال سياسي للكاتبة دوريس ليسينج. ظهرت أول طبعة للرواية في سبتمبر من عام 1985 للناشرين جوناثان كيب في المملكة المتحدة وألفريد أ'
>>> sent2 = u'روايه الكاتبه دوريس ليسينج هي روايه خيال سياسي ظهرت في سبتمبر 1985 بعنوان الارهابي الصالح وتم نشرها عن طريق جوناثان كيب والفريد أ في انجلترا'
>>> sim.similarity(sent1, sent2)
0.9611366391181946

Requirements

  • Python >= 3.3

Installation

  • Development

for text similarity download fasttext arabic word2vec pretrained model from here

TODO

  • Part Of Speech tagger
  • Noun-phrases extraction
  • Parser
  • Classification support
  • Grammer

License

MIT licensed. See the bundled LICENSE file for more details.

Join the chat at https://gitter.im/textblob-ar/community

textblob-ar's People

Contributors

abdallahnasir avatar adhaamehab avatar anasir-ureed avatar dependabot[bot] avatar gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textblob-ar's Issues

issue in running, هل عندك علم في هذي المشكله ام لا

Traceback (most recent call last):
File "C:/Users/ahmad/PycharmProjects/gittingdata/سثؤخىي صشغ/textblobarabic.py", line 5, in
blobb = TextBlob("""هندسة البرمجيات هي دراسة تصميم وتنفيذ وتعديل البرمجيات بما يضمن توفر هذه البرمجيات بجودة عالية وتكلفة معقولة متاحة للجميع وقابلة للتطوير فيما بعد وسريعة للبناء. وهندسة البرمجيات تقوم على أسس ونظريات من الهندسة وعلوم الحاسب كمبدأ ال Functional Structure من الهندسة والذي يعتمد على مبدأ تصميم أجزاء صغيرة تتجانس في العمل مع بعضها لتشكل عمل الك""")
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\textblob_ar\blob.py", line 71, in init
_pos_tagger = pos_tagger if pos_tagger is not None else StanfordPartOfSpeechTagger()
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\textblob_ar\pos_tagger.py", line 12, in init
self._tagger = StanfordPOSTagger(modelPath, modelJar)
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\nltk\tag\stanford.py", line 160, in init
super(StanfordPOSTagger, self).init(*args, **kwargs)
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\nltk\tag\stanford.py", line 74, in init
self._JAR, path_to_jar, searchpath=(), url=_stanford_url, verbose=verbose
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\nltk\internals.py", line 854, in find_jar
name_pattern, path_to_jar, env_vars, searchpath, url, verbose, is_regex
File "C:\Users\ahmad\PycharmProjects\gittingdata\venv\lib\site-packages\nltk\internals.py", line 740, in find_jar_iter
'Could not find %s jar file at %s' % (name_pattern, path_to_jar)
LookupError: Could not find stanford-postagger.jar jar file at textblob_ar/data/model.jar

could not install the Library

Thanks Adham for the work
I tried to install the library using

pip install textblob_ar

this was the output from jupyter notebook

Collecting textblob_ar
Note: you may need to restart the kernel to use updated packages.
ERROR: Could not find a version that satisfies the requirement textblob_ar (from versions: none)
ERROR: No matching distribution found for textblob_ar

I am using python 3.7.4

please help me resolve this issue

Thanks

Sentiment analysis problem

Hi,

Could you please suggest solution for the .sentiment function error
'HTTP Error 429: Too Many Requests'.
It was working fine but then whenever I run it, this error pops up. I was thinking that it must be the textblob-ar is using an API like Google and I need some cool off period, but I tried after leaving it for a whole day. Still the problem is the same.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.