Stemming is the main step used for handling the morphologically rich languages such as Arabic. It is usually used in several fields such as Natural Language Processing, Information Retrieval (IR), and Text Mining. The goal of stemming is to reduce inflected or derived words to their base form. Since the Arabic language is an inflectional language and mainly depends on roots and patterns to generate words, this stemmer was developed based on the interaction between roots and patterns. The approach adopted for its development is similar to that used to develop the lemmatizer. The achieved accuracies are 96.93% and 96.56% for respectively the Quranic corpus “Al-Mus’haf” and the NEMLAR corpus.
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.
Zeroual, I., Boudchiche, M., Mazroui, A., Lakhouaja, A., . “Developing and performance evaluation of a new Arabic heavy/light stemmer”, In: Proceedings of the second International Conference on Big Data, Cloud and Applications, Tetuan, (Morocco), March 29-30, 2017. ISBN: 978-1-4503-4852-2. DOI: 10.1145/3090354.3090371
Source
You have the opportunity to download the source code for stemming from Alkhalil official website.
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 stemming module.
// Get result in text format
var texte = "##################";
var url = "http://oujda-nlp-team.net:8080/api/Stemmer";
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/Apistm/" + 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/Apistm/";
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/Stemmer/";
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/Stemmer"
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/Apistm/" + 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.")