Advertisement
Mix0r

Holgersson

Jan 23rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package textproc;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.ArrayList;
  6. import java.util.HashSet;
  7. import java.util.List;
  8. import java.util.Scanner;
  9. import java.util.Set;
  10.  
  11. public class Holgersson {
  12.  
  13. public static final String[] REGIONS = { "blekinge", "bohuslän", "dalarna", "dalsland", "gotland", "gästrikland",
  14. "halland", "hälsingland", "härjedalen", "jämtland", "lappland", "medelpad", "närke", "skåne", "småland",
  15. "södermanland", "uppland", "värmland", "västerbotten", "västergötland", "västmanland", "ångermanland",
  16. "öland", "östergötland" };
  17.  
  18. public static void main(String[] args) throws FileNotFoundException {
  19.  
  20. long t0 = System.nanoTime();
  21.  
  22. List<TextProcessor> wordList = new ArrayList<TextProcessor>();
  23.  
  24. TextProcessor p = new SingleWordCounter("nils");
  25. TextProcessor norge = new SingleWordCounter("norge");
  26. TextProcessor multi = new MultiWordCounter(REGIONS);
  27.  
  28. Scanner scan = new Scanner(new File("undantagsord.txt"));
  29. Set<String> stopwords = new HashSet<String>();
  30. while (scan.hasNext()) {
  31. stopwords.add(scan.next());
  32. }
  33. TextProcessor undantag = new GeneralWordCounter(stopwords);
  34.  
  35. wordList.add(p);
  36. wordList.add(norge);
  37. wordList.add(multi);
  38. wordList.add(undantag);
  39.  
  40. Scanner s = new Scanner(new File("nilsholg.txt"));
  41. s.useDelimiter("(\\s|,|\\.|:|;|!|\\?|'|\\\")+"); // se handledning
  42.  
  43. while (s.hasNext()) {
  44. String word = s.next().toLowerCase();
  45. for (TextProcessor tp : wordList) {
  46. tp.process(word);
  47. }
  48.  
  49. }
  50.  
  51. s.close();
  52. scan.close();
  53.  
  54. for (TextProcessor tp : wordList) {
  55. tp.report();
  56. }
  57.  
  58. long t1 = System.nanoTime();
  59. System.out.println("tid: " + (t1 - t0) / 1000000.0 + " ms");
  60. // treemap 273, 290, 312
  61. // hashmap 243
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement