Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package parser;
  2.  
  3. import org.jsoup.Jsoup;
  4. import org.jsoup.nodes.Document;
  5. import org.jsoup.nodes.Element;
  6. import org.jsoup.select.Elements;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.File;
  10. import java.io.FileReader;
  11. import java.io.IOException;
  12.  
  13. public class Parser
  14. {
  15. public static void main(String[] args) throws IOException {
  16.  
  17. String input = "files/index.html.txt";
  18. Words cuvinte = new Words();
  19. int result = cuvinte.words(input);
  20. System.out.println(result);
  21. }
  22. }
  23.  
  24.  
  25. package parser;
  26.  
  27. import java.io.BufferedReader;
  28. import java.io.File;
  29. import java.io.FileNotFoundException;
  30. import java.io.FileReader;
  31. import java.io.IOException;
  32. import java.nio.charset.Charset;
  33. import java.nio.charset.StandardCharsets;
  34. import java.nio.file.Files;
  35. import java.nio.file.Paths;
  36.  
  37. public class Words
  38. {
  39. public static int words(String input)
  40. {
  41. int count=0;
  42. Convert convert = new Convert();
  43. String in = "";
  44. try {
  45. in = convert.readFile(input, StandardCharsets.UTF_8);
  46. } catch (IOException e1) {
  47. // TODO Auto-generated catch block
  48. e1.printStackTrace();
  49. }
  50. //CountWords countWords = new CountWords();
  51. //int i = countWords.countWords(in);
  52. WordChecker wordChecker = new WordChecker();
  53. String str;
  54. for (String word : in.split(" "))
  55. {
  56. if(!wordChecker.check_for_word(word))
  57. {
  58. System.out.println(word);
  59. count++;
  60. }}
  61. return count;
  62. }
  63. }
  64.  
  65.  
  66. package parser;
  67.  
  68. import java.io.BufferedReader;
  69. import java.io.FileReader;
  70. import java.io.IOException;
  71.  
  72. public class WordChecker
  73. {
  74. public static boolean check_for_word(String word) {
  75. // System.out.println(word);
  76. try {
  77. //BufferedReader in = new BufferedReader(new FileReader("/usr/share/dict/linux.words"));
  78. BufferedReader in = new BufferedReader(new FileReader("files/stopwords"));
  79. String str;
  80. while ((str = in.readLine()) != null) {
  81. if (str.indexOf(word) != -1) {
  82. return true;
  83.  
  84. }
  85. }
  86. in.close();
  87. } catch (IOException e) {
  88. }
  89. return false;
  90. }
  91. }
  92.  
  93.  
  94. package parser;
  95.  
  96. import java.io.IOException;
  97. import java.nio.charset.Charset;
  98. import java.nio.file.Files;
  99. import java.nio.file.Paths;
  100.  
  101. public class Convert
  102. {
  103. static String readFile(String path, Charset encoding)
  104. throws IOException
  105. {
  106. System.out.println(path);
  107. byte[] encoded = Files.readAllBytes(Paths.get(path));
  108. return new String(encoded, encoding);
  109. }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement