maj words

This commit is contained in:
Jephté Clain 2025-01-24 13:18:54 +04:00
parent 0dfb30d395
commit 741c8ab9b2
2 changed files with 95 additions and 23 deletions

View File

@ -31,6 +31,8 @@ class Word {
private $fem;
/** @var string article "le", "la", "l'" */
private $le;
/** @var string article "ce", "cet", "cette" */
private $ce;
/** @var string article "du", "de la", "de l'" */
private $du;
/** @var string article "au", "à la", "à l'" */
@ -56,23 +58,27 @@ class Word {
}
if (preg_match('/^l\'\s*/i', $spec, $ms) && $fem !== null) {
$le = "l'";
$ce = "cet ";
$du = "de l'";
$au = "à l'";
$spec = substr($spec, strlen($ms[0]));
} elseif (preg_match('/^la\s+/i', $spec, $ms)) {
$fem = true;
$le = "la ";
$ce = "cette ";
$du = "de la ";
$au = "à la ";
$spec = substr($spec, strlen($ms[0]));
} elseif (preg_match('/^le\s+/i', $spec, $ms)) {
$fem = false;
$le = "le ";
$ce = "ce ";
$du = "du ";
$au = "au ";
$spec = substr($spec, strlen($ms[0]));
} else {
$le = null;
$ce = null;
$du = null;
$au = null;
}
@ -86,6 +92,7 @@ class Word {
}
$this->fem = $fem;
$this->le = $le;
$this->ce = $ce;
$this->du = $du;
$this->au = $au;
$this->w = $spec;
@ -99,10 +106,11 @@ class Word {
* @param bool|string $fem genre du nom avec lequel accorder les adjectifs,
* avec l'équivalence false==="M" et true==="F"
*/
function w($amount=1, bool $upper1=false, $fem=false): string {
function w($amount=1, bool $upper1=false, $fem=null): string {
if ($amount === true) $amount = 2;
elseif ($amount === false) $amount = 0;
$amount = abs($amount);
$fem ??= $this->fem;
$w = $this->w;
# marque du nombre
if ($amount <= 1) {
@ -136,8 +144,8 @@ class Word {
*
* @param bool|int $amount
*/
function u($amount=1, $fem=false): string {
return $this->w($amount, true, $fem);
function u($amount=1): string {
return $this->w($amount, true);
}
/**
@ -151,62 +159,121 @@ class Word {
}
/** retourner le mot sans article et avec la quantité */
function q(int $amount=1, $fem=false): string {
return $amount." ".$this->w($amount, $fem);
function q(int $amount=1): string {
return $amount." ".$this->w($amount);
}
/** retourner le mot sans article et avec la quantité $amount/$max */
function r(int $amount, int $max, $fem=false): string {
return "$amount/$max ".$this->w($amount, $fem);
function r(int $amount, int $max): string {
return "$amount/$max ".$this->w($amount);
}
/** retourner le mot avec l'article indéfini et la quantité */
function un(int $amount=1, $fem=false): string {
function un(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$aucun = $this->fem? "aucune ": "aucun ";
return $aucun.$this->w($amount, $fem);
return $aucun.$this->w($amount);
} elseif ($abs_amount == 1) {
$un = $this->fem? "une ": "un ";
return $un.$this->w($amount, $fem);
return $un.$this->w($amount);
} else {
return "les $amount ".$this->w($amount, $fem);
return "les $amount ".$this->w($amount);
}
}
function le(int $amount=1, $fem=false): string {
/** retourner le mot avec l'article indéfini mais sans la quantité */
function _un(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount <= 1) {
$un = $this->fem? "une ": "un ";
return $un.$this->w($amount);
} else {
return "les ".$this->w($amount);
}
}
function le(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$le = $this->fem? "la 0 ": "le 0 ";
return $le.$this->w($amount, $fem);
return $le.$this->w($amount);
} elseif ($abs_amount == 1) {
return $this->le.$this->w($amount, $fem);
return $this->le.$this->w($amount);
} else {
return "les $amount ".$this->w($amount, $fem);
return "les $amount ".$this->w($amount);
}
}
function du(int $amount=1, $fem=false): string {
function _le(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount <= 1) {
return $this->le.$this->w($amount);
} else {
return "les ".$this->w($amount);
}
}
function ce(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$ce = $this->fem? "cette 0 ": "ce 0 ";
return $ce.$this->w($amount);
} elseif ($abs_amount == 1) {
return $this->ce.$this->w($amount);
} else {
return "ces $amount ".$this->w($amount);
}
}
function _ce(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount <= 1) {
return $this->ce.$this->w($amount);
} else {
return "ces ".$this->w($amount);
}
}
function du(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$du = $this->fem? "de la 0 ": "du 0 ";
return $du.$this->w($amount, $fem);
return $du.$this->w($amount);
} elseif ($abs_amount == 1) {
return $this->du.$this->w($amount, $fem);
return $this->du.$this->w($amount);
} else {
return "des $amount ".$this->w($amount, $fem);
return "des $amount ".$this->w($amount);
}
}
function au(int $amount=1, $fem=false): string {
function _du(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount <= 1) {
return $this->du.$this->w($amount);
} else {
return "des ".$this->w($amount);
}
}
function au(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount == 0) {
$au = $this->fem? "à la 0 ": "au 0 ";
return $au.$this->w($amount, $fem);
return $au.$this->w($amount);
} elseif ($abs_amount == 1) {
return $this->au.$this->w($amount, $fem);
return $this->au.$this->w($amount);
} else {
return "aux $amount ".$this->w($amount, $fem);
return "aux $amount ".$this->w($amount);
}
}
function _au(int $amount=1): string {
$abs_amount = abs($amount);
if ($abs_amount <= 1) {
return $this->au.$this->w($amount);
} else {
return "aux ".$this->w($amount);
}
}
}

View File

@ -2,6 +2,11 @@
namespace nulib\text;
class words {
static function with($spec): Word {
if ($spec instanceof Word) return $spec;
else return new Word(strval($spec));
}
static function q(int $count, string $spec, bool $adjective=true): string {
$word = new Word($spec, $adjective);
return $word->q($count);