Alkhalil root extractor provides the root of each word of a given sentence. It is an indispensable tool for several natural language processing applications such as search engines, text classification and information retrieval. The method of extraction used in this work runs in two steps. The first one consists in seeking of all the possible roots of each word analyzed out of context with the morphological analyzer Alkhalil Morpho Sys 2. Then, we develop in the second step a disambiguation approach based on continuous quadratic splines to choose among these roots the one that corresponds to the word context. We test this method on a representative corpus, and we obtained encouraging results with an accuracy of the order of 96%.
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.
Boudlal, A., Bebah, M. O. A. O., Lakhouaja, A., Mazroui, A., & Meziane, A. (2011). A Markovian approach for arabic root extraction. Int. Arab J. Inf. Technol., 8(1), 91-98.
Source
You have the opportunity to download the source code for Root extraction from Alkhalil official website.
RESTful Web API Code Snippets
for Root extraction 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 Root extraction module.
// Get result in text format
var texte = "##################";
var url = "http://oujda-nlp-team.net:8080/api/Racine";
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/ApiRacine/" + 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/Racine/";
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/ApiRacine/";
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/Racine"
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/ApiRacine/" + 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.")