NER Module

There are two options to download Farasa NER; either downloading just the jar file, or downloading the entire sourcecode zipped. You can also view demo or use web API.

Please login/register to download.

View Demo Use web API

FARASA Demo

for NER Module

RESTful Web API Code Snippets

for NER Module

import json
import requests
url = 'https://farasa.qcri.org/webapi/ner/'
text = 'يُشار إلى أن اللغة العربية' 
api_key = "#####################"
payload = {'text': text, 'api_key': api_key}
data = requests.post(url, data=payload)
result = json.loads(data.text)
print(result)   
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class FarasaSegmenter {
    private static HttpURLConnection con;
    public static void main(String[] args) throws IOException {
        var url = "https://farasa.qcri.org/webapi/ner";
        var text = "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون";
        var api_key = "#####################";
        var urlParameters = "text=" + text + "&api_key=" + api_key;
        byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
        try {
            var myurl = new URL(url);
            con = (HttpURLConnection) myurl.openConnection();
            con.setDoOutput(true);
            con.setRequestMethod("POST");
            con.setRequestProperty("User-Agent", "Java client");
            con.setRequestProperty("Content-Type", "application/json");
            try (var wr = new DataOutputStream(con.getOutputStream())) {
                wr.write(postData);
            }
            try (var br = new BufferedReader(
                    new InputStreamReader(con.getInputStream()))) {
                String line = br.readLine();
                System.out.println(line);
            }
        } finally {
            con.disconnect();
        }
    }
}
var text ='يُشار إلى أن اللغة العربية';
var api_key = "#####################";
var settings = { "async": true, 
"crossDomain": true, 
"url": "https://farasa.qcri.org/webapi/ner/", 
"method": "POST", 
"headers": { "content-type": "application/json", "cache-control": "no-cache", }, 
"processData": false, "data": "{\"text\":"+"\""+text+"\", \"api_key\":"+"\""+api_key+"\"}"; 
$.ajax(settings).done(function (response) { console.log(response); });
curl --header "Content-Type: application/json" -d "{\"text\":\"'يُشار إلى أن اللغة العربية'\", \"api_key\":\"'###################'\"}" https://farasa.qcri.org/webapi/ner/ 

Frequently Asked Questions

How can I use the jar file?
In case of using just the jar file, download it and create a directory with the name "lib" next to it. Furthermore, you need to download and place the next set of jar files in the lib directory: In the command prompt, navigate to the directory where the jar file is and type the following command:
java -jar FarasaNERJar.jar -i  -o 
How do I use Farasa NER package as a library in an application?
To use Farasa NER within your application, follow the next example code:
package tryingfarasa;

import com.qcri.farasa.segmenter.Farasa;
import com.qcri.farasa.pos.FarasaPOSTagger;
import com.qcri.farasa.ner.ArabicNER;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

public class TryingFarasaPOS {
    public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException,
    UnsupportedEncodingException, InterruptedException, Exception {





        ArrayList segOutput = farasa.segmentLine("النص المراد معالجته");

        Sentence sentence = farasaPOS.tagLine(segOutput);

        for (Clitic w : sentence.clitics)
        System.out.println(w.surface + "/" + w.guessPOS + ((w.genderNumber!="")?"-"+w.genderNumber:"")+" ");

public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException, UnsupportedEncodingException, InterruptedException, Exception {
        Farasa segmenter = new Farasa();
        FarasaPOSTagger tagger = new FarasaPOSTagger(segmenter);
        ArabicNER ner = new ArabicNER(segmenter, tagger);



        ArrayList output = ner.tagLine("النص المراد معالجته");

    int loc = 0;
    for (String s : output)
        {
        String plusSign = " ";
        if (loc == 0)
        {
            plusSign = "";
        }
                System.out.println(plusSign + s.trim());

        loc++;
        }
     }
}