Alkhalil Lemmatizer assigns to each word of an Arabic sentence, a single lemma taking into account the word context. The proposed system comprises two modules. The first one consists of an analysis out of context, based on the morphosyntactic analyzer Alkhalil Morpho Sys 2. In the second module, we use the context to identify the correct lemma from the potential lemmas of the word obtained by the first module. For this purpose, we use a statistical technique based on the hidden Markov models, where the observations are the words of the sentence, and the lemmas represent the hidden states. We validate this approach using a labelled corpus consisting of about 500,000 words. The lemmatizer gives the correct lemma in more than 99.24% in the training set and about 94.45% of the words in the test set.
For further details, please check the following paper :
M. Boudchiche and A. Mazroui, . “Spline functions for Arabic morphological disambiguation, Applied Computing and Informatics, https://doi.org/10.1016/j.aci.2020.02.002.
M. Boudchiche, A. Mazroui, . “A hybrid approach for Arabic lemmatization”, Int. J. Speech Technol., 2018, DOI 10.1007/s10772-018-9528-3.
Source
You have the opportunity to download the source code for lemmatization from Alkhalil official website.
RESTful Web API Code Snippets
for Lemmatization Module
API code examples in popular programming languages such as Java, Python, and JavaScript. These code snippets allow you to effectively utilize the API and integrate it into your projects for the Lemmatization module.
// Get result in text format
var texte = "##################";
var url = "http://oujda-nlp-team.net:8080/api/lemma";
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
}
};
xhr.send("textinput=" + texte);
// Get result in JSON format
/*
var texte = "##################";
var url = "http://oujda-nlp-team.net:8080/api/Apilmm/" + texte;
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error("Erreur : " + xhr.status);
}
}
};
xhr.send();
*/
// Get result in text format
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.net.URLEncoder;
public class Exemple {
public static void main(String[] args) throws IOException {
String url = "http://oujda-nlp-team.net:8080/api/Apilmm/";
String text = "##################################";
// Encodes the text parameter to be included in the URL
String encodedText = URLEncoder.encode(text, StandardCharsets.UTF_8.toString());
// Constructs the complete API URL with the encoded text parameter
String apiUrl = url + encodedText;
// Creates the URL object
URL apiURL = new URL(apiUrl);
// Opens the connection
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
// Reads the response from the API
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
// Prints the response
System.out.println(response.toString());
} finally {
// Disconnects the connection
connection.disconnect();
}
}
}
/*
// Get result in JSON format
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class Exemple {
public static void main(String[] args) {
try {
String baseUrl = "http://oujda-nlp-team.net:8080/api/lemma/";
String text = "##################################";
// Encodes the text parameter to be included as a query parameter
String encodedText = URLEncoder.encode(text, StandardCharsets.UTF_8.toString());
String apiUrl = baseUrl + "?textinput=" + encodedText;
URL apiURL = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) apiURL.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println(response.toString());
} finally {
connection.disconnect();
}
} catch (UnsupportedEncodingException | MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
*/
import requests
# Get result in text format
url = "http://oujda-nlp-team.net:8080/api/lemma"
text_input = "##############################"
data = {"textinput": text_input}
response = requests.post(url, data=data)
if response.status_code == 200:
result = response.text
print(f"Result in text format: {result}")
else:
print("Error during API request.")
# Get result in JSON format
# text = "##############################"
# url = "http://oujda-nlp-team.net:8080/api/Apilmm/" + text
# response = requests.get(url)
# if response.status_code == 200:
# result = response.text
# print(f"Result in JSON format: {result}")
# else:
# print("Error during API request.")