<commit_before><?php

namespace Joli\Jane;

use Joli\Jane\Guesser\Guess\ClassGuess;

class Schema
{
    /** @var string Origin of the schema (file or url path) */
    private $origin;

    /** @var string Namespace wanted for this schema */
    private $namespace;

    /** @var string Directory where to put files */
    private $directory;

    /** @var string Name of the root object in the schema (if needed) */
    private $rootName;

    /** @var ClassGuess[] List of classes associated to this schema */
    private $classes = [];

    /** @var string[] A list of references this schema is registered to */
    private $references;

    /** @var mixed Parsed schema */
    private $parsed;

    /**
     * Schema constructor.
     * @param string $origin
     * @param string $namespace
     * @param string $directory
     * @param string $rootName
     */
    public function __construct($origin, $namespace, $directory, $rootName)
    {
        $this->origin = $origin;
        $this->namespace = $namespace;
        $this->directory = $directory;
        $this->rootName = $rootName;
        $this->references = [$origin];
    }

    /**
     * @return string
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * @return string
     */
    public function getNamespace()
    {
        return $this->namespace;
    }

    /**
     * @return string
     */
    public function getDirectory()
    {
        return $this->directory;
    }

    /**
     * @return string
     */
    public function getRootName()
    {
        return $this->rootName;
    }

    public function addClass($reference, $class)
    {
        $this->classes[$reference] = $class;
    }

    public function getClass($reference)
    {
        if (!array_key_exists($reference, $this->classes)) {
            return null;
        }

        return $this->classes[$reference];
    }

    /**
     * @return ClassGuess[]
     */
    public function getClasses()
    {
        return $this->classes;
    }

    public function addReference($reference)
    {
        $this->references[] = $reference;
    }

    public function hasReference($reference)
    {
        return in_array($reference, $this->references, true);
    }

    /**
     * @return mixed
     */
    public function getParsed()
    {
        return $this->parsed;
    }

    /**
     * @param mixed $parsed
     */
    public function setParsed($parsed)
    {
        $this->parsed = $parsed;
    }
}
<commit_msg>Avoid multiple paths string for the same origin<commit_after><?php

namespace Joli\Jane;

use Joli\Jane\Guesser\Guess\ClassGuess;

class Schema
{
    /** @var string Origin of the schema (file or url path) */
    private $origin;

    /** @var string Namespace wanted for this schema */
    private $namespace;

    /** @var string Directory where to put files */
    private $directory;

    /** @var string Name of the root object in the schema (if needed) */
    private $rootName;

    /** @var ClassGuess[] List of classes associated to this schema */
    private $classes = [];

    /** @var string[] A list of references this schema is registered to */
    private $references;

    /** @var mixed Parsed schema */
    private $parsed;

    /**
     * Schema constructor.
     * @param string $origin
     * @param string $namespace
     * @param string $directory
     * @param string $rootName
     */
    public function __construct($origin, $namespace, $directory, $rootName)
    {
        $this->origin = $this->fixPath($origin);
        $this->namespace = $namespace;
        $this->directory = $directory;
        $this->rootName = $rootName;
        $this->references = [$this->origin];
    }

    /**
     * @return string
     */
    public function getOrigin()
    {
        return $this->origin;
    }

    /**
     * @return string
     */
    public function getNamespace()
    {
        return $this->namespace;
    }

    /**
     * @return string
     */
    public function getDirectory()
    {
        return $this->directory;
    }

    /**
     * @return string
     */
    public function getRootName()
    {
        return $this->rootName;
    }

    public function addClass($reference, $class)
    {
        $this->classes[$reference] = $class;
    }

    public function getClass($reference)
    {
        if (!array_key_exists($reference, $this->classes)) {
            return null;
        }

        return $this->classes[$reference];
    }

    /**
     * @return ClassGuess[]
     */
    public function getClasses()
    {
        return $this->classes;
    }

    public function addReference($reference)
    {
        $this->references[] = $reference;
    }

    public function hasReference($reference)
    {
        return in_array($reference, $this->references, true);
    }

    /**
     * @return mixed
     */
    public function getParsed()
    {
        return $this->parsed;
    }

    /**
     * @param mixed $parsed
     */
    public function setParsed($parsed)
    {
        $this->parsed = $parsed;
    }

    private function fixPath($path)
    {
        $path = preg_replace('~/{2,}~','/', $path);

        if ($path === '/') {
            return '/';
        }

        $pathParts = [];
        foreach(explode('/',rtrim($path,'/')) as $part) {
            if ('.' === $part) {
                continue;
            }

            if ('..' === $part && count($pathParts) > 0) {
                array_pop($pathParts);
                continue;
            }

            $pathParts[] = $part;
        }

        return implode('/',$pathParts);
    }
}

{'fraction_non_alphanumeric': 0.13575628006413681, 'fraction_numerical': 0.0003563156957063959, 'mean_word_length': 1.9133367929423974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '4283372', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1590, 'n_words': 411}