Advertisement
programajster

Z10_Slownik

May 29th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package z10_3;
  2.  
  3. import java.io.IOException;
  4. import java.util.List;
  5.  
  6. public class Z10_3 {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Slownik s = new Slownik();
  11.        
  12.         try{
  13.             s.wczytaj("C:\\Users\\student.INFORMATYKA\\Desktop\\thesaurus.txt");
  14.         } catch(IOException ex){
  15.             System.out.println("Nie znaleziono pliku");
  16.         }
  17.        
  18.         String szukane = "ziom";
  19.         List<String> Lista = s.znajdz(szukane);
  20.        
  21.        
  22.         if(Lista != null)
  23.         {
  24.              System.out.println("Bliskoznaczne wyrazy do: "+szukane);
  25.         for(String S: Lista)
  26.         {
  27.             System.out.println(S);
  28.         }
  29.         }
  30.         else System.out.println("Nie ma słów bliskoznacznych do: "+szukane);
  31.     }
  32.  
  33. }
  34. //-------------------------------------Slownik.java
  35.  
  36. package z10_3;
  37.  
  38. import java.io.BufferedReader;
  39. import java.io.File;
  40. import java.io.FileNotFoundException;
  41. import java.io.FileReader;
  42. import java.io.IOException;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.Map;
  46. import java.util.TreeMap;
  47.  
  48. public class Slownik {
  49.    
  50.     Map<String, List<String>> slowa = new TreeMap<>();
  51.    
  52.     public void wczytaj(String NazwaPliku) throws FileNotFoundException, IOException
  53.     {
  54.         File plik = new File(NazwaPliku);
  55.         BufferedReader czytacz = new BufferedReader(new FileReader(plik));
  56.        
  57.         String wiersz = null;
  58.         while((wiersz = czytacz.readLine()) != null)
  59.                 {
  60.                  //   System.out.println(wiersz);
  61.                     String wyrazy[] = wiersz.split(";");
  62.                    
  63.                     List<String> bliskoznaczne = new ArrayList<>();
  64.                    
  65.                     for(int i = 0;i<wyrazy.length;i++){
  66.                     bliskoznaczne.add(wyrazy[i]);
  67.                     slowa.put(wyrazy[0],bliskoznaczne);
  68.                     }
  69.                            
  70.                 }
  71.        
  72.                 czytacz.close();
  73.    
  74.     }
  75.    
  76.     List<String> znajdz(String s)
  77.     {
  78.         List<String> Lista = slowa.get(s);
  79.         return Lista;
  80.     }
  81.    
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement