<commit_before><?php
namespace Ivory;

use Ivory\Connection\Connection;
use Ivory\Connection\ConnectionParameters;
use Ivory\Connection\IConnection;
use Ivory\Exception\StatementExceptionFactory;
use Ivory\Lang;
use Ivory\Lang\SqlPattern\SqlPatternParser;
use Ivory\Type\Ivory\CommandRecipeType;
use Ivory\Type\Ivory\IdentifierType;
use Ivory\Type\Ivory\QuotedIdentifierType;
use Ivory\Type\Ivory\RelationRecipeType;
use Ivory\Type\Ivory\SqlType;
use Ivory\Type\Std\StdRangeCanonicalFuncProvider;
use Ivory\Type\Std\StdTypeLoader;
use Ivory\Type\TypeRegister;

/**
 * The standard factory for the core Ivory objects.
 *
 * The factory may either be inherited or replaced altogether to change any default behaviour of Ivory. The user
 * supplied factory may be activated with {@link Ivory::setCoreFactory()}. Note, however, that {@link Ivory} caches the
 * objects so setting another core factory is only effective at the very beginning of working with Ivory.
 */
class StdCoreFactory implements ICoreFactory
{
    public function createTypeRegister() : TypeRegister
    {
        $reg = new TypeRegister();
        $reg->registerTypeLoader(new StdTypeLoader());
        $reg->registerRangeCanonicalFuncProvider(new StdRangeCanonicalFuncProvider());

        $reservedTypes = Lang\Sql\Types::getReservedTypes();
        foreach ($reservedTypes as $alias => list($implSchema, $implName)) {
            $reg->registerTypeAbbreviation($alias, $implSchema, $implName);
        }

        // standard non-volatile type converters for SQL patterns; volatile ones will be defined on the connection
        $reg->registerSqlPatternType('sql', new SqlType());
        $reg->registerSqlPatternType('ident', new IdentifierType());
        $reg->registerSqlPatternType('qident', new QuotedIdentifierType());

        // standard type abbreviations
        $reg->registerTypeAbbreviation('s', 'pg_catalog', 'text');
        $reg->registerTypeAbbreviation('d', 'pg_catalog', 'int');
        $reg->registerTypeAbbreviation('D', 'pg_catalog', 'bigint');
        $reg->registerTypeAbbreviation('n', 'pg_catalog', 'numeric');
        $reg->registerTypeAbbreviation('f', 'pg_catalog', 'float8');
        $reg->registerTypeAbbreviation('b', 'pg_catalog', 'bool');
        $reg->registerTypeAbbreviation('a', 'pg_catalog', 'date'); // FIXME: come up with a reasonable abbreviation for the date type
        $reg->registerTypeAbbreviation('t', 'pg_catalog', 'time');
        $reg->registerTypeAbbreviation('ts', 'pg_catalog', 'timestamp');
        $reg->registerTypeAbbreviation('tstz', 'pg_catalog', 'timestamptz');

        return $reg;
    }

    public function createSqlPatternParser() : SqlPatternParser
    {
        return new SqlPatternParser();
    }

    public function createStatementExceptionFactory() : StatementExceptionFactory
    {
        return new StatementExceptionFactory();
    }

    public function createConnection(string $connName, ConnectionParameters $params) : IConnection
    {
        $conn = new Connection($connName, $params);
<commit_msg>StdCoreFactory: do not register abbreviations for "date" and "time" data types<commit_after><?php
namespace Ivory;

use Ivory\Connection\Connection;
use Ivory\Connection\ConnectionParameters;
use Ivory\Connection\IConnection;
use Ivory\Exception\StatementExceptionFactory;
use Ivory\Lang;
use Ivory\Lang\SqlPattern\SqlPatternParser;
use Ivory\Type\Ivory\CommandRecipeType;
use Ivory\Type\Ivory\IdentifierType;
use Ivory\Type\Ivory\QuotedIdentifierType;
use Ivory\Type\Ivory\RelationRecipeType;
use Ivory\Type\Ivory\SqlType;
use Ivory\Type\Std\StdRangeCanonicalFuncProvider;
use Ivory\Type\Std\StdTypeLoader;
use Ivory\Type\TypeRegister;

/**
 * The standard factory for the core Ivory objects.
 *
 * The factory may either be inherited or replaced altogether to change any default behaviour of Ivory. The user
 * supplied factory may be activated with {@link Ivory::setCoreFactory()}. Note, however, that {@link Ivory} caches the
 * objects so setting another core factory is only effective at the very beginning of working with Ivory.
 */
class StdCoreFactory implements ICoreFactory
{
    public function createTypeRegister() : TypeRegister
    {
        $reg = new TypeRegister();
        $reg->registerTypeLoader(new StdTypeLoader());
        $reg->registerRangeCanonicalFuncProvider(new StdRangeCanonicalFuncProvider());

        $reservedTypes = Lang\Sql\Types::getReservedTypes();
        foreach ($reservedTypes as $alias => list($implSchema, $implName)) {
            $reg->registerTypeAbbreviation($alias, $implSchema, $implName);
        }

        // standard non-volatile type converters for SQL patterns; volatile ones will be defined on the connection
        $reg->registerSqlPatternType('sql', new SqlType());
        $reg->registerSqlPatternType('ident', new IdentifierType());
        $reg->registerSqlPatternType('qident', new QuotedIdentifierType());

        // standard type abbreviations
        $reg->registerTypeAbbreviation('s', 'pg_catalog', 'text');
        $reg->registerTypeAbbreviation('d', 'pg_catalog', 'int');
        $reg->registerTypeAbbreviation('D', 'pg_catalog', 'bigint');
        $reg->registerTypeAbbreviation('n', 'pg_catalog', 'numeric');
        $reg->registerTypeAbbreviation('f', 'pg_catalog', 'float8');
        $reg->registerTypeAbbreviation('b', 'pg_catalog', 'bool');
        $reg->registerTypeAbbreviation('ts', 'pg_catalog', 'timestamp');
        $reg->registerTypeAbbreviation('tstz', 'pg_catalog', 'timestamptz');

        return $reg;
    }

    public function createSqlPatternParser() : SqlPatternParser
    {
        return new SqlPatternParser();
    }

    public function createStatementExceptionFactory() : StatementExceptionFactory
    {
        return new StatementExceptionFactory();
    }

    public function createConnection(string $connName, ConnectionParameters $params) : IConnection
    {
        $conn = new Connection($connName, $params);

{'fraction_non_alphanumeric': 0.11498491451558833, 'fraction_numerical': 0.00033523298692591353, 'mean_word_length': 4.313446126447017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4865168', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1627, 'n_words': 413}