Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Author Shaha Hassan
- *date 16/11/2014
- * GNU License, feel free to do whatever with the code, as long as you give me Shaha Hassan the credit for the code.
- *
- * This program was written to count the occurances of UNICODE letters, or their combinations(2 and 3 char long).
- * It can be used to find what letter occurs the most in a language, or what combinations of letters occur the most.
- * A user can input what UNICODE characters are he wants to focus on in a file and the text to be analysed in another.
- * The program then reads the text file, counts the number of occurences of combinations of consecutive required unicode characters
- * and lists them in descending order.
- */
- /*
- * this project is in java and has 4 files
- * Driver
- * Matrix
- * Map
- * Documentation
- * this one is Driver.java (search though my pastes to find the other files.
- */
- import java.io.*;
- import java.util.Scanner;
- public class Driver {
- public static void main(String args[]) throws IOException {
- Reader s = null;
- Writer[] files=null;
- String fin = null;
- Scanner scn = new Scanner(System.in);
- //delete commented stmts if you'd like a prompt which asks you to input custom file names or press '.' for default
- //believe me that becomes tedious after running the program a few times.
- //anyway, opens files
- try {
- // System.out.println("Enter input filename or . ");
- // fin = scn.next();
- // if(fin.equals("."))
- fin = "D:\\in.txt";
- // else fin = fin + ".txt";
- s = new InputStreamReader(new FileInputStream(fin),"UTF-8");
- // System.out.println("Enter output filename or . ");
- fin=".";
- // fin = scn.next();
- if(fin.equals(".")) fin = "D:\\out";
- files = new Writer[3];
- for(int i=1; i<4; i++ ) {
- files[i-1] = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fin+i+".txt"),"UTF-8"));
- }
- } catch (UnsupportedEncodingException e) {
- System.out.print("Coding Format not supported");
- } catch (FileNotFoundException e) {
- System.out.println(fin + "not found.");
- }
- scn.close();
- Map m = new Map();
- Matrix tally = new Matrix(m);
- System.out.println("Map " + m);
- char t1, t2, t3, pre, curr;
- int pos1, pos2, pos3;
- t1=(char)s.read();
- t2 = (char)s.read();
- pre = t2;
- pos1 = m.getpos(t1);
- pos2 = m.getpos(t2);
- if ( (pos1>-1) && (pos2>-1) ) {
- tally.add(pos1, pos2);
- tally.add(pos1);
- tally.add(pos2);
- }
- while(s.ready()) {
- curr=(char)s.read();
- t3 = curr;
- pos1 = m.getpos(t1);
- pos2 = m.getpos(t2);
- pos3 = m.getpos(t3);
- if( pos3>-1) {
- tally.add(pos3);
- if(pos2>-1) {
- tally.add(pos2, pos3);
- if(pos1>-1) {
- tally.add(pos1, pos2, pos3);
- }
- }
- }
- t1 = pre;
- pre = curr;
- t2 = curr;
- }
- tally.genlist(m);
- tally.write(files);
- for(int i=0; i<3; i++) {
- files[i].close();
- }
- s.close();
- System.out.println("Output saved in following files: D:\\out1.txt, D:\\out2.txt, D:\\out3.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement