Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Remove words

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Remove words

    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


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Remove words

    If you're getting an error, please post it. To better communicate what you're trying to do, it would help to post the input file and show what the program is supposed to do.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    VagosM (March 22nd, 2014)

  4. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Remove words

    I dont take an error but an empty list.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Remove words

    There are three ArrayLists. Which one(s) are empty?
    Does the contents of the others look correct?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: February 10th, 2014, 06:24 AM
  2. Need to print the words
    By nimesh89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 26th, 2013, 05:27 AM
  3. Replies: 12
    Last Post: March 17th, 2013, 01:38 AM
  4. Adding add/remove button to add/remove tab
    By JMtrasfiero in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 27th, 2012, 11:24 AM
  5. Help: Num to words
    By shamed in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 7th, 2010, 06:55 PM