ant clean ant jar
java -jar dist/farasaSeg.jar
Or, just pass a text file (where the encoding is utf-8) as input to the package and specify the output file name as following:
java -jar dist/farasaSeg.jar -i <inputfile> -o <output_file>
To use Farasa segmentation package as a library in your application, just build it as shown before using the shell command “ant jar”. Then import the jar file farasaSeg.jar into your project. The following is an example few line of code to show how to use Farasa segmentation package
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<String> output = farasa.segmentLine("النص المراد معالجته"); for(String s: output) System.out.println(s); ... } ... }
ant clean ant jar
To run the package as a standalone, just pass a text file (where the encoding is utf-8) as input to the package and specify the output file name as following:
java -jar dist/FarasaPOSJar.jar -i <inputfile> -o <output_file>
To use Farasa POS Tagger as a library in your application, just build it as before using the shell script file “make.sh”. Then import the jar file FarasaPOS.jar into your project. The following is an example fews line of code to show how to use Farasa POS module
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<String> segOutput = farasa.segmentLine("النص المراد معالجته"); Sentence sentence = farasaPOS.tagLine(segOutput); for (Clitic w : sentence.clitics) System.out.println(w.surface + "/" + w.guessPOS + ((w.genderNumber!="")?"-"+w.genderNumber:"")+" "); } }
java -jar dist/farasaSeg.jar -i <inputfile> -o <output_file>
To use Farasa Diacritizer as a library in your application, just build it (or download the already built one) and then import the jar file FarasaDiacritize.jar into your project. The following is an example few lines of code to show how to use Farasa POS module.
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("النص المراد معالجته"); } }
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<String> segOutput = farasa.segmentLine("النص المراد معالجته"); Sentence sentence = farasaPOS.tagLine(segOutput); for (Clitic w : sentence.clitics) System.out.println(w.surface + "/" + w.guessPOS + ((w.genderNumber!="")?"-"+w.genderNumber:"")+" "); } }
java -jar FarasaNERJar.jar -i <inputfile> -o <output_file>
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<String> 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); ArrayListoutput = ner.tagLine("النص المراد معالجته"); int loc = 0; for (String s : output) { String plusSign = " "; if (loc == 0) { plusSign = ""; } System.out.println(plusSign + s.trim()); loc++; } } }