Advertisement
Guest User

Untitled

a guest
May 27th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.31 KB | None | 0 0
  1.  
  2. package aed_projeto;
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9.  
  10. public class AED_PROJETO {
  11.  
  12.     public static void main(String[] args) throws FileNotFoundException {
  13.        
  14.         //como é que sabemos o tamanho do dicionario??
  15.         int tamanhoDicionario =1000000;
  16.         //temos de inicializar com o tamanho do dicionario
  17.         Dicionario dicio = new Dicionario(tamanhoDicionario);
  18.         dicio.init();
  19.         //System.out.println(dicio.hashFunction("abcdefg"));
  20.         int i = 0;
  21.         String [] fileAr = {"dicionarioFinal.txt","6.txt"};
  22.         // The name of the file to open.
  23.         String fileName = fileAr[0];
  24.  
  25.         // This will reference one line at a time
  26.         String line = null;
  27.        
  28.        
  29.         try {
  30.             // FileReader reads text files in the default encoding.
  31.             FileReader fileReader =
  32.                 new FileReader(fileName);
  33.  
  34.             // Always wrap FileReader in BufferedReader.
  35.             BufferedReader bufferedReader =
  36.                 new BufferedReader(fileReader);
  37.            
  38.             while((line = bufferedReader.readLine()) != null) {
  39.                 dicio.inserePalavra(line);
  40.             }  
  41.  
  42.             // Always close files.
  43.             bufferedReader.close();        
  44.         }
  45.         catch(FileNotFoundException ex) {
  46.             System.out.println(
  47.                 "Unable to open file '" +
  48.                 fileName + "'");                
  49.         }
  50.         catch(IOException ex) {
  51.             System.out.println(
  52.                 "Error reading file '"
  53.                 + fileName + "'");                  
  54.             // Or we could just do this:
  55.             // ex.printStackTrace();
  56.         }
  57.        
  58.        
  59.        
  60.        
  61.        
  62.        
  63.        
  64.        
  65.        
  66.        
  67.        
  68.        
  69.        
  70.         leFreq(fileAr[1],dicio);
  71.        
  72.        
  73.        
  74.        
  75.        
  76.         System.out.println(dicio.colisoes);
  77.         System.out.println("medeus");
  78.         Scanner sc = new Scanner(System.in);
  79.         String word=sc.nextLine();
  80.         System.out.println("Palavra a procurar: "+word);
  81.         while(true) {
  82.             dicio.correct(word);
  83.             word=sc.nextLine();
  84.         }
  85.        
  86.        
  87.        
  88.     }
  89.  
  90.    
  91.    
  92.    
  93.    
  94.    
  95.    
  96.     public static void leFreq(String nomeFicheiro,Dicionario dicio){
  97.         System.out.println("ficheiro "+nomeFicheiro);
  98.         // The name of the file to open.
  99.         String fileName2 = nomeFicheiro;
  100.         // This will reference one line at a time
  101.         String line2 = null;
  102.         String palavra;
  103.         int freq;
  104.         Node no = new Node();
  105.         String [] palavras = new String[2] ;
  106.        
  107.         try {
  108.             // FileReader reads text files in the default encoding.
  109.             FileReader fileReader2 =
  110.                 new FileReader(fileName2);
  111.  
  112.             // Always wrap FileReader in BufferedReader.
  113.             BufferedReader bufferedReader2 =
  114.                 new BufferedReader(fileReader2);
  115.            
  116.             while((line2 = bufferedReader2.readLine()) != null) {
  117.                
  118.                 palavras = line2.split(" ");
  119.                 no = dicio.procura(palavras[0]);
  120.                 //System.out.println(palavras[0]);
  121.                 //System.out.println(palavras[1]);
  122.                 if(no==null)
  123.                 {  
  124.                     //System.out.println("inserimos palavra "+palavras[0]);
  125.                     no = dicio.inserePalavra(palavras[0]);
  126.                     no.freqAbs=Integer.parseInt(palavras[1]);
  127.                 }
  128.                 else{
  129.                     no.freqAbs=Integer.parseInt(palavras[1]);
  130.                 }
  131.             }  
  132.  
  133.             // Always close files.
  134.             bufferedReader2.close();        
  135.         }
  136.         catch(FileNotFoundException ex) {
  137.             System.out.println(
  138.                 "Unable to open file '" +
  139.                 fileName2 + "'");                
  140.         }
  141.         catch(IOException ex) {
  142.             System.out.println(
  143.                 "Error reading file '"
  144.                 + fileName2 + "'");                  
  145.             // Or we could just do this:
  146.             // ex.printStackTrace();
  147.         }
  148.     }
  149.    
  150.    
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement