<commit_before><?php

namespace Sleimanx2\Plastic;

use Elasticsearch\ClientBuilder;
use Sleimanx2\Plastic\Map\Builder as MapBuilder;

class Connection
{

    /**
     * @var
     */
    protected $elastic;

    /**
     * @var array
     */
    private $config = [
        'hosts'   => ['localhost:9200'],
        'retries' => 2
    ];


    /**
     * Connection constructor.
     *
     * @param array $config
     */
    public function __construct(array $config = [])
    {
        $this->config = $config;

        $this->elastic = $this->initClient();
    }


    /**
     * Get map builder instance for this connection
     *
     * @return MapBuilder
     */
    public function getMapBuilder()
    {
        return new MapBuilder($this);
    }

    /**
     * Create an elastic search instance
     *
     * @return \Elasticsearch\Client
     */
    private function initClient()
    {
        return ClientBuilder::create()
            ->setHosts($this->config['hosts'])
            ->setRetries($this->config['retries'])
            ->build();
    }
}<commit_msg>get method for map grammar<commit_after><?php

namespace Sleimanx2\Plastic;

use Elasticsearch\ClientBuilder;
use Sleimanx2\Plastic\Map\Builder as MapBuilder;
use Sleimanx2\Plastic\Map\Grammar as MapGrammar;

class Connection
{

    /**
     * Elasticsearch client instance
     *
     * @var
     */
    protected $elastic;

    /**
     * Default elastic config
     *
     * @var array
     */
    private $config = [
        'hosts'   => ['localhost:9200'],
        'retries' => 2,
        'index'   => 'default_index'
    ];

    /**
     * Connection constructor.
     *
     * @param array $config
     */
    public function __construct(array $config = [])
    {
        $this->config = empty($config) ? $this->config : $config;

        $this->elastic = $this->buildClient($this->config);

        $this->index = $this->config['index'];
    }

    /**
     * Get map builder instance for this connection
     *
     * @return MapBuilder
     */
    public function getMapBuilder()
    {
        return new MapBuilder($this);
    }

    /**
     * Get map grammar instance for this connection
     *
     * @return MapBuilder
     */
    public function getMapGrammar()
    {
        return new MapGrammar();
    }

    /**
     * Execute a map statement on index;
     *
     * @param $mappings
     * @return array
     */
    public function mapStatement($mappings)
    {
        return $this->elastic->indices()->putMapping(array_merge(['index' => $this->index], $mappings));
    }

    /**
     * Create an elastic search instance
     *
     * @param array $config
     * @return \Elasticsearch\Client
     */
    private function buildClient(array $config)
    {
        return ClientBuilder::create()
            ->setHosts($config['hosts'])
            ->setRetries($config['retries'])
            ->build();
    }
}
{'fraction_non_alphanumeric': 0.13514442916093536, 'fraction_numerical': 0.00515818431911967, 'mean_word_length': 1.974437627811861, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '3054220', 'n_tokens_mistral': 882, 'n_tokens_neox': 850, 'n_words': 186}