<commit_before>/*
 * 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 <NAME> <<EMAIL>>
 */
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();
        }
        if (DICT.contains(concatenatedWord) || DICT.contains(concatenatedWord.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)) {
                    lastGoodFirst = firstTerm;
                    if (DICT.contains(secondTerm)) {
                        return firstTerm + " " + secondTerm;
                    } else {
                        i++;
                    }
                    //return firstTerm + " " + secondTerm;
                } else {<commit_msg>Update: TrieSpellChecker.java<commit_after>/*
 * 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 <NAME> <<EMAIL>>
 */
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)) {
                    lastGoodFirst = firstTerm;
                    if (DICT.contains(secondTerm)) {
                        return firstTerm + " " + secondTerm;
                    } else {
                        i++;
                    }
                    //return firstTerm + " " + secondTerm;
                } else {
{'fraction_non_alphanumeric': 0.10993269426881501, 'fraction_numerical': 0.0014276973281664286, 'mean_word_length': 2.2348284960422165, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5993339', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1304, 'n_words': 280}