<commit_before>import jpype as jp
import os
import bayespy.utils
import platform

path_to_package = bayespy.utils.get_path_to_parent_dir(__file__)
separator = ";"
if platform.system() == "Linux":
    separator = ":"

classpath = ".{0}{1}{0}{2}".format(separator, os.path.join(path_to_package, 'bin/bayesserver-7.6.jar'),
                              os.path.join(path_to_package, 'bin/sqlite-jdbc-3.8.11.2.jar'))
if not jp.isJVMStarted():
    jp.startJVM(jp.getDefaultJVMPath(), "-Djava.class.path={}".format(classpath))
    bayesServer = jp.JPackage("com.bayesserver")
    sqlLite = jp.JPackage("org.sqlite.JDBC")
    bayesServerInference = jp.JPackage("com.bayesserver.inference")
    bayesServerParams = jp.JPackage("com.bayesserver.learning.parameters")<commit_msg>Adding a thread attach to the jni so it doesn't error out when called by Flask etc.<commit_after>import jpype as jp
import os
import bayespy.utils
import platform

path_to_package = bayespy.utils.get_path_to_parent_dir(__file__)
separator = ";"
if platform.system() == "Linux":
    separator = ":"

classpath = ".{0}{1}{0}{2}".format(separator, os.path.join(path_to_package, 'bin/bayesserver-7.6.jar'),
                              os.path.join(path_to_package, 'bin/sqlite-jdbc-3.8.11.2.jar'))
if not jp.isJVMStarted():
    jp.startJVM(jp.getDefaultJVMPath(), "-Djava.class.path={}".format(classpath))

    # so it doesn't crash if called by a Python thread.
    if not jp.isThreadAttachedToJVM():
        jp.attachThreadToJVM()

    bayesServer = jp.JPackage("com.bayesserver")
    sqlLite = jp.JPackage("org.sqlite.JDBC")
    bayesServerInference = jp.JPackage("com.bayesserver.inference")
    bayesServerParams = jp.JPackage("com.bayesserver.learning.parameters")
{'fraction_non_alphanumeric': 0.14614499424626007, 'fraction_numerical': 0.012658227848101266, 'mean_word_length': 4.144970414201183, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '601043', 'n_tokens_mistral': 650, 'n_tokens_neox': 621, 'n_words': 101}