<commit_before><?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Expose;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\Groups;

use ApiPlatform\Core\Annotation as API;

use App\Model\PropositionInterface;
use App\Model\Exercise;

/**
 * @ORM\Entity
 * @ORM\Table(name="translation")
 *
 * @API\ApiResource(
 *     normalizationContext={"groups"={"read"}},
 *     attributes={"securit"="is_granted('ROLE_USER')"},
 *     collectionOperations={
 *          "get"={"security"="is_granted('ROLE_USER')"},
 *          "post"={
 *              "security"="is_granted('ROLE_ADMIN')",
 *              "normalization_context"={"groups"={"writeCollection"}}
 *          }
 *     },
 *     itemOperations={
 *          "get"={"security"="is_granted('ROLE_USER')"},
 *          "put"={"security"="is_granted('ROLE_ADMIN')"},
 *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
 *     }
 * )
 *
 * @Serializer\ExclusionPolicy("all")
 */
class Translation implements Exercise
{
    public $NOT_A_GROUP_DELIMITER_REGEX; // not ( [ {
    public $OPTION_GROUP_REGEX; // to find imediatly resolvable option groups such as (a|b|c) but not (a|b (c|d)|e)

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("id")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=225)
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("text")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $text;

    /**
     * @ORM\Column(type="array")
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     * @Serializer\Expose()
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $answers;

    /**
     * @ORM\ManyToOne(targetEntity="Lesson", inversedBy="translations", cascade={"persist"})
     * @ORM\JoinColumn(name="lesson_id", referencedColumnName="id")
     */
    protected $lesson;

    /**
     * @ORM\Column(type="integer", options={"default":1}, nullable=true)
     *
     * @Groups({"read", "writeLesson", "readItem"})
     */
    protected $difficulty;

    /**
     * @ORM\OneToMany(targetEntity="Complaint", mappedBy="translation", cascade={"persist", "remove"})
     */
    protected $complaints;

    /**
     * @ORM\Column(type="json")
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("words")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $words;

    public function __construct()
    {
        $this->NOT_A_GROUP_DELIMITER_REGEX = '[^\(\{\[]';
        $this->OPTION_GROUP_REGEX = sprintf(
            '/\(%s*?\|%s*?\)/',
           $this->NOT_A_GROUP_DELIMITER_REGEX,
           $this->NOT_A_GROUP_DELIMITER_REGEX
        );
        $this->complaints = new ArrayCollection();
    }

    public function matches(PropositionInterface $proposition)
    {
        return $this->caseInsensitiveStrictMatches($proposition);
    }

    public function strictMatches(PropositionInterface $proposition)
    {
        return $this->text === $proposition->getText();
    }

    public function caseInsensitiveStrictMatches(PropositionInterface $proposition)
    {
        return preg_match(sprintf("/%s/i", $proposition->getText()), $this->text);
    }

    public function getText()<commit_msg>Bugfix nullable translation words<commit_after><?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Expose;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\Groups;

use ApiPlatform\Core\Annotation as API;

use App\Model\PropositionInterface;
use App\Model\Exercise;

/**
 * @ORM\Entity
 * @ORM\Table(name="translation")
 *
 * @API\ApiResource(
 *     normalizationContext={"groups"={"read"}},
 *     attributes={"securit"="is_granted('ROLE_USER')"},
 *     collectionOperations={
 *          "get"={"security"="is_granted('ROLE_USER')"},
 *          "post"={
 *              "security"="is_granted('ROLE_ADMIN')",
 *              "normalization_context"={"groups"={"writeCollection"}}
 *          }
 *     },
 *     itemOperations={
 *          "get"={"security"="is_granted('ROLE_USER')"},
 *          "put"={"security"="is_granted('ROLE_ADMIN')"},
 *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
 *     }
 * )
 *
 * @Serializer\ExclusionPolicy("all")
 */
class Translation implements Exercise
{
    public $NOT_A_GROUP_DELIMITER_REGEX; // not ( [ {
    public $OPTION_GROUP_REGEX; // to find imediatly resolvable option groups such as (a|b|c) but not (a|b (c|d)|e)

    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("id")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=225)
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("text")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $text;

    /**
     * @ORM\Column(type="array")
     *
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     * @Serializer\Expose()
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $answers;

    /**
     * @ORM\ManyToOne(targetEntity="Lesson", inversedBy="translations", cascade={"persist"})
     * @ORM\JoinColumn(name="lesson_id", referencedColumnName="id")
     */
    protected $lesson;

    /**
     * @ORM\Column(type="integer", options={"default":1}, nullable=true)
     *
     * @Groups({"read", "writeLesson", "readItem"})
     */
    protected $difficulty;

    /**
     * @ORM\OneToMany(targetEntity="Complaint", mappedBy="translation", cascade={"persist", "remove"})
     */
    protected $complaints;

    /**
     * @ORM\Column(type="json")
     * @Groups({"read", "writeLesson", "readItem", "startLearningSession"})
     *
     * @Serializer\Expose()
     * @Serializer\SerializedName("words")
     * @Serializer\Groups({"startLearningSession"})
     */
    protected $words;

    public function __construct()
    {
        $this->NOT_A_GROUP_DELIMITER_REGEX = '[^\(\{\[]';
        $this->OPTION_GROUP_REGEX = sprintf(
            '/\(%s*?\|%s*?\)/',
           $this->NOT_A_GROUP_DELIMITER_REGEX,
           $this->NOT_A_GROUP_DELIMITER_REGEX
        );
        $this->complaints = new ArrayCollection();
        $this->words = [];
    }

    public function matches(PropositionInterface $proposition)
    {
        return $this->caseInsensitiveStrictMatches($proposition);
    }

    public function strictMatches(PropositionInterface $proposition)
    {
        return $this->text === $proposition->getText();
    }

    public function caseInsensitiveStrictMatches(PropositionInterface $proposition)
    {
        return preg_match(sprintf("/%s/i", $proposition->getText()), $this->text);
    }

    public function getText()
{'fraction_non_alphanumeric': 0.17301976999612353, 'fraction_numerical': 0.0010337252875048455, 'mean_word_length': 3.2809734513274336, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 24, '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': '5599808', 'n_tokens_mistral': 2525, 'n_tokens_neox': 2435, 'n_words': 333}