Advertisement
Guest User

:)

a guest
Oct 16th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. package lab3;
  2.  
  3. import java.io.File;
  4. import java.util.HashSet;
  5. import java.util.Map.Entry;
  6. import java.util.Scanner;
  7. import java.util.Set;
  8.  
  9. import javafx.application.Application;
  10. import javafx.collections.FXCollections;
  11. import javafx.collections.ObservableList;
  12. import javafx.scene.Scene;
  13. import javafx.scene.control.Button;
  14. import javafx.scene.control.ListView;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.layout.BorderPane;
  17. import javafx.scene.layout.HBox;
  18. import javafx.scene.layout.Priority;
  19. import javafx.stage.Stage;
  20. import textproc.GeneralWordCounter;
  21. import textproc.WordCountComparator;
  22.  
  23. public class BookReaderController extends Application {
  24.  
  25.     @Override
  26.     public void start(Stage primaryStage) throws Exception {
  27.         BorderPane root = new BorderPane();
  28.         Scene scene = new Scene(root, 500, 500);
  29.         primaryStage.setTitle("BookReader");
  30.         primaryStage.setScene(scene);
  31.         primaryStage.show();
  32.  
  33. // ---------------------------------------------------------------------------------------------
  34.  
  35.         Scanner scan = new Scanner(new File("undantagsord.txt"));
  36.         Set<String> stopwords = new HashSet<String>();
  37.         while (scan.hasNext()) {
  38.             stopwords.add(scan.next().toLowerCase());
  39.         }
  40.         GeneralWordCounter<String> r = new GeneralWordCounter<String>(stopwords);
  41.         Scanner s = new Scanner(new File("nilsholg.txt"));
  42.         s.findWithinHorizon("\uFEFF", 1);
  43.         s.useDelimiter("(\\s|,|\\.|:|;|!|\\?|'|\\\")+");
  44.  
  45.         while (s.hasNext()) {
  46.             String word = s.next().toLowerCase();
  47.             r.process(word);
  48.         }
  49.         s.close();
  50.         scan.close();
  51.         ObservableList<Entry<String, Integer>> words = FXCollections.observableArrayList(r.getWords());
  52.         ListView<Entry<String, Integer>> listView = new ListView<Entry<String, Integer>>(words);
  53.         root.setCenter(listView);
  54.  
  55. //---------------------------------------------------------------------------------------------
  56.  
  57.         HBox hbox = new HBox();
  58.  
  59.         Button b1 = new Button("Alphabetical");
  60.         Button b2 = new Button("Frequency");
  61.         Button b3 = new Button("Find");
  62.  
  63.         TextField txt = new TextField();
  64.  
  65.         HBox.setHgrow(b1, Priority.ALWAYS);
  66.         HBox.setHgrow(b2, Priority.ALWAYS);
  67.         HBox.setHgrow(txt, Priority.ALWAYS);
  68.         HBox.setHgrow(b3, Priority.ALWAYS);
  69.  
  70.         b1.setMaxWidth(Double.MAX_VALUE);
  71.         b2.setMaxWidth(Double.MAX_VALUE);
  72.         txt.setMaxWidth(Double.MAX_VALUE);
  73.         b3.setMaxWidth(Double.MAX_VALUE);
  74.  
  75.         txt.setPromptText("Search");
  76.  
  77.         hbox.getChildren().addAll(b1, b2, txt, b3);
  78.  
  79.         root.setBottom(hbox);
  80.  
  81. //---------------------------------------------------------------------------------------------
  82.  
  83.         b1.setOnAction(e -> words.setAll(r.getWords()));
  84.         b2.setOnAction(e -> words.sort(new WordCountComparator()));
  85.         b3.setOnAction(e -> {
  86.            
  87.         });
  88.  
  89. //---------------------------------------------------------------------------------------------
  90.  
  91.     }
  92.  
  93.     public static void main(String[] args) {
  94.         Application.launch(args);
  95.  
  96.     }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement