/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.trie.spellchecker;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Leandro Ordonez <leandro.ordone.ante@gmail.com>
 */
public class TrieSpellChecker {

    public static final List<String> DICT = new ArrayList<>();

    public static void initialize() {
        try {
            InputStream dictStream = TrieSpellChecker.class.getResourceAsStream("/org/trie/util/american-english");
            BufferedReader br = new BufferedReader(new InputStreamReader(dictStream));
            String line;
            while ((line = br.readLine()) != null) {
                DICT.add(line);
            }
//            System.out.println(DICT);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(TrieSpellChecker.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TrieSpellChecker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static String compoundSplitter(String concatenatedWord) {
        return compoundSplitter(concatenatedWord, 0);
    }

    private static String compoundSplitter(String concatenatedWord, int level) {
        if (DICT.isEmpty()) {
            initialize();
        }
        String altConcatenatedWord = new StringBuffer(concatenatedWord).insert(concatenatedWord.length()-1, "'").toString();
        if (DICT.contains(concatenatedWord) || DICT.contains(concatenatedWord.toLowerCase()) || DICT.contains(altConcatenatedWord) || DICT.contains(altConcatenatedWord.toLowerCase())) {
            return concatenatedWord;
        } else {
            String firstTerm, secondTerm, lastGoodFirst = "#none";
            int i = 2;
            while (i <= concatenatedWord.length()) {
                firstTerm = concatenatedWord.substring(0, i);
                secondTerm = concatenatedWord.substring(i);
                if (DICT.contains(firstTerm)  || DICT.contains(firstTerm.toLowerCase())) {
                    lastGoodFirst = firstTerm;
                    if (DICT.contains(secondTerm)) {
                        return firstTerm + " " + secondTerm;
                    } else {
                        i++;
                    }
                    //return firstTerm + " " + secondTerm;
                } else {
                    if (firstTerm.equals(concatenatedWord)) {
                        if(level < 1 && !lastGoodFirst.equals("#none")){
                            return lastGoodFirst + " " + compoundSplitter(concatenatedWord.substring(lastGoodFirst.length()), level+1);
                        } else {
                            return (level > 0)? "\b" + concatenatedWord : concatenatedWord;
                        }
                    } else {
                        i++;
                    }
                }

            }
//            System.out.println(lastFirstCorrect);
        }
        return concatenatedWord;
    }

    public static void main(String[] args) {
        System.out.println(TrieSpellChecker.compoundSplitter("housenumbernumeric")); // -> house number numeric
        System.out.println(TrieSpellChecker.compoundSplitter("wickedweather"));      // -> wicked weather
        System.out.println(TrieSpellChecker.compoundSplitter("liquidweather"));      // -> liquid weather
        System.out.println(TrieSpellChecker.compoundSplitter("driveourtrucks"));     // -> drive our trucks
        System.out.println(TrieSpellChecker.compoundSplitter("gocompact"));          // -> go compact
        System.out.println(TrieSpellChecker.compoundSplitter("slimprojector"));      // -> slim projector
        System.out.println(TrieSpellChecker.compoundSplitter("orcore"));             // -> or core
        System.out.println(TrieSpellChecker.compoundSplitter("zipcode"));            // -> zip code
        System.out.println(TrieSpellChecker.compoundSplitter("asdkjkeerver"));       // -> asdkjkeerver
    }
}

@@ -1650,17 +1650,19 @@
 length()
--
+ - 
 1, %22'%22).
@@ -2222,17 +2222,16 @@
 rstTerm)
- 
  %7C%7C DICT
@@ -2591,38 +2591,16 @@
  %7D else 
-%7B%0A                    
 if (firs
@@ -2653,22 +2653,19 @@
         
-    
 if
+ 
 (level %3C
@@ -2701,16 +2701,17 @@
 #none%22))
+ 
 %7B%0A      
@@ -2724,28 +2724,24 @@
             
-  
-  
 return lastG
@@ -2835,17 +2835,15 @@
 evel
-+
+ + 
 1);%0A
-    
     
@@ -2887,28 +2887,24 @@
             
- 
-   
 return (leve
@@ -2909,16 +2909,17 @@
 vel %3E 0)
+ 
 ? %22%5Cb%22 +
@@ -2972,32 +2972,26 @@
             
-    %7D%0A  
+%7D%0A
             
@@ -2986,34 +2986,32 @@
                 
-  
 %7D else %7B%0A       
@@ -3019,37 +3019,29 @@
             
-    
 i++;%0A
-    
             
@@ -3050,27 +3050,8 @@
   %7D%0A
-                %7D%0A%0A
     

Update TrieSpellChecker.java