<commit_before><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\UsedKeywordsMemory;


use CultuurNet\UDB3\Keyword;

class KeywordUsed extends Event
{

    /**
     * @var Keyword
     */
    protected $keyword;

    /**
     * @var string
     */
    protected $userId;

    /**
     * @return Keyword
     */
    public function getKeyword()
    {
        return $this->keyword;
    }

    /**
     * @param string $userId
     * @param Keyword $keyword
     */
    public function __construct($userId, Keyword $keyword)
    {
        $this->userId = $userId;
        $this->keyword = $keyword;
    }

    public static function deserialize(array $data)
    {
        return new static($data['user_id'], unserialize($data['keyword']));
    }

    public function serialize()
    {
        return parent::serialize() + array(
            'keyword' => serialize($this->keyword),
        );
    }
}<commit_msg>iii-66: Add temporary compatibility layer for older events where keyword is not an object yet<commit_after><?php
/**
 * @file
 */

namespace CultuurNet\UDB3\UsedKeywordsMemory;


use CultuurNet\UDB3\Keyword;

class KeywordUsed extends Event
{

    /**
     * @var Keyword
     */
    protected $keyword;

    /**
     * @var string
     */
    protected $userId;

    /**
     * @return Keyword
     */
    public function getKeyword()
    {
        return $this->keyword;
    }

    /**
     * @param string $userId
     * @param Keyword $keyword
     */
    public function __construct($userId, Keyword $keyword)
    {
        $this->userId = $userId;
        $this->keyword = $keyword;
    }

    public static function deserialize(array $data)
    {
        $keyword = @unserialize($data['keyword']);
        // @todo Remove this temporary BC layer.
        // compatibility layer start
        if (false === $keyword) {
            $keyword = new Keyword($data['keyword']);
        }
        // compatibility layer end
        return new static($data['user_id'], $keyword);
    }

    public function serialize()
    {
        return parent::serialize() + array(
            'keyword' => serialize($this->keyword),
        );
    }
}
{'fraction_non_alphanumeric': 0.13274336283185842, 'fraction_numerical': 0.0027945971122496508, 'mean_word_length': 2.072961373390558, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2963349', 'n_tokens_mistral': 633, 'n_tokens_neox': 632, 'n_words': 148}