Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package z10_3;
- import java.io.IOException;
- import java.util.List;
- public class Z10_3 {
- public static void main(String[] args) {
- Slownik s = new Slownik();
- try{
- s.wczytaj("C:\\Users\\student.INFORMATYKA\\Desktop\\thesaurus.txt");
- } catch(IOException ex){
- System.out.println("Nie znaleziono pliku");
- }
- String szukane = "ziom";
- List<String> Lista = s.znajdz(szukane);
- if(Lista != null)
- {
- System.out.println("Bliskoznaczne wyrazy do: "+szukane);
- for(String S: Lista)
- {
- System.out.println(S);
- }
- }
- else System.out.println("Nie ma słów bliskoznacznych do: "+szukane);
- }
- }
- //-------------------------------------Slownik.java
- package z10_3;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.TreeMap;
- public class Slownik {
- Map<String, List<String>> slowa = new TreeMap<>();
- public void wczytaj(String NazwaPliku) throws FileNotFoundException, IOException
- {
- File plik = new File(NazwaPliku);
- BufferedReader czytacz = new BufferedReader(new FileReader(plik));
- String wiersz = null;
- while((wiersz = czytacz.readLine()) != null)
- {
- // System.out.println(wiersz);
- String wyrazy[] = wiersz.split(";");
- List<String> bliskoznaczne = new ArrayList<>();
- for(int i = 0;i<wyrazy.length;i++){
- bliskoznaczne.add(wyrazy[i]);
- slowa.put(wyrazy[0],bliskoznaczne);
- }
- }
- czytacz.close();
- }
- List<String> znajdz(String s)
- {
- List<String> Lista = slowa.get(s);
- return Lista;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement