Hello , i have to remove from text files stop words , first i load text with stop words and put them in the arraylist after take the file i want to remove the stop words and put every word in an arraylist , after i try to remove from the listthe stop words but i cant make it i try to make a new arraylist and put the not stopwords in the new list but i take null.
the code
public class Anaktisi { public static void main(String[] args)throws IOException{ String fileQue = "C:\\Users\\VagosM\\Desktop\\que.txt"; String fileStpWo = "C:\\Users\\VagosM\\Desktop\\stopwords.txt"; ArrayList listStpWo ; ArrayList listQue ; ArrayList list = null ; int i ,j ; String word = null; boolean flag = true; listStpWo=readSave(fileQue); // for(i=0;i<listStpWo.size();i++) // System.out.println(listStpWo.get(i)); listQue=readSave(fileQue); // for(i=0;i<listQue.size();i++) // System.out.println(listQue.get(i)); list=removeStopWords(listQue , listStpWo) for(i=0;i<list.size();i++) System.out.println(list.get(i)); } public static ArrayList readSave(String filePath){ ArrayList list = new ArrayList(); try { Scanner reader = new Scanner(new FileInputStream(filePath)); while(reader.hasNext()) { list.add(reader.next()); } reader.close(); } catch(FileNotFoundException ex) { System.out.println("Unable to open file '" + filePath + "'"); } return list; } public static ArrayList removeStopWords(ArrayList listQue , ArrayList list){ ArrayList listre = new ArrayList (); String word = null; int i ,j ; boolean flag = true; for(j = 0 ; j < listQue.size() ; j++){ for(i = 0 ; i < list.size() ; i++) { if((listQue.get(j)).equals(list.get(i))){ flag = false; break; } } if(flag!=false){ listre.add(word); System.out.println(word); } } return listre; } }
Thanks sorry if my english is bad