ajouter le support des articles

This commit is contained in:
Jephté Clain 2025-10-08 09:04:31 +04:00
parent ee058e00cd
commit 75c06e7038

View File

@ -28,17 +28,23 @@ use nulib\ValueException;
*/
class Word {
/** @var bool le mot est-il féminin? */
private $fem;
private bool $fem;
/** @var string article "aucun", "aucune" */
private ?string $aucun;
/** @var string article "un", "une" */
private ?string $un;
/** @var string article "le", "la", "l'" */
private $le;
private ?string $le;
/** @var string article "ce", "cet", "cette" */
private $ce;
private ?string $ce;
/** @var string article "de", "d'" */
private ?string $de;
/** @var string article "du", "de la", "de l'" */
private $du;
private ?string $du;
/** @var string article "au", "à la", "à l'" */
private $au;
private ?string $au;
/** @var string le mot sans article */
private $w;
private string $w;
function __construct(string $spec, bool $adjective=false) {
if (preg_match('/^f([eé]m(inin)?)?\s*:\s*/iu', $spec, $ms)) {
@ -57,28 +63,40 @@ class Word {
$fem = null;
}
if (preg_match('/^l\'\s*/i', $spec, $ms) && $fem !== null) {
$aucun = $fem? "aucune ": "aucun ";
$un = $fem? "une ": "un ";
$le = "l'";
$ce = "cet ";
$de = "d'";
$du = "de l'";
$au = "à l'";
$spec = substr($spec, strlen($ms[0]));
} elseif (preg_match('/^la\s+/i', $spec, $ms)) {
$fem = true;
$aucun = "aucune ";
$un = "une ";
$le = "la ";
$ce = "cette ";
$de = "de ";
$du = "de la ";
$au = "à la ";
$spec = substr($spec, strlen($ms[0]));
} elseif (preg_match('/^le\s+/i', $spec, $ms)) {
$fem = false;
$aucun = "aucun ";
$un = "un ";
$le = "le ";
$ce = "ce ";
$de = "de ";
$du = "du ";
$au = "au ";
$spec = substr($spec, strlen($ms[0]));
} else {
$aucun = null;
$un = null;
$le = null;
$ce = null;
$de = null;
$du = null;
$au = null;
}
@ -86,13 +104,16 @@ class Word {
# si c'est un nom, il faut l'article et le genre
if ($fem === null) {
throw new ValueException("Vous devez spécifier le genre du nom");
} elseif ($le === null || $du === null || $au === null) {
} elseif ($le === null) {
throw new ValueException("Vous devez spécifier l'article du nom");
}
}
$this->fem = $fem;
$this->aucun = $aucun;
$this->un = $un;
$this->le = $le;
$this->ce = $ce;
$this->de = $de;
$this->du = $du;
$this->au = $au;
$this->w = $spec;
@ -168,15 +189,25 @@ class Word {
return "$amount/$max ".$this->w($amount);
}
function pronom(): string {
return $this->fem? "elle": "il";
}
function articleAucun(): ?string {
return $this->un;
}
function articleUn(): ?string {
return $this->un;
}
/** retourner le mot avec l'article indéfini et la quantité */
function un(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$aucun = $this->fem? "aucune ": "aucun ";
return $aucun.$this->w($amount);
return $this->aucun.$this->w($amount);
} elseif ($abs_amount == 1) {
$un = $this->fem? "une ": "un ";
return $un.$this->w($amount);
return $this->un.$this->w($amount);
} else {
return "les $amount ".$this->w($amount);
}
@ -193,6 +224,10 @@ class Word {
}
}
function articleLe(): ?string {
return $this->le;
}
function le(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
@ -214,6 +249,10 @@ class Word {
}
}
function articleCe(): string {
return $this->ce;
}
function ce(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
@ -235,6 +274,18 @@ class Word {
}
}
function articleDe(): string {
return $this->de;
}
function _de(int $amount=1): string {
return $this->de.$this->w($amount);
}
function articleDu(): string {
return $this->du;
}
function du(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
@ -256,6 +307,10 @@ class Word {
}
}
function articleAu(): string {
return $this->au;
}
function au(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {