### Python Example Source: https://farasa.qcri.org/POS Example of how to use the Farasa POS Tagging API with Python. ```APIDOC ## POST /webapi/pos/ ### Description This endpoint performs Part-of-Speech (POS) tagging on the provided text using the Farasa API. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/pos/ ### Parameters #### Request Body - **text** (string) - Required - The text to be tagged. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **response** (json) - The POS tagged result. ### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Java Example Source: https://farasa.qcri.org/POS Example of how to use the Farasa POS Tagging API with Java. ```APIDOC ## POST /webapi/pos/ ### Description This endpoint performs Part-of-Speech (POS) tagging on the provided text using the Farasa API. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/pos/ ### Parameters #### Request Body - **text** (string) - Required - The text to be tagged. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **response** (json) - The POS tagged result. ### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Java Example Source: https://farasa.qcri.org/lemmatization Example of how to use the Farasa Lemmatization API with Java HTTPURLConnection. ```APIDOC ## Java Request ### Description This snippet shows how to lemmatize Arabic text using the Farasa Web API with Java. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/lemmatization/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to lemmatize. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون", "api_key": "#####################" } ``` ### Response #### Success Response (200) - The response will be a JSON object containing the lemmatized text and related information. ``` -------------------------------- ### Python Example Source: https://farasa.qcri.org/lemmatization Example of how to use the Farasa Lemmatization API with Python requests. ```APIDOC ## Python Request ### Description This snippet demonstrates how to perform lemmatization using the Farasa Web API with Python. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/lemmatization/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to lemmatize. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - The response will be a JSON object containing the lemmatized text and related information. ``` -------------------------------- ### cURL Example Source: https://farasa.qcri.org/lemmatization Example of how to use the Farasa Lemmatization API with cURL. ```APIDOC ## cURL Request ### Description This snippet shows how to perform lemmatization using the Farasa Web API via cURL. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/lemmatization/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to lemmatize. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "'يُشار إلى أن اللغة العربية'", "api_key": "'###################'" } ``` ### Response #### Success Response (200) - The response will be a JSON object containing the lemmatized text and related information. ``` -------------------------------- ### cURL Example Source: https://farasa.qcri.org/POS Example of how to use the Farasa POS Tagging API with cURL. ```APIDOC ## POST /webapi/pos/ ### Description This endpoint performs Part-of-Speech (POS) tagging on the provided text using the Farasa API. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/pos/ ### Parameters #### Request Body - **text** (string) - Required - The text to be tagged. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "'يُشار إلى أن اللغة العربية'", "api_key": "'###################'" } ``` ### Response #### Success Response (200) - **response** (json) - The POS tagged result. ### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### JavaScript Example Source: https://farasa.qcri.org/lemmatization Example of how to use the Farasa Lemmatization API with JavaScript AJAX. ```APIDOC ## JavaScript Request ### Description This snippet demonstrates lemmatization using the Farasa Web API with JavaScript and jQuery AJAX. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/lemmatization/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to lemmatize. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - The response will be a JSON object containing the lemmatized text and related information. ``` -------------------------------- ### JavaScript Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=footer-area Provides a JavaScript example for calling the Farasa Web API. Remember to replace 'YOUR_API_KEY' with your valid API key. ```javascript const url = "https://farasa.qcri.org/webapi/segmentation?text=أحب اللغة العربية&key=YOUR_API_KEY"; fetch(url) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Curl Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=footer-area Illustrates how to use Curl to interact with the Farasa Web API. Substitute 'YOUR_API_KEY' with your actual key. ```bash curl -G "https://farasa.qcri.org/webapi/segmentation" --data-urlencode "text=أحب اللغة العربية" -d "key=YOUR_API_KEY" ``` -------------------------------- ### Java Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=footer-area Shows how to interact with the Farasa Web API using Java. Replace 'YOUR_API_KEY' with your actual API key. ```java import java.io.IOException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class FarasaApi { public static void main(String[] args) { final String uri = "https://farasa.qcri.org/webapi/segmentation"; final String apiKey = "YOUR_API_KEY"; final String text = "أحب اللغة العربية"; try (CloseableHttpClient httpclient = HttpClients.createDefault()) { URIBuilder builder = new URIBuilder(uri); builder.addParameter("text", text); builder.addParameter("key", apiKey); HttpGet request = new HttpGet(builder.build()); request.setHeader("Content-type", "application/json"); try (CloseableHttpResponse response = httpclient.execute(request)) { System.out.println(EntityUtils.toString(response.getEntity())); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Curl Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=contact This Curl command shows how to access the Farasa Web API. Substitute 'YOUR_API_KEY' with your actual API key. ```bash curl "https://farasa.qcri.org/webapi/process?text=النص المراد معالجته&key=YOUR_API_KEY&service=segmentation" ``` -------------------------------- ### Java Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=contact This Java snippet shows how to interact with the Farasa Web API. Replace 'YOUR_API_KEY' with your actual API key. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class FarasaApiClient { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); String apiKey = "YOUR_API_KEY"; String textToProcess = "النص المراد معالجته"; String service = "segmentation"; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://farasa.qcri.org/webapi/process?text=" + textToProcess + "&key=" + apiKey + "&service=" + service)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Status Code: " + response.statusCode()); System.out.println("Response Body: " + response.body()); } } ``` -------------------------------- ### Python Segmentation API Source: https://farasa.qcri.org/segmentation Example of how to use the Farasa Segmentation API with Python. ```APIDOC ## Python Segmentation API ### Description This snippet demonstrates how to perform word segmentation using the Farasa API with Python. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/segmentation/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to be segmented. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **result** (object) - Contains the segmented text and other relevant information. ### Response Example ```json { "result": "يُشار إلى أن اللغة العربية" } ``` ``` -------------------------------- ### Java Segmentation API Source: https://farasa.qcri.org/segmentation Example of how to use the Farasa Segmentation API with Java. ```APIDOC ## Java Segmentation API ### Description This snippet demonstrates how to perform word segmentation using the Farasa API with Java. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/segmentation/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to be segmented. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **result** (string) - The segmented Arabic text. ### Response Example ```json { "result": "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون" } ``` ``` -------------------------------- ### JavaScript Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=contact This JavaScript snippet demonstrates how to call the Farasa Web API using fetch. Remember to replace 'YOUR_API_KEY' with your key. ```javascript const apiKey = "YOUR_API_KEY"; const textToProcess = "النص المراد معالجته"; const service = "segmentation"; fetch(`https://farasa.qcri.org/webapi/process?text=${textToProcess}&key=${apiKey}&service=${service}`) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### cURL Segmentation API Source: https://farasa.qcri.org/segmentation Example of how to use the Farasa Segmentation API with cURL. ```APIDOC ## cURL Segmentation API ### Description This snippet demonstrates how to perform word segmentation using the Farasa API with cURL. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/segmentation/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to be segmented. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "'يُشار إلى أن اللغة العربية'", "api_key": "'###################'" } ``` ### Response #### Success Response (200) - **result** (string) - The segmented Arabic text. ### Response Example ```json { "result": "يُشار إلى أن اللغة العربية" } ``` ``` -------------------------------- ### JavaScript Segmentation API Source: https://farasa.qcri.org/segmentation Example of how to use the Farasa Segmentation API with JavaScript. ```APIDOC ## JavaScript Segmentation API ### Description This snippet demonstrates how to perform word segmentation using the Farasa API with JavaScript. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/segmentation/ ### Parameters #### Request Body - **text** (string) - Required - The Arabic text to be segmented. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **result** (string) - The segmented Arabic text. ### Response Example ```json { "result": "يُشار إلى أن اللغة العربية" } ``` ``` -------------------------------- ### Python Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=footer-area Demonstrates how to use the Farasa Web API for text processing in Python. Ensure you have registered and obtained an API key. ```python import requests url = "https://farasa.qcri.org/webapi/segmentation" params = { "text": "أحب اللغة العربية", "key": "YOUR_API_KEY" } response = requests.get(url, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Use Farasa NER as a Library in Java Source: https://farasa.qcri.org/NER Integrate Farasa NER into your Java application. This example demonstrates initializing the segmenter, POS tagger, and NER components, then processing text. ```java 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++; } } } ``` -------------------------------- ### Use Farasa Segmenter as a Java Library Source: https://farasa.qcri.org/lemmatization Example code demonstrating how to import and use the Farasa segmentation package as a library in a Java application. Ensure the farasaSeg.jar is imported into your project. ```java package tryingfarasa; import com.qcri.farasa.segmenter.Farasa; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; public class TryingSeg { ... public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException { ... Farasa farasa = new Farasa(); ArrayList output = farasa.segmentLine("النص المراد معالجته"); for(String s: output) System.out.println(s); ... } ... } ``` -------------------------------- ### Python Example for Farasa Web API Source: https://farasa.qcri.org/?hashtag=contact This Python snippet demonstrates how to use the Farasa Web API for text processing. Ensure you have registered and obtained an API key. ```python import requests url = "https://farasa.qcri.org/webapi/process" params = { "text": "النص المراد معالجته", "key": "YOUR_API_KEY", "service": "segmentation" } response = requests.get(url, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Python Spell Check API Source: https://farasa.qcri.org/spellcheck Example of how to use the Farasa Spell Check API with Python. ```APIDOC ## Python Spell Check API ### Description This snippet demonstrates how to perform spell checking using the Farasa API with Python. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/spellcheck/ ### Parameters #### Request Body - **text** (string) - Required - The text to spell check. - **api_key** (string) - Required - Your Farasa API key. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **output** (string) - The spell-checked text or suggestions. ### Response Example ```json { "output": "[Spell check results]" } ``` ``` -------------------------------- ### JavaScript Spell Check API Source: https://farasa.qcri.org/spellcheck Example of how to use the Farasa Spell Check API with JavaScript. ```APIDOC ## JavaScript Spell Check API ### Description This snippet demonstrates how to perform spell checking using the Farasa API with JavaScript. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/spellcheck/ ### Parameters #### Request Body - **text** (string) - Required - The text to spell check. - **api_key** (string) - Required - Your Farasa API key. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **output** (string) - The spell-checked text or suggestions. ### Response Example ```json { "output": "[Spell check results]" } ``` ``` -------------------------------- ### Java Spell Check API Source: https://farasa.qcri.org/spellcheck Example of how to use the Farasa Spell Check API with Java. ```APIDOC ## Java Spell Check API ### Description This snippet demonstrates how to perform spell checking using the Farasa API with Java. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/spellcheck/ ### Parameters #### Request Body - **text** (string) - Required - The text to spell check. - **api_key** (string) - Required - Your Farasa API key. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **output** (string) - The spell-checked text or suggestions. ### Response Example ```json { "output": "[Spell check results]" } ``` ``` -------------------------------- ### cURL Spell Check API Source: https://farasa.qcri.org/spellcheck Example of how to use the Farasa Spell Check API with cURL. ```APIDOC ## cURL Spell Check API ### Description This snippet demonstrates how to perform spell checking using the Farasa API with cURL. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/spellcheck/ ### Parameters #### Request Body - **text** (string) - Required - The text to spell check. - **api_key** (string) - Required - Your Farasa API key. ### Request Example ```bash curl --header "Content-Type: application/json" -d "{\"text\":\"يُشار إلى أن اللغة العربية\", \"api_key\":\"###################\"}" https://farasa.qcri.org/webapi/spellcheck/ ``` ### Response #### Success Response (200) - **output** (string) - The spell-checked text or suggestions. ### Response Example ```json { "output": "[Spell check results]" } ``` ``` -------------------------------- ### Use Farasa POS Tagger as a Library in Java Source: https://farasa.qcri.org/POS Integrate the Farasa POS Tagger into your Java application. Build the project using 'make.sh', import the FarasaPOS.jar, and use the provided classes for segmentation and POS tagging. This example demonstrates basic usage. ```java package tryingfarasa; import com.qcri.farasa.segmenter.Farasa; import com.qcri.farasa.pos.FarasaPOSTagger; import com.qcri.farasa.pos.Sentence; import com.qcri.farasa.pos.Clitic; 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 { Farasa farasa = new Farasa(); FarasaPOSTagger farasaPOS = new FarasaPOSTagger(farasa); 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:"")+" "); } } ``` -------------------------------- ### Diacritize Text using Python Source: https://farasa.qcri.org/diacritization Use this Python snippet to send text to the Farasa Diacritization API and receive the diacritized result. Ensure you have the 'requests' library installed. ```python import json import requests url = 'https://farasa.qcri.org/webapi/diacritize/' text = 'يُشار إلى أن اللغة العربية' api_key = "#####################" payload = {'text': text, 'api_key': api_key} data = requests.post(url, data=payload) result = json.loads(data.text) print(result) __ ``` -------------------------------- ### Python POS Tagging Web API Source: https://farasa.qcri.org/POS Use this Python snippet to send text to the Farasa POS Tagging API and receive the results. Ensure you have the 'requests' library installed. ```python import json import requests url = 'https://farasa.qcri.org/webapi/pos/' text = 'يُشار إلى أن اللغة العربية' api_key = "#####################" payload = {'text': text, 'api_key': api_key} data = requests.post(url, data=payload) result = json.loads(data.text) print(result) __ ``` -------------------------------- ### Python Web API Request for Lemmatization Source: https://farasa.qcri.org/lemmatization Use this Python snippet to send text to the Farasa Lemmatization API and receive lemmatized results. Ensure you have the 'requests' library installed. ```python import json import requests url = 'https://farasa.qcri.org/webapi/lemmatization/' text = 'يُشار إلى أن اللغة العربية' api_key = "#####################" payload = {'text': text, 'api_key': api_key} data = requests.post(url, data=payload) result = json.loads(data.text) print(result) __ ``` -------------------------------- ### Java Spell Check API Request Source: https://farasa.qcri.org/spellcheck Perform a POST request to the Farasa Spell Check API using Java. This example demonstrates setting up the connection, sending parameters, and reading the response. ```java 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/spellcheck/"; 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(); } } } __ ``` -------------------------------- ### Run Farasa NER JAR from Command Line Source: https://farasa.qcri.org/NER Execute the FarasaNERJar.jar file from the command prompt. Ensure all required dependency JAR files are placed in a 'lib' directory next to the main JAR. ```bash java -jar FarasaNERJar.jar -i -o ``` -------------------------------- ### Run Farasa Dependency Parser JAR Source: https://farasa.qcri.org/dependency Use this command to run the Farasa Dependency Parser JAR file from the command prompt. Ensure the 'lib' directory is next to the JAR file. ```bash java -jar FarasaDependencyJar.jar -i -o ``` -------------------------------- ### Run Farasa Constituency Parser Jar Source: https://farasa.qcri.org/constituency Use this command to run the Farasa Constituency Parser from the downloaded jar file. Ensure the 'lib' directory is next to the jar file. ```bash java -jar FarasaConstituencyJar.jar -i -o ``` -------------------------------- ### Run Farasa Segmenter Standalone (File Input/Output) Source: https://farasa.qcri.org/lemmatization Process a text file with UTF-8 encoding as input and specify an output file name for the Farasa Segmenter. ```bash java -jar dist/farasaSeg.jar -i -o ``` -------------------------------- ### Python Segmentation API Request Source: https://farasa.qcri.org/segmentation Use this Python snippet to send text to the Farasa segmentation API and receive the results. Ensure you have the 'requests' library installed. ```python import json import requests url = 'https://farasa.qcri.org/webapi/segmentation/' text = 'يُشار إلى أن اللغة العربية' api_key = "#####################" payload = {'text': text, 'api_key': api_key} data = requests.post(url, data=payload) result = json.loads(data.text) print(result) __ ``` -------------------------------- ### Run Farasa POS Tagger Standalone Source: https://farasa.qcri.org/POS Execute the Farasa POS Tagger package as a standalone application by providing an input text file and specifying an output file name. Ensure the input file is UTF-8 encoded. ```bash java -jar dist/farasaPOSJar.jar -i -o ``` -------------------------------- ### Compile Farasa POS Tagger Source Code Source: https://farasa.qcri.org/POS Use these commands to compile the source code and build the JAR file for the Farasa POS Tagger. ```bash ant java ant jar ``` -------------------------------- ### Run Farasa Segmenter Standalone (Interactive) Source: https://farasa.qcri.org/lemmatization Run the Farasa Segmenter package in interactive mode using this command. ```bash java -jar dist/farasaSeg.jar ``` -------------------------------- ### Run Farasa Diacritizer Standalone Source: https://farasa.qcri.org/seq2seq_diacritization Execute the Farasa diacritizer as a standalone application using its JAR file. Specify input and output files using command-line arguments. ```bash java -jar dist/farasaDiacritizeJar.jar -i -o ``` -------------------------------- ### Python Seq2seq Diacritization API Request Source: https://farasa.qcri.org/seq2seq_diacritization Use this Python snippet to send text for diacritization to the Seq2seq API. Ensure you have the 'requests' library installed. Replace '#####################' with your actual API key. ```python import json import requests url = 'https://farasa.qcri.org/webapi/seq2seq_diacritize/' text = 'يُشار إلى أن اللغة العربية' api_key = "#####################" dialect = "mor" payload = {'text': text, 'api_key': api_key, "dialect": dialect} data = requests.post(url, data=payload) result = json.loads(data.text) print(result) __ ``` -------------------------------- ### Python NER API Request Source: https://farasa.qcri.org/NER Use this Python snippet to send text to the Farasa NER API and receive the results. Ensure you have the 'requests' library installed and replace '#####################' with your actual API key. ```python 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) __ ``` -------------------------------- ### Java NER API Request Source: https://farasa.qcri.org/NER This Java code demonstrates how to make a POST request to the Farasa NER API. It includes setting up the connection, sending the text and API key, and reading the response. Replace '#####################' with your API key. ```java 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(); } } }__ ``` -------------------------------- ### Java Web API Request for Lemmatization Source: https://farasa.qcri.org/lemmatization This Java code demonstrates how to connect to the Farasa Lemmatization API using an HTTP POST request. It handles sending text and API key, then prints the response. ```java 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 FarasaLemmatization { private static HttpURLConnection con; public static void main(String[] args) throws IOException { var url = "https://farasa.qcri.org/webapi/lemmatization/"; 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(); } } }__ ``` -------------------------------- ### RESTful Web API - NER Module Source: https://farasa.qcri.org/NER Code snippets demonstrating how to use the Farasa NER RESTful Web API for text analysis. ```APIDOC ## POST /webapi/ner/ ### Description This endpoint performs Named Entity Recognition on the provided text using the Farasa NER module. ### Method POST ### Endpoint https://farasa.qcri.org/webapi/ner/ ### Parameters #### Request Body - **text** (string) - Required - The text to analyze for named entities. - **api_key** (string) - Required - Your API key for authentication. ### Request Example ```json { "text": "يُشار إلى أن اللغة العربية", "api_key": "#####################" } ``` ### Response #### Success Response (200) - **entities** (array) - A list of named entities found in the text, with their types and positions. ### Response Example ```json { "entities": [ { "text": "اللغة العربية", "type": "MISC", "start": 18, "end": 30 } ] } ``` ``` -------------------------------- ### Java POS Tagging Web API Source: https://farasa.qcri.org/POS This Java code demonstrates how to connect to the Farasa POS Tagging API using an HTTP POST request. It handles URL connection, parameter encoding, and response reading. ```java 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/pos/"; 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(); } } } __ ``` -------------------------------- ### Integrate Farasa Diacritizer as a Library in Java Source: https://farasa.qcri.org/seq2seq_diacritization Use the Farasa Diacritizer as a library in your Java application. Import the necessary classes and initialize the DiacritizeText object with the data directory and model files. ```java package tryingfarasa; import java.io.FileNotFoundException; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import com.qcri.farasa.segmenter.Farasa; import com.qcri.farasa.pos.FarasaPOSTagger; import com.qcri.farasa.diacritize.DiacritizeText; public class TryingFarasaPOS { public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException, UnsupportedEncodingException, InterruptedException, Exception { Farasa farasa = new Farasa(); FarasaPOSTagger farasaPOS = new FarasaPOSTagger(farasa); String dataDirectory = "/var/www/farasa/data/"; DiacritizeText dt = new DiacritizeText(dataDirectory, "all-text.txt.nocase.blm", farasa, tagger); String diacritized = dt.diacritize("النص المراد معالجته"); } } ``` -------------------------------- ### cURL POS Tagging Web API Source: https://farasa.qcri.org/POS This cURL command demonstrates how to interact with the Farasa POS Tagging API from the command line. It specifies the content type and provides the text and API key in the request body. ```curl curl --header "Content-Type: application/json" -d "{\"text\":\'يُشار إلى أن اللغة العربية\'", \"api_key\":\'###################\'}" https://farasa.qcri.org/webapi/pos/ __ ``` -------------------------------- ### cURL Web API Request for Lemmatization Source: https://farasa.qcri.org/lemmatization This cURL command shows how to make a POST request to the Farasa Lemmatization API. It specifies the content type and provides the text and API key in the request body. ```curl curl --header "Content-Type: application/json" -d "{\"text\":\'يُشار إلى أن اللغة العربية\'", \"api_key\":\'###################\'}" https://farasa.qcri.org/webapi/lemmatization/ __ ``` -------------------------------- ### Java Segmentation API Request Source: https://farasa.qcri.org/segmentation This Java code demonstrates how to make a POST request to the Farasa segmentation API. It handles URL connection, request parameters, and response reading. ```java 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/segmentation/"; 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(); } } } __ ``` -------------------------------- ### Diacritize Text using Java Source: https://farasa.qcri.org/diacritization This Java code demonstrates how to connect to the Farasa Diacritization API using an HTTP POST request. It handles the request and response streams for diacritizing Arabic text. ```java 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 FarasaDiacritizer { private static HttpURLConnection con; public static void main(String[] args) throws IOException { var url = "https://farasa.qcri.org/webapi/diacritize/"; 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(); } } } __ ``` -------------------------------- ### cURL Seq2seq Diacritization API Request Source: https://farasa.qcri.org/seq2seq_diacritization This cURL command shows how to make a POST request to the Seq2seq diacritization API from the command line. It includes the necessary headers and data payload. Replace '###################' with your actual API key. ```curl curl --header "Content-Type: application/json" -d "{\"text\":\'يُشار إلى أن اللغة العربية'\, \"api_key\":\'###################\', \"dialect\":\'mor\'}" https://farasa.qcri.org/webapi/seq2seq_diacritize/ __ ``` -------------------------------- ### Java Seq2seq Diacritization API Request Source: https://farasa.qcri.org/seq2seq_diacritization This Java code demonstrates how to make a POST request to the Seq2seq diacritization API. It handles the HTTP connection, request parameters, and response reading. Replace '#####################' with your actual API key. ```java 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 FarasaDiacritizer { private static HttpURLConnection con; public static void main(String[] args) throws IOException { var url = "https://farasa.qcri.org/webapi/seq2seq_diacritize/"; var text = "يُشار إلى أن اللغة العربية يتحدثها أكثر من 422 مليون"; var api_key = "#####################"; var dialect = "mor" var urlParameters = "text=" + text + "&api_key=" + api_key+ "&dialect=" + dialect; 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(); } } }__ ```