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 2 of 2

Thread: please help! *find and remove "outcasts" in supposed to be alphabetic sorted list

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help! *find and remove "outcasts" in supposed to be alphabetic sorted list

    Hi,

    I'm writing my master thesis on document layout recognition and I'm writing a program on recognizing dictionary-pages.

    I have a list of what could be lemmas (~the "lookup word"). {cab, calculator, car, cat}.

    The list is supposed to be sorted in alphabetic order. But sometimes it isn't and I've gotten a word/words in to the list, which isn't supposed to be a lemma, that is, something that has fulfilled all the criterias of being a lemma, but in reality isn't has snuck in: {cab, calculator, cast, car, call, cat}.

    Now, I have to find the word that has been recognized as a lemma but isn't ('cause it doesn't follow the alphabetic order).
    I kind of need to find the path most of the words are following and then remove the outcasts.

    I'd love to post some example code of what I've been trying, but truth is, that after trying more than a dozen of different methods, I got so frustrated that I deleted everything.

    My main approach is to get sublists and find the part of the list where the faulty word is but then I kind of get stuck.

    Please, please help, or comment if I haven't explained good enough. I'm going crazy here!
    Last edited by Maria; March 15th, 2010 at 11:13 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help! *find and remove "outcasts" in supposed to be alphabetic sorted list

    Somehow I imagine this would be great to solve with recursion - something like this:

    /**
     * check if the lemmas are listed in alphabetic order. If not, remove fake lemmas.
     * @param lemmings
     * @param finished
     * @return correct lemma-list
     */private List<String> checkingLemmas(List<String> lemmings, ArrayList<String> finished){
    	if(isSorted(lemmings))
    		return lemmings;
    	if(lemmings.size() == 2){
    		//what to do here?
    		// I don't have anything to compare to anymore so I don't know which of the two to remove.
    		//went too far...
     
    	}
    	if(lemmings.size() == 3){
    		ArrayList<String> x = new ArrayList<String>();
    		x.add(lemmings.get(0));
    		x.add(lemmings.get(lemmings.size()-1));
    	}
     	List<String> list1 = lemmings.subList(0, (lemmings.size()/2));
    	List<String> list2 = lemmings.subList((lemmings.size()/2), (lemmings.size()-1));
     	if(isSorted(list1)){
     			finished.addAll(list1);
     			Collections.sort(finished);
    	}
    	else if(!isSorted(list1)){
    		finished.addAll(checkingLemmas(list1, finished));
    	}
    	if(isSorted(list2)){
    		finished.addAll(list2);
    		Collections.sort(finished);
    	}
    	else if(!isSorted(list2)){
    		finished.addAll(checkingLemmas(list2, finished));
    	}
    	return finished;
    }
    Last edited by Maria; March 15th, 2010 at 11:10 PM.

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 04:30 PM
  2. Replies: 2
    Last Post: March 23rd, 2010, 02:38 AM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM
  5. Replies: 4
    Last Post: August 13th, 2009, 06:54 AM

Tags for this Thread