<commit_before><?php
namespace Bizgolf;

function loadLanguage($languageName)
{
    $baseDir = dirname(__DIR__);
    $language = require "{$baseDir}/languages/${languageName}.php";

    list($imageId) = \Hiatus\execX('docker images -q', [$language['tagName']]);
    if ($imageId === '') {
        file_put_contents('php://stderr', "Building image for language {$language['tagName']}.\n");

        $baseDir = dirname(__DIR__);
        \Hiatus\execX('docker build', ['-t' => $language['tagName'], "{$baseDir}/languages/{$language['tagName']}"]);
    }

    return $language;
}

/**
 * Creates a docker image based on the requested language with the given user script added to the image for execution.
 *
 * @param string $languageName One of the supported languages.
 * @param string $script The file path to the user's submission to test.
 * @param string|null $constantName The name of the constant to set, if a constant is being used.
 * @param mixed|null $constantValue The value of the constant to set, if a constant is being used.
 * @return array A description of the docker image that was created.
 * @throws Exception if unable to create docker image
 */
function createImage($languageName, $script, $constantName = null, $constantValue = null)<commit_msg>Document loadLanguage.<commit_after><?php
namespace Bizgolf;

/**
 * Loads a language specification and builds the docker image for it if it doesn't already exist.
 *
 * @param string $languageName The name of the language specification which is the name of the php file in the languages/ directory.
 * @return array The language specification includes:
 *     string tagName The name of the docker image tag for the language which is also the name of the directory that contains the Dockerfile.
 *     callable addConstant A function that takes a user script as a string, a constant name and a constant value and returns the user's script
 *         modified so that the constant is set to the given value for the execution of the script.
 *     callable executeCommand The command to execute a script for.  The script filename will be passed as an argument.
 *     callable disableFunctionality A function that takes an image specification and a string describing the functionality to be disabled.
 *         This function will disable the described functionality and return a new image specification for the image that won't allow the given
 *         functionality.
 */
function loadLanguage($languageName)
{
    $baseDir = dirname(__DIR__);
    $language = require "{$baseDir}/languages/${languageName}.php";

    list($imageId) = \Hiatus\execX('docker images -q', [$language['tagName']]);
    if ($imageId === '') {
        file_put_contents('php://stderr', "Building image for language {$language['tagName']}.\n");

        $baseDir = dirname(__DIR__);
        \Hiatus\execX('docker build', ['-t' => $language['tagName'], "{$baseDir}/languages/{$language['tagName']}"]);
    }

    return $language;
}

/**
 * Creates a docker image based on the requested language with the given user script added to the image for execution.
 *
 * @param string $languageName One of the supported languages.
 * @param string $script The file path to the user's submission to test.
 * @param string|null $constantName The name of the constant to set, if a constant is being used.
 * @param mixed|null $constantValue The value of the constant to set, if a constant is being used.
 * @return array A description of the docker image that was created.
 * @throws Exception if unable to create docker image
 */
function createImage($languageName, $script, $constantName = null, $constantValue = null)
{'fraction_non_alphanumeric': 0.10084954782132091, 'fraction_numerical': 0.0, 'mean_word_length': 4.069444444444445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1725416', 'n_tokens_mistral': 951, 'n_tokens_neox': 920, 'n_words': 426}