<commit_before><?php

/**
 * Base class for data objects.
 */
class Data implements JsonSerializable
{
	protected $data = [];

	public function __construct(array $data = null)
	{
		if($data)
			$this->set($data);
	}



	public function set(array $data): self
	{
		foreach($data as $k => $v)
			$this->{$k} = $v;
		
		return $this;
	}



	public function __get($key)
	{
		return $this->data[$key] ?? null;
	}

	public function __set($key, $value)
	{
		$this->data[$key] = $value;
	}	

	public function __isset($key)
	{
		return $this->{$key} !== null;
	}
	
	public function __unset($key)
	{
		unset($this->data[$key]);
	}

	public function __call($method, $args)
	{
		if(is_callable($this->data[$method]))
			return call_user_func_array($this->data[$method], $args);
	}



	/**
	 * JSON serialization.
	 */
	const SERIALIZE = false;
	public function jsonSerialize()
	{
		$keys = static::SERIALIZE;

		// Sanity check...
		if( ! is_bool($keys) && ! is_array($keys))
			throw new \Exception(get_class($this).'::SERIALIZE must be array of keys to serialize, or boolean (true=all, false=none)');
		
		// None (default)
		if($keys === false || $keys == [])
			return [];
<commit_msg>Added __toString for Data class.<commit_after><?php

/**
 * Base class for data objects.
 */
class Data implements JsonSerializable
{
	protected $data = [];

	public function __construct(array $data = null)
	{
		if($data)
			$this->set($data);
	}



	public function set(array $data): self
	{
		foreach($data as $k => $v)
			$this->{$k} = $v;
		
		return $this;
	}


	public function __toString()
	{
		return get_class($this);
	}


	public function __get($key)
	{
		return $this->data[$key] ?? null;
	}

	public function __set($key, $value)
	{
		$this->data[$key] = $value;
	}	

	public function __isset($key)
	{
		return $this->{$key} !== null;
	}
	
	public function __unset($key)
	{
		unset($this->data[$key]);
	}

	public function __call($method, $args)
	{
		if(is_callable($this->data[$method] ?? false))
			return call_user_func_array($this->data[$method], $args);
	}



	/**
	 * JSON serialization.
	 */
	const SERIALIZE = false;
	public function jsonSerialize()
	{
		$keys = static::SERIALIZE;

		// Sanity check...
		if( ! is_bool($keys) && ! is_array($keys))
			throw new \Exception(get_class($this).'::SERIALIZE must be array of keys to serialize, or boolean (true=all, false=none)');
		
		// None (default)
		if($keys === false || $keys == [])
			return [];

{'fraction_non_alphanumeric': 0.18192968111201963, 'fraction_numerical': 0.0, 'mean_word_length': 3.5398886827458256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2300352', 'n_tokens_mistral': 967, 'n_tokens_neox': 868, 'n_words': 204}