Instantly share code, notes, and snippets.
Last activeMay 27, 2022 20:12
Save mhashim6/7d96f7ea274c9eb7e509798a332d78ac to your computer and use it in GitHub Desktop.
removes Arabic diacritics (tashkeel تشكيل) from any file almost instantly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Copyright2017mhashim6(MuhammadHashim) | |
LicensedundertheApacheLicense,Version2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "ASIS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
/** | |
created by mhashim6 (Muhammad Hashim) on 26/06/2017 | |
*/ | |
public class RemoveTashkeel { | |
//Unicode values of Tashkeel | |
private final static char[] tashkeel = { (char) Integer.parseInt("064F",16), (char)Integer.parseInt("0650",16), | |
(char)Integer.parseInt("0651",16), (char)Integer.parseInt("0652",16), | |
(char)Integer.parseInt("064B",16), (char)Integer.parseInt("064C",16), | |
(char)Integer.parseInt("064D",16), (char)Integer.parseInt("064E",16) }; | |
publicstaticvoidmain(String[]args) { | |
if (args.length !=2){ | |
System.out.println("Usage:\njava -Dfile.encoding=UTF-8 RemoveTashkeel sourceFile targetFile\n"); | |
System.exit(1); | |
} | |
//check if sourceFile exists | |
FilesourceFile =newFile(args[0]); | |
if (!sourceFile.exists()) { | |
System.out.println(args[0] +" doesn't exist.\nterminated.\n\n"); | |
System.exit(2); | |
} | |
longstart =System.currentTimeMillis(); | |
removeTashkeel(args[0],args[1]); | |
longend =System.currentTimeMillis(); | |
System.out.printf("\nTime taken: %d ms.\n", (end -start)); | |
} | |
privatestaticvoidremoveTashkeel(Stringin,Stringout) { | |
FileReaderreader =null; | |
FileWriterwriter =null; | |
try { | |
reader =newFileReader(in); | |
writer =newFileWriter(out); | |
//traverse each character | |
intc; | |
while ((c =reader.read()) != -1) | |
if (!isTashkeel((char)c)) | |
writer.append((char)c); | |
System.out.println("\n-----PROCESS FINISHED SUCCESSFULLY!"); | |
} | |
catch (Exceptione) { | |
System.out.println("\n-----AN ERROR OCCURED:"); | |
e.printStackTrace(); | |
} | |
finally { | |
try { | |
reader.close(); | |
writer.flush(); | |
writer.close(); | |
} | |
catch (IOExceptione) { | |
System.out.println("ERROR WHILE FLUSHING/CLOSING FILES:\n\n"); | |
e.printStackTrace(); | |
} | |
} | |
} | |
publicstaticbooleanisTashkeel(charc) { | |
for (inti =0;i <tashkeel.length;i++) { | |
if (c ==tashkeel[i]) {returntrue; } | |
} | |
returnfalse; | |
} | |
} |
Author
mhashim6 commentedJun 26, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The word (كِتَابٌ) becomes (كتاب).
How-To:
- copy the text in a new File named RemoveTashkeel.java
- compile using:
javac RemoveTashkeel.java - run the code using:
java -Dfile.encoding=UTF-8 RemoveTashkeel sourceFile targetFile
this code is used inOpen-Hadith-Data-Project
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment