The problem
Moroccans write online in Darija. It mixes Arabic, Amazigh, French and Spanish, has no fixed spelling or grammar, and is written in Arabic letters or in Latin letters with digits standing in for Arabic sounds (“3” for ع, “7” for ح). The NLP tools we could use, like NLTK, Farasa or Naftawayh, handled English, French or Modern Standard Arabic. None of them understood a Darija comment.
And no dataset existed that said whether a Darija word is positive, negative or angry.
Open Darija dictionary
We started Open Darija in April 2018 to build that dataset ourselves. It was a website with two sides:
- Visitors got a word that was waiting for verification and rated it: how positive it is, which sentiments it carries, and a description. They could also report a word or suggest a correction.
- Admins pasted in text or word lists, and the platform extracted and cleaned the words, split them into already verified and new, and sent the new ones to the verification queue. Admins approved corrections, handled reports, managed the list of neutral words and the sentiment tags, and exported the dictionary.
The visitor form: rate the word’s polarity, tick its sentiments, add a description or a correction.
The platform also served the dictionaries through an API, so any program could ask for the latest version instead of keeping a stale local copy.
Processing Darija text
On top of the dictionary we wrote our own processing steps for Darija:
- Detect the script. Text in Latin letters is transliterated into Arabic using a letter mapping table, so both forms go through the same pipeline.
- Turn emojis into words, because an angry face is often the clearest sentiment in a comment.
- Shorten stretched words back to their normal form, like “bzzzzaf” to “bzaf”.
- Clean digits, punctuation and leftover Latin characters.
- Tokenise, drop stop words and stem, so plurals, feminine forms and conjugated verbs match the root word in the dictionary.
What’s left is classified by topic and by sentiment, either with a simple lexicon approach that counts which classes the words belong to, or with a trained classifier (SVM or Bayesian) that uses the same lexicon as features. The sentiment analysis covers seven sentiments.
The platform around it
We applied this to public Facebook profiles. Only posts visible to everyone were collected, and only their text was analysed. The system had four applications and one database:
- A Python collector, based on an open-source Facebook scraper using Selenium and ChromeDriver, that saves a profile’s public posts into a folder structure.
- The Java core, the centre of the system (below).
- Open Darija, in PHP, providing the dictionaries.
- F-Analyzer, a React app with Chart.js where you request an analysis and explore the results: most-used words, most-mentioned people, topics, overall sentiment and the sentiment of each post.
The architecture from the 2019 project report: four applications and one database.
The Java core, layer by layer
The core was a Spring application with a REST API in front and a set of services behind it, each with one job:
- REST layer: receives requests from F-Analyzer and returns results as JSON.
- Master service: the coordinator. It decides which services to call, in which order, for each request.
- Scraping service: starts the Python collector for a profile, by running it as a system command, and reports back when it’s done.
- Structuring service: turns the collected files into documents and stores them in MongoDB.
- Analysis service: fetches the latest dictionary from the Open Darija API, runs the Darija processing on each document and stores the results.
- Data access layer: the only part that talks to MongoDB. Other services read and write through it, so the storage could change without touching the rest.
A request for a new profile goes through the whole chain: collect, structure, analyse, store, return. A request for a profile that’s already been analysed goes straight to the data access layer and back.
What I took from it
This was one of my first data project, before I called it data engineering. Most of what I still care about was already in it: getting messy text into a shape you can work with, splitting a system into parts that each do one thing, and keeping the data access in one place.
It also came back seven years later. Open Barlaman works on Arabic text again, this time with OCR and LLMs instead of hand-built stemming rules.