// Path: utils-basickit/src/main/java/com/cognitionis/utils_basickit/FileUtils.java
// public static boolean URL_exists(String URLName) {
//     boolean result = false;
//     try {
//         if (System.getProperty("DEBUG") != null
//                 && System.getProperty("DEBUG").equalsIgnoreCase("true")) {
//             System.err.println("EXISTS? " + ensureURL(URLName));
//         }
//         final URL url = new URL(ensureURL(URLName));
//         final URLConnection con = url.openConnection(); // this will return
//                                                         // an
//                                                         // {Http,Jar}UrlConnection
//                                                         // depending
//         if (url.getProtocol().equals("http")) {
//             final HttpURLConnection con_http = (HttpURLConnection) con;
//             HttpURLConnection.setFollowRedirects(false);
//             // HttpURLConnection.setInstanceFollowRedirects(false); // this
//             // might be needed
//             con_http.setRequestMethod("HEAD");
//             if (con_http.getResponseCode() == HttpURLConnection.HTTP_OK) {
//                 result = true;
//             }
//         } else {
//             con.connect(); // still does not work and requires external
//                            // resources
//             result = true;
//         }
//     } catch (final Exception e) {
//         if (System.getProperty("DEBUG") != null
//                 && System.getProperty("DEBUG").equalsIgnoreCase("true")) {
//             System.err.println("Errors found (FileUtils): URL (" + URLName
//                     + ") not found: " + e.getMessage() + "\n");
//             e.printStackTrace(System.err);
//         }
//         return false;
//     }
//     return result;
// }


import java.io.*;
import java.util.*;
import com.cognitionis.utils_basickit.*;
import static com.cognitionis.utils_basickit.FileUtils.URL_exists;
package com.cognitionis.nlp_lang_models;



/**
 *
 * @author Héctor Llorens
 * @since 2011
 *
 * This is an implementation of the famous Tenkle Text Categorization algorithm
 * based on character n-grams
 * Best known as TextCat
 *
 */
public class TextCategorizer {

    private final static int MIN_WORDS_4_CATEGORIZE = 5;
    private final static String DEFAULT_CATEGORY = "en"; // English

    private String conf_file_path = "/resources/lang_models/text_categorization/";
    private String conf_file_name = "indoeuropean.conf";
    //private String conf_file_path = "indoeuropean.conf";
    private ArrayList<TextCategorizerFingerprint> categories = new ArrayList();

    public TextCategorizer() {
        loadFingerprints();
    }

    public TextCategorizer(String conf_file_path) {
        this.conf_file_path = conf_file_path;
        loadFingerprints();
    }

    private void loadFingerprints() {
        this.categories.clear();
        try {
            // For our beloved Windows
            String extra = ""; // TODO check if this is really needed
            if (File.separator.equals("\\")) {
                extra = "\\";
            }
            String app_path = FileUtils.getApplicationPath(TextCategorizer.class);
            
// Path: utils-basickit/src/main/java/com/cognitionis/utils_basickit/FileUtils.java
// public static boolean URL_exists(String URLName) {
//     boolean result = false;
//     try {
//         if (System.getProperty("DEBUG") != null
//                 && System.getProperty("DEBUG").equalsIgnoreCase("true")) {
//             System.err.println("EXISTS? " + ensureURL(URLName));
//         }
//         final URL url = new URL(ensureURL(URLName));
//         final URLConnection con = url.openConnection(); // this will return
//                                                         // an
//                                                         // {Http,Jar}UrlConnection
//                                                         // depending
//         if (url.getProtocol().equals("http")) {
//             final HttpURLConnection con_http = (HttpURLConnection) con;
//             HttpURLConnection.setFollowRedirects(false);
//             // HttpURLConnection.setInstanceFollowRedirects(false); // this
//             // might be needed
//             con_http.setRequestMethod("HEAD");
//             if (con_http.getResponseCode() == HttpURLConnection.HTTP_OK) {
//                 result = true;
//             }
//         } else {
//             con.connect(); // still does not work and requires external
//                            // resources
//             result = true;
//         }
//     } catch (final Exception e) {
//         if (System.getProperty("DEBUG") != null
//                 && System.getProperty("DEBUG").equalsIgnoreCase("true")) {
//             System.err.println("Errors found (FileUtils): URL (" + URLName
//                     + ") not found: " + e.getMessage() + "\n");
//             e.printStackTrace(System.err);
//         }
//         return false;
//     }
//     return result;
// }


// Path: nlp-lang-models/src/main/java/com/cognitionis/nlp_lang_models/TextCategorizer.java
import java.io.*;
import java.util.*;
import com.cognitionis.utils_basickit.*;
import static com.cognitionis.utils_basickit.FileUtils.URL_exists;

package com.cognitionis.nlp_lang_models;



/**
 *
 * @author Héctor Llorens
 * @since 2011
 *
 * This is an implementation of the famous Tenkle Text Categorization algorithm
 * based on character n-grams
 * Best known as TextCat
 *
 */
public class TextCategorizer {

    private final static int MIN_WORDS_4_CATEGORIZE = 5;
    private final static String DEFAULT_CATEGORY = "en"; // English

    private String conf_file_path = "/resources/lang_models/text_categorization/";
    private String conf_file_name = "indoeuropean.conf";
    //private String conf_file_path = "indoeuropean.conf";
    private ArrayList<TextCategorizerFingerprint> categories = new ArrayList();

    public TextCategorizer() {
        loadFingerprints();
    }

    public TextCategorizer(String conf_file_path) {
        this.conf_file_path = conf_file_path;
        loadFingerprints();
    }

    private void loadFingerprints() {
        this.categories.clear();
        try {
            // For our beloved Windows
            String extra = ""; // TODO check if this is really needed
            if (File.separator.equals("\\")) {
                extra = "\\";
            }
            String app_path = FileUtils.getApplicationPath(TextCategorizer.class);
            
        if (!URL_exists(app_path+conf_file_path)) { // Check for external resoucre (outside classes)