File size: 2,636 Bytes
cf14c12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <?php
namespace Ai\Domain\ValueObjects;
use JsonSerializable;
use Override;
class Classification implements JsonSerializable
{
public readonly bool $isFlagged;
public readonly bool $isHate;
public readonly bool $isHateThreatening;
public readonly bool $isHarassment;
public readonly bool $isHarassmentThreatening;
public readonly bool $isSefHarm;
public readonly bool $isSefHarmIntent;
public readonly bool $isSefHarmInstructions;
public readonly bool $isSexual;
public readonly bool $isSexualMinors;
public readonly bool $isViolence;
public readonly bool $isViolenceGraphic;
public function __construct(
array $flags = []
) {
$check = [
'hate', 'hate/threatening', 'harassment', 'harassment/threatening',
'self-harm', 'self-harm/intent', 'self-harm/instructions', 'sexual',
'sexual/minors', 'violence', 'violence/graphic'
];
$flags = array_filter($flags, fn ($flag) => in_array($flag, $check));
$this->isFlagged = count($flags) > 0;
$this->isHate = in_array('hate', $flags);
$this->isHateThreatening = in_array('hate/threatening', $flags);
$this->isHarassment = in_array('harassment', $flags);
$this->isHarassmentThreatening = in_array('harassment/threatening', $flags);
$this->isSefHarm = in_array('self-harm', $flags);
$this->isSefHarmIntent = in_array('self-harm/intent', $flags);
$this->isSefHarmInstructions = in_array('self-harm/instructions', $flags);
$this->isSexual = in_array('sexual', $flags);
$this->isSexualMinors = in_array('sexual/minors', $flags);
$this->isViolence = in_array('violence', $flags);
$this->isViolenceGraphic = in_array('violence/graphic', $flags);
}
#[Override]
public function jsonSerialize(): array
{
return [
'flagged' => $this->isFlagged,
'categories' => [
'hate' => $this->isHate,
'hate/threatening' => $this->isHateThreatening,
'harassment' => $this->isHarassment,
'harassment/threatening' => $this->isHarassmentThreatening,
'self-harm' => $this->isSefHarm,
'self-harm/intent' => $this->isSefHarmIntent,
'self-harm/instructions' => $this->isSefHarmInstructions,
'sexual' => $this->isSexual,
'sexual/minors' => $this->isSexualMinors,
'violence' => $this->isViolence,
'violence/graphic' => $this->isViolenceGraphic,
]
];
}
}
|