Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.io.RandomAccessFile;
- import java.util.Scanner;
- import java.lang.StringBuilder;
- import java.util.HashMap;
- /*
- * Platsen vartifrån man får listan med de sorterade orden är som följer
- * C:\Program Files\Cygwin\home\Dark Angel\sorted_index.txt
- */
- public class konkordans {
- private static RandomAccessFile indexFile;// =
- private static Scanner sc;
- private static HashMap<String,Integer> map = new HashMap();
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- map.put(" ", 0);
- map.put("a", 1);
- map.put("b", 2);
- map.put("c", 3);
- map.put("d", 4);
- map.put("e", 5);
- map.put("f", 6);
- map.put("g", 7);
- map.put("h", 8);
- map.put("i", 9);
- map.put("j", 10);
- map.put("k", 11);
- map.put("l", 12);
- map.put("m", 13);
- map.put("n", 14);
- map.put("o", 15);
- map.put("p", 16);
- map.put("q", 17);
- map.put("r", 18);
- map.put("s", 19);
- map.put("t", 20);
- map.put("u", 21);
- map.put("v", 22);
- map.put("w", 23);
- map.put("x", 24);
- map.put("y", 25);
- map.put("z", 26);
- map.put("å", 27);
- map.put("ä", 28);
- map.put("ö", 29);
- setInfo();
- }
- private static void setInfo() throws IOException{
- indexFile = new RandomAccessFile(new File("C:/Program Files/Cygwin/home/Dark Angel/sorted_index.txt"),"rw");
- System.out.println(indexFile); //Meningslöst men den får ligga där för tillfället.
- //indexFile.seek(19635638);
- Long[]B = new Long[27000];
- String s = indexFile.readLine();
- for(int i = 0;i<= 3291831;i++){
- s = indexFile.readLine();
- sc = new Scanner(s);
- String word = sc.next();
- int abc = toInt(word);
- Long pos = sc.nextLong();
- B[abc]= pos;
- File file;
- RandomAccessFile writeToFile;
- if(word.length()>=3){
- String tempABC = word.substring(0,3);
- file=new File(tempABC);
- if(file.exists()){
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }else{
- file.createNewFile();
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }
- }
- if(word.length()==2){
- String tempABC = word.substring(0,2);
- file=new File(tempABC);
- if(file.exists()){
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }else{
- file.createNewFile();
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }
- }
- if(word.length()==1){
- String tempABC = word.substring(0,1);
- file=new File(tempABC);
- if(file.exists()){
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }if(true){
- file.createNewFile();
- PrintWriter pw = new PrintWriter(file);
- pw.write(s);
- pw.close();
- // writeToFile = new RandomAccessFile(file,"rw");
- // writeToFile.writeUTF(s);
- // writeToFile.close();
- }
- else{
- System.out.println("Ist wröööngh!");
- }
- }
- //String a = word.substring(1);
- // System.out.print(a);
- // System.out.print("s");
- }
- }
- private static int toInt(String s){
- int toReturn = 0;
- if(s.length() >= 3){
- String a = s.substring(0, 1);
- //System.out.println("a= "+map.get(a));
- String b = s.substring(1, 2);
- //System.out.println("b= "+map.get(b));
- String c = s.substring(2, 3);
- //System.out.println("c= "+map.get(c));
- toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
- return toReturn;
- }
- else if(s.length() == 2){
- String a = s.substring(0, 1);
- //System.out.println("a= "+map.get(a));
- String b = s.substring(1, 2);
- //System.out.println("b= "+map.get(b));
- String c = " ";
- //System.out.println("c= "+map.get(c));
- toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
- return toReturn;
- }
- else if(s.length() == 1){
- String a = s.substring(0, 1);
- //System.out.println(map.get(a));
- String b = " ";
- //System.out.println(map.get(b));
- String c = " ";
- //System.out.println(map.get(c));
- toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
- return toReturn;
- }
- else{
- System.out.println("**********"+"FEEEEEEEEEEEL");
- return toReturn;
- }
- }
- }
Add Comment
Please, Sign In to add comment