BVB Source Codes

Algorithm-Implementations Show StopWords.java Source code

Return Download Algorithm-Implementations: download StopWords.java Source code - Download Algorithm-Implementations Source code - Type:.java
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class StopWords {
  5.  
  6.     private static String OUTPUT_FILE = "YOUR_FILE_LOCATION";
  7.  
  8.     public static Boolean searchForStopWord(String word, List<String> textForCheck) {
  9.  
  10.         int indexOfWord = Collections.binarySearch(textForCheck,word);
  11.  
  12.         if(indexOfWord < 0)
  13.             return false;
  14.         else
  15.             return true;
  16.     }
  17.  
  18.     public static List<String> readStopWords(String stopWordsFilename) throws Exception {
  19.  
  20.             FileInputStream fStream = new FileInputStream(stopWordsFilename);
  21.  
  22.             DataInputStream dataStreamObject = new DataInputStream(fStream);
  23.             BufferedReader objectForBuffer = new BufferedReader(new InputStreamReader(dataStreamObject));
  24.  
  25.             String strLine;
  26.             String oneLinerString = "";
  27.  
  28.             while ((strLine = objectForBuffer.readLine()) != null) {
  29.                 strLine.trim();
  30.                 oneLinerString = oneLinerString + "," + strLine;
  31.             }
  32.  
  33.             List<String> tokenizedList = Arrays.asList(oneLinerString.split(","));
  34.             fStream.close();
  35.  
  36.             return tokenizedList;
  37.      }
  38.  
  39.     public static void removeStopWords(String textFilename, List<String> stopWords)  {
  40.  
  41.         try {
  42.             FileOutputStream outputStream = new FileOutputStream(OUTPUT_FILE);
  43.             PrintStream outputFileWriter = new PrintStream(outputStream);
  44.  
  45.             FileInputStream fStream = new FileInputStream(textFilename);
  46.             DataInputStream dataStreamObject = new DataInputStream(fStream);
  47.             BufferedReader objectForBuffer = new BufferedReader(new InputStreamReader(dataStreamObject));
  48.  
  49.             String strLine;
  50.  
  51.             while ((strLine = objectForBuffer.readLine()) != null) {
  52.  
  53.                 boolean flag = false;
  54.  
  55.                 List<String> tokenizedList = Arrays.asList(strLine.split("([^a-zA-z0-9])"));
  56.  
  57.                 for(int i=0;i<tokenizedList.size();i++) {
  58.  
  59.                     flag = searchForStopWord(tokenizedList.get(i), stopWords);
  60.  
  61.                     if (!flag)
  62.                         outputFileWriter.print(tokenizedList.get(i)+" ");
  63.  
  64.                     flag = false;
  65.                 }
  66.  
  67.                 outputFileWriter.print("\n");
  68.             }
  69.         }
  70.  
  71.         catch(Exception e){
  72.             System.err.println(e.getMessage());
  73.          }
  74.     }
  75.  
  76.     public static void main(String[] arg) throws Exception {
  77.  
  78.         Scanner keyboard = new Scanner(System.in);
  79.  
  80.         System.out.print("Please type stop words file name: ");
  81.         List<String> stopWords = readStopWords(keyboard.next());
  82.  
  83.         System.out.print("Please type text file name: ");
  84.         removeStopWords(keyboard.next(), stopWords);
  85.  
  86.     }
  87. }
  88.  
  89.  
downloadStopWords.java Source code - Download Algorithm-Implementations Source code
Related Source Codes/Software:
raty - 2017-04-22
RDVTabBarController - Highly customizable tabBar and tabBarController fo... 2017-04-22
material-icon-lib - Library containing over 1500 material vector icons... 2017-04-21
httpdiff - Perform the same request against two HTTP servers ... 2017-04-21
jquerytools - The missing UI library for the Web ... 2017-04-21
mcrouter - Mcrouter is a memcached protocol router for scalin... 2017-04-22
dynomite - A generic dynamo implementation for different k-v ... 2017-04-22
kityminder - Baidu brain figure 2017-04-22
llvm - Mirror of official llvm git repository located at ... 2017-04-22
RBBAnimation - Block-based animations made easy, comes with easin... 2017-04-22
ied - 2017-04-29
Nimble - A Matcher Framework for Swift and Objective-C 2017-04-29
MHVideoPhotoGallery - A Photo and Video Gallery 2017-04-29
shoulda-matchers - Collection of testing matchers extracted from Shou... 2017-04-29
Android-SlideExpandableListView - A better ExpandableListView, with animated expanda... 2017-04-29
AppSales-Mobile - App Sales allows iPhone and Mac App Store develope... 2017-04-29
react-templates - Light weight templates for react ... 2017-04-28
afterglow-theme - A minimal dark Theme for Sublime Text 2 and 3 2017-04-28
jwt-go - Golang implementation of JSON Web Tokens (JWT) 2017-04-28
DeerResume - Tool MarkDown online resume, online preview, edit,... 2017-04-28

 Back to top