<commit_before><?php

namespace Sajari\Record;

use sajari\engine\Key as EngineKey;
use sajari\engine\Value as EngineValue;
use sajari\engine\Value\Repeated as EngineValueRepeated;

class Key
{
    /** @var $field string */
    private $field;
    private $value;

    /**
     * Key constructor.
     * @param $field string
     * @param $value
     */
    public function __construct($field, $value)
    {
        $this->field = $field;
        $this->value = $value;
    }

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

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

    /**
     * @return EngineKey
     */
    public function Proto()
    {
        $protoKey = new EngineKey();
        $protoKey->setField($this->field);

        $value = new EngineValue();
        if (is_array($this->value)) {
          $repeated = new EngineValueRepeated();
          foreach ($this->value as $v) {
            $repeated->addValues($v);
          }
          $value->setRepeated($repeated);
        } else if (is_null($this->value)) {
          $value->setNull(true);<commit_msg>Add Record Key constructor from Proto<commit_after><?php

namespace Sajari\Record;

use sajari\engine\Key as EngineKey;
use sajari\engine\Value as EngineValue;
use sajari\engine\Value\Repeated as EngineValueRepeated;

class Key
{
    /** @var $field string */
    private $field;
    private $value;

    /**
     * Key constructor.
     * @param $field string
     * @param $value
     */
    public function __construct($field, $value)
    {
        $this->field = $field;
        $this->value = $value;
    }

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

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

    public static function fromProto(\sajari\engine\Key $p)
    {
        $v = $p->getValue();
        if ($v->hasSingle()) {
            return new Key($p->getField(), $v->getSingle());
        } else if ($v->hasRepeated()) {
            return new Key($p->getField(), $v->getRepeated()->getValuesList());
        } else {
            return new Key($p->getField(), NULL);
        }
    }

    /**
     * @return EngineKey
     */
    public function Proto()
    {
        $protoKey = new EngineKey();
        $protoKey->setField($this->field);

        $value = new EngineValue();
        if (is_array($this->value)) {
          $repeated = new EngineValueRepeated();
          foreach ($this->value as $v) {
            $repeated->addValues($v);
          }
          $value->setRepeated($repeated);
        } else if (is_null($this->value)) {
          $value->setNull(true);
{'fraction_non_alphanumeric': 0.14834578441835647, 'fraction_numerical': 0.0, 'mean_word_length': 1.9383490073145246, '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': '3918251', 'n_tokens_mistral': 863, 'n_tokens_neox': 853, 'n_words': 189}