Giter VIP home page Giter VIP logo

textblob-ar's Introduction

textblob-ar [WIP]

https://travis-ci.org/adhaamehab/textblob-ar.svg?branch=master

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

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.