<commit_before>/*
 ** 2013 August 10
 **
 ** The author disclaims copyright to this source code.  In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.unity.rtti;

import info.ata4.io.DataInputReader;
import info.ata4.io.DataOutputWriter;
import info.ata4.log.LogUtils;
import info.ata4.unity.asset.AssetFile;
import info.ata4.unity.asset.ObjectPath;
import info.ata4.unity.util.ClassID;
import info.ata4.unity.util.UnityVersion;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class FieldTypeDatabase {
    
    private static final Logger L = LogUtils.getLogger();
    
    public static final int VERSION = 1;
    public static final String FILENAME = "structdb.dat";
    
    private static FieldTypeDatabase instance;

    public static FieldTypeDatabase getInstance() {
        if (instance == null) {
            instance = new FieldTypeDatabase();
        }
        return instance;
    }
    
    private HashMap<Pair<Integer, UnityVersion>, FieldTypeNode> nodeMap = new HashMap<>();
    private int learned;
    
    private FieldTypeDatabase() {
        load();
    }
    
    public int getLearned() {
        return learned;
    }
    
    public Map<Pair<Integer, UnityVersion>, FieldTypeNode> getFieldTypeMap() {
        return Collections.unmodifiableMap(nodeMap);
    }
    
    private void load() {
        L.info("Loading type database");
        
        // read database file, external or internal otherwise
        InputStream is;
        try {
            Path dbFile = Paths.get(FILENAME);
            String dbPath = "/resources/" + FILENAME;<commit_msg>Use database file relative to jar file instead of the cwd<commit_after>/*
 ** 2013 August 10
 **
 ** The author disclaims copyright to this source code.  In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.unity.rtti;

import info.ata4.io.DataInputReader;
import info.ata4.io.DataOutputWriter;
import info.ata4.log.LogUtils;
import info.ata4.unity.asset.AssetFile;
import info.ata4.unity.asset.ObjectPath;
import info.ata4.unity.util.ClassID;
import info.ata4.unity.util.UnityVersion;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class FieldTypeDatabase {
    
    private static final Logger L = LogUtils.getLogger();
    
    public static final int VERSION = 1;
    public static final String FILENAME = "structdb.dat";
    
    private static FieldTypeDatabase instance;

    public static FieldTypeDatabase getInstance() {
        if (instance == null) {
            instance = new FieldTypeDatabase();
        }
        return instance;
    }
    
    private HashMap<Pair<Integer, UnityVersion>, FieldTypeNode> nodeMap = new HashMap<>();
    private int learned;
    
    private FieldTypeDatabase() {
        load();
    }
    
    public int getLearned() {
        return learned;
    }
    
    public Map<Pair<Integer, UnityVersion>, FieldTypeNode> getFieldTypeMap() {
        return Collections.unmodifiableMap(nodeMap);
    }
    
    private void load() {
        L.info("Loading type database");
        
        // read database file, external or internal otherwise
        InputStream is;
        try {
            Path jarFile = Paths.get(FieldTypeDatabase.class.getProtectionDomain().getCodeSource().getLocation().toURI());
            Path dbFile = jarFile.resolveSibling(FILENAME);
            String dbPath = "/resources/" + FILENAME;
{'fraction_non_alphanumeric': 0.10203268234356318, 'fraction_numerical': 0.007971303308090873, 'mean_word_length': 3.207041072925398, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7550527', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1443, 'n_words': 404}