Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aed_projeto;
- import java.io.*;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class AED_PROJETO {
- public static void main(String[] args) throws FileNotFoundException {
- //como é que sabemos o tamanho do dicionario??
- int tamanhoDicionario =1000000;
- //temos de inicializar com o tamanho do dicionario
- Dicionario dicio = new Dicionario(tamanhoDicionario);
- dicio.init();
- //System.out.println(dicio.hashFunction("abcdefg"));
- int i = 0;
- String [] fileAr = {"dicionarioFinal.txt","6.txt"};
- // The name of the file to open.
- String fileName = fileAr[0];
- // This will reference one line at a time
- String line = null;
- try {
- // FileReader reads text files in the default encoding.
- FileReader fileReader =
- new FileReader(fileName);
- // Always wrap FileReader in BufferedReader.
- BufferedReader bufferedReader =
- new BufferedReader(fileReader);
- while((line = bufferedReader.readLine()) != null) {
- dicio.inserePalavra(line);
- }
- // Always close files.
- bufferedReader.close();
- }
- catch(FileNotFoundException ex) {
- System.out.println(
- "Unable to open file '" +
- fileName + "'");
- }
- catch(IOException ex) {
- System.out.println(
- "Error reading file '"
- + fileName + "'");
- // Or we could just do this:
- // ex.printStackTrace();
- }
- leFreq(fileAr[1],dicio);
- System.out.println(dicio.colisoes);
- System.out.println("medeus");
- Scanner sc = new Scanner(System.in);
- String word=sc.nextLine();
- System.out.println("Palavra a procurar: "+word);
- while(true) {
- dicio.correct(word);
- word=sc.nextLine();
- }
- }
- public static void leFreq(String nomeFicheiro,Dicionario dicio){
- System.out.println("ficheiro "+nomeFicheiro);
- // The name of the file to open.
- String fileName2 = nomeFicheiro;
- // This will reference one line at a time
- String line2 = null;
- String palavra;
- int freq;
- Node no = new Node();
- String [] palavras = new String[2] ;
- try {
- // FileReader reads text files in the default encoding.
- FileReader fileReader2 =
- new FileReader(fileName2);
- // Always wrap FileReader in BufferedReader.
- BufferedReader bufferedReader2 =
- new BufferedReader(fileReader2);
- while((line2 = bufferedReader2.readLine()) != null) {
- palavras = line2.split(" ");
- no = dicio.procura(palavras[0]);
- //System.out.println(palavras[0]);
- //System.out.println(palavras[1]);
- if(no==null)
- {
- //System.out.println("inserimos palavra "+palavras[0]);
- no = dicio.inserePalavra(palavras[0]);
- no.freqAbs=Integer.parseInt(palavras[1]);
- }
- else{
- no.freqAbs=Integer.parseInt(palavras[1]);
- }
- }
- // Always close files.
- bufferedReader2.close();
- }
- catch(FileNotFoundException ex) {
- System.out.println(
- "Unable to open file '" +
- fileName2 + "'");
- }
- catch(IOException ex) {
- System.out.println(
- "Error reading file '"
- + fileName2 + "'");
- // Or we could just do this:
- // ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement