<commit_before><?php

namespace Gregwar\RST;

class Environment
{
    /**
     * Letters used as separators for titles and horizontal line
     */
    public static $letters = array(
        '=' => 1,
        '-' => 2,
        '~' => 3,
        '*' => 4
    );

    public static $tableLetter = '=';

    // Current file name
    protected $currentFileName = null;
    protected $currentDirectory = '.';
    protected $targetDirectory = '.';

    // Metas
    protected $metas = null;

    // Dependencies of this document
    protected $dependencies = array();

    // Variables of the document
    protected $variables = array();

    // Links
    protected $links = array();

    // Level counters
    protected $levels = array();
    protected $counters = array();

    // Anonymous links stack
    protected $anonymous = array();

    public function __construct()
    {
        foreach (self::$letters as $letter => $level) {
            $this->levels[$level] = 1;
            $this->counters[$level] = 0;
        }
    }

    public function setMetas($metas)
    {
        $this->metas = $metas;
    }

    /**
     * Resolves a reference URL
     */
    public function resolve($url)
    {
        $url = $this->canonicalUrl($url);

        if ($this->metas) {
            $entry = $this->metas->get($url);<commit_msg>Adding getMyToc()<commit_after><?php

namespace Gregwar\RST;

class Environment
{
    /**
     * Letters used as separators for titles and horizontal line
     */
    public static $letters = array(
        '=' => 1,
        '-' => 2,
        '~' => 3,
        '*' => 4
    );

    public static $tableLetter = '=';

    // Current file name
    protected $currentFileName = null;
    protected $currentDirectory = '.';
    protected $targetDirectory = '.';

    // Metas
    protected $metas = null;

    // Dependencies of this document
    protected $dependencies = array();

    // Variables of the document
    protected $variables = array();

    // Links
    protected $links = array();

    // Level counters
    protected $levels = array();
    protected $counters = array();

    // Anonymous links stack
    protected $anonymous = array();

    public function __construct()
    {
        foreach (self::$letters as $letter => $level) {
            $this->levels[$level] = 1;
            $this->counters[$level] = 0;
        }
    }

    public function setMetas($metas)
    {
        $this->metas = $metas;
    }

    /**
     * Get the docs involving this document
     */
    public function getMyToc()
    {
        if (!$this->currentFileName || !$this->metas) {
            return null;
        }

        $meta = $this->metas->get($this->currentFileName);

        if (!$meta || !isset($meta['parent'])) {
            return null;
        }

        $parent = $this->metas->get($meta['parent']);

        if (!$parent) {
            return null;
        }

        foreach ($parent['tocs'] as $toc) {
            if (in_array($this->currentFileName, $toc)) {
                $before = array();
                $after = $toc;

                while ($after) {
                    $file = array_shift($after);
                    if ($file == $this->currentFileName) {
                        return array($before, $after);
                    }
                    $before[] = $file;
                }
            }
        }

        return null;
    }

    /**
     * Resolves a reference URL
     */
    public function resolve($url)
    {
        $url = $this->canonicalUrl($url);

        if ($this->metas) {
            $entry = $this->metas->get($url);
{'fraction_non_alphanumeric': 0.14408661854525265, 'fraction_numerical': 0.003331482509716824, 'mean_word_length': 1.7110609480812642, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '1015513', 'n_tokens_mistral': 1069, 'n_tokens_neox': 996, 'n_words': 254}