Guest User

Untitled

a guest
Jul 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.io.RandomAccessFile;
  6. import java.util.Scanner;
  7. import java.lang.StringBuilder;
  8. import java.util.HashMap;
  9.  
  10.  
  11. /*
  12. * Platsen vartifrån man får listan med de sorterade orden är som följer
  13. * C:\Program Files\Cygwin\home\Dark Angel\sorted_index.txt
  14. */
  15. public class konkordans {
  16. private static RandomAccessFile indexFile;// =
  17. private static Scanner sc;
  18. private static HashMap<String,Integer> map = new HashMap();
  19.  
  20.  
  21. /**
  22. * @param args
  23. * @throws IOException
  24. */
  25. public static void main(String[] args) throws IOException {
  26. map.put(" ", 0);
  27. map.put("a", 1);
  28. map.put("b", 2);
  29. map.put("c", 3);
  30. map.put("d", 4);
  31. map.put("e", 5);
  32. map.put("f", 6);
  33. map.put("g", 7);
  34. map.put("h", 8);
  35. map.put("i", 9);
  36. map.put("j", 10);
  37. map.put("k", 11);
  38. map.put("l", 12);
  39. map.put("m", 13);
  40. map.put("n", 14);
  41. map.put("o", 15);
  42. map.put("p", 16);
  43. map.put("q", 17);
  44. map.put("r", 18);
  45. map.put("s", 19);
  46. map.put("t", 20);
  47. map.put("u", 21);
  48. map.put("v", 22);
  49. map.put("w", 23);
  50. map.put("x", 24);
  51. map.put("y", 25);
  52. map.put("z", 26);
  53. map.put("å", 27);
  54. map.put("ä", 28);
  55. map.put("ö", 29);
  56.  
  57.  
  58.  
  59.  
  60. setInfo();
  61.  
  62. }
  63.  
  64. private static void setInfo() throws IOException{
  65. indexFile = new RandomAccessFile(new File("C:/Program Files/Cygwin/home/Dark Angel/sorted_index.txt"),"rw");
  66. System.out.println(indexFile); //Meningslöst men den får ligga där för tillfället.
  67. //indexFile.seek(19635638);
  68. Long[]B = new Long[27000];
  69.  
  70.  
  71.  
  72. String s = indexFile.readLine();
  73.  
  74. for(int i = 0;i<= 3291831;i++){
  75. s = indexFile.readLine();
  76. sc = new Scanner(s);
  77. String word = sc.next();
  78. int abc = toInt(word);
  79. Long pos = sc.nextLong();
  80. B[abc]= pos;
  81. File file;
  82. RandomAccessFile writeToFile;
  83.  
  84. if(word.length()>=3){
  85.  
  86. String tempABC = word.substring(0,3);
  87. file=new File(tempABC);
  88. if(file.exists()){
  89. PrintWriter pw = new PrintWriter(file);
  90. pw.write(s);
  91. pw.close();
  92. // writeToFile = new RandomAccessFile(file,"rw");
  93. // writeToFile.writeUTF(s);
  94. // writeToFile.close();
  95. }else{
  96. file.createNewFile();
  97. PrintWriter pw = new PrintWriter(file);
  98. pw.write(s);
  99. pw.close();
  100. // writeToFile = new RandomAccessFile(file,"rw");
  101. // writeToFile.writeUTF(s);
  102. // writeToFile.close();
  103. }
  104. }
  105. if(word.length()==2){
  106. String tempABC = word.substring(0,2);
  107. file=new File(tempABC);
  108. if(file.exists()){
  109. PrintWriter pw = new PrintWriter(file);
  110. pw.write(s);
  111. pw.close();
  112. // writeToFile = new RandomAccessFile(file,"rw");
  113. // writeToFile.writeUTF(s);
  114. // writeToFile.close();
  115. }else{
  116. file.createNewFile();
  117. PrintWriter pw = new PrintWriter(file);
  118. pw.write(s);
  119. pw.close();
  120. // writeToFile = new RandomAccessFile(file,"rw");
  121. // writeToFile.writeUTF(s);
  122. // writeToFile.close();
  123. }
  124.  
  125. }
  126. if(word.length()==1){
  127. String tempABC = word.substring(0,1);
  128. file=new File(tempABC);
  129. if(file.exists()){
  130. PrintWriter pw = new PrintWriter(file);
  131. pw.write(s);
  132. pw.close();
  133. // writeToFile = new RandomAccessFile(file,"rw");
  134. // writeToFile.writeUTF(s);
  135. // writeToFile.close();
  136. }if(true){
  137. file.createNewFile();
  138. PrintWriter pw = new PrintWriter(file);
  139. pw.write(s);
  140. pw.close();
  141. // writeToFile = new RandomAccessFile(file,"rw");
  142. // writeToFile.writeUTF(s);
  143. // writeToFile.close();
  144. }
  145. else{
  146. System.out.println("Ist wröööngh!");
  147. }
  148.  
  149. }
  150.  
  151. //String a = word.substring(1);
  152. // System.out.print(a);
  153.  
  154. // System.out.print("s");
  155.  
  156. }
  157. }
  158.  
  159. private static int toInt(String s){
  160. int toReturn = 0;
  161. if(s.length() >= 3){
  162. String a = s.substring(0, 1);
  163. //System.out.println("a= "+map.get(a));
  164. String b = s.substring(1, 2);
  165. //System.out.println("b= "+map.get(b));
  166. String c = s.substring(2, 3);
  167. //System.out.println("c= "+map.get(c));
  168. toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
  169. return toReturn;
  170. }
  171. else if(s.length() == 2){
  172. String a = s.substring(0, 1);
  173. //System.out.println("a= "+map.get(a));
  174. String b = s.substring(1, 2);
  175. //System.out.println("b= "+map.get(b));
  176. String c = " ";
  177. //System.out.println("c= "+map.get(c));
  178. toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
  179. return toReturn;
  180. }
  181. else if(s.length() == 1){
  182.  
  183.  
  184. String a = s.substring(0, 1);
  185. //System.out.println(map.get(a));
  186. String b = " ";
  187. //System.out.println(map.get(b));
  188. String c = " ";
  189. //System.out.println(map.get(c));
  190. toReturn = map.get(a)*(30^2)+map.get(b)*30+map.get(c); // a*30^2+b*30+c
  191. return toReturn;
  192.  
  193. }
  194. else{
  195. System.out.println("**********"+"FEEEEEEEEEEEL");
  196. return toReturn;
  197. }
  198. }
  199.  
  200.  
  201.  
  202.  
  203.  
  204. }
Add Comment
Please, Sign In to add comment