Skip to content

Commit

Permalink
Merge pull request #63 from kiwilan/develop
Browse files Browse the repository at this point in the history
v2.3.3
  • Loading branch information
ewilan-riviere committed Jan 28, 2024
2 parents 94c63e5 + 1b30bba commit 5da90da
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiwilan/php-ebook",
"description": "PHP package to read metadata and extract covers from eBooks, comics and audiobooks.",
"version": "2.3.2",
"version": "2.3.3",
"keywords": [
"php",
"ebook",
Expand Down
314 changes: 287 additions & 27 deletions src/Tools/MetaTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,283 @@
use Kiwilan\Ebook\Ebook;
use Transliterator;

/**
* Convert eBook title and metadata to a slug.
*
* @method string getSlug() Get slug of book title with addional metadata, like `lord-of-the-rings-01-fellowship-of-the-ring-j-r-r-tolkien-1954-epub-en`.
* @method string getSlugSimple() Get simple slug of book title, like `the-fellowship-of-the-ring`.
* @method string getSeriesSlug() Get slug of serie title, like `lord-of-the-rings-j-r-r-tolkien-1954-epub-en`.
* @method string getSeriesSlugSimple() Get simple slug of serie title, like `the-lord-of-the-rings`.
*/
class MetaTitle
{
/** @var string[][] */
protected array $determiners = [];
/**
* @var string[][]
*/
public const DETERMINERS = [
'en' => [
'the ',
'a ',
'an ',
'some ',
'any ',
'this ',
'that ',
'my ',
'your ',
'his ',
'her ',
'its ',
'our ',
'their ',
'all ',
'both ',
'each ',
],
'fr' => [
'les ',
'l\' ',
'le ',
'la ',
'du ',
'de ',
'une ',
'au ',
'des ',
'ce ',
'cet ',
'cette ',
'ces ',
'mon ',
'ton ',
'son ',
'notre ',
'votre ',
'leur ',
'tous ',
'toutes ',
'chaque ',
],
'es' => [
'el ',
'la ',
'los ',
'las ',
'un ',
'una ',
'este ',
'esta ',
'estos ',
'estas ',
'mi ',
'tu ',
'su ',
'nuestro ',
'vuestro ',
'sus ',
'mío ',
'tuyo ',
'suyo ',
'algunos ',
'algunas ',
'todo ',
'toda ',
'todos ',
'todas ',
'otro ',
'otra ',
],
'it' => [
'il ',
'la ',
'i ',
'gli ',
'le ',
'un ',
'uno ',
'una ',
'alcuni ',
'alcune ',
'questo ',
'questa ',
'questi ',
'queste ',
'quel ',
'quella ',
'quelli ',
'quelle ',
'mia ',
'tua ',
'sua ',
'nostra ',
'vostra ',
'loro ',
'ogni ',
'tutti ',
'tutte ',
'alcuni ',
'alcune ',
'qualche ',
],
'de' => [
'der ',
'die ',
'das ',
'ein ',
'eine ',
'mein ',
'dein ',
'sein ',
'ihr ',
'unser ',
'euer ',
'ihr ',
'jeder ',
'jede ',
'jedes ',
'alle ',
'viel ',
'einige ',
'ein paar ',
'manche ',
'welcher ',
'welche ',
'welches ',
],
'pl' => [
'ten ',
'ta ',
'to ',
'te ',
'tamten ',
'tamta ',
'tamto ',
'jaki ',
'jaka ',
'jakie ',
'każdy ',
'każda ',
'każde ',
'wszystki ',
'wszystko ',
'wszyscy ',
'wszystkie ',
'który ',
'która ',
'które ',
'którzy ',
'której ',
'którego ',
'którym ',
],
'ru' => [
'этот ',
'эта ',
'это ',
'эти ',
'тот ',
'та ',
'то ',
'те ',
'весь ',
'вся ',
'всё ',
'все ',
'каждый ',
'каждая ',
'каждое ',
'каждые ',
'мой ',
'моя ',
'моё ',
'мои ',
'твой ',
'твоя ',
'твоё ',
'твои ',
'свой ',
'своя ',
'своё ',
'свои ',
'наш ',
'наша ',
'наше ',
'наши ',
'ваш ',
'ваша ',
'ваше ',
'ваши ',
'их ',
'их ',
'некоторые ',
'всякий ',
'любой ',
'каждый ',
],
'zh' => [
'',
'',
'一个 ',
'这些 ',
'那些 ',
],
'ja' => [
'これ ',
'それ ',
'あれ ',
'この ',
'その ',
'あの ',
],
'ko' => [
'',
'',
'',
'이것 ',
'그것 ',
'저것 ',
],
'ar' => [
'هذا ',
'هذه ',
'ذلك ',
'تلك ',
'هؤلاء ',
'تلكم ',
],
'pt' => [
'o ',
'a ',
'os ',
'as ',
'um ',
'uma ',
],
'nl' => [
'de ',
'het ',
'een ',
'deze ',
'dit ',
'die ',
],
'sv' => [
'den ',
'det ',
'en ',
'ett ',
'dessa ',
'dessa ',
],
'tr' => [
'bu ',
'şu ',
'o ',
'bir ',
'bu ',
'şu ',
],
];

protected function __construct(
protected ?string $slug = null,
Expand All @@ -18,32 +291,17 @@ protected function __construct(
) {
}

public static function make(
Ebook $ebook,
array $determiners = [
'en' => [
'the ',
'a ',
],
'fr' => [
'les ',
"l'",
'le ',
'la ',
"d'un",
"d'",
'une ',
'au ',
],
],
): ?self {
/**
* Create a new MetaTitle instance.
*/
public static function make(Ebook $ebook): ?self
{
if (! $ebook->getTitle()) {
return null;
}

$self = new self();

$self->determiners = $determiners;
$self->parse($ebook);

return $self;
Expand Down Expand Up @@ -100,6 +358,7 @@ private function parse(Ebook $ebook): static
* - Add serie title, here `Lord of the Rings`
* - Add volume, here `1`
* - Add author name, here `J. R. R. Tolkien`
* - Add year, here `1954`
* - Add extension, here `epub`
* - Add language, here `en`
*/
Expand All @@ -119,10 +378,11 @@ public function getSlugSimple(): string
/**
* Get slug of serie title, like `lord-of-the-rings-j-r-r-tolkien-1954-epub-en`.
*
* - Remove determiners
* - Add author name
* - Add extension
* - Add language
* - Remove determiners, here `The`
* - Add author name, here `J. R. R. Tolkien`
* - Add year, here `1954`
* - Add extension, here `epub`
* - Add language, here `en`
*/
public function getSeriesSlug(): ?string
{
Expand Down Expand Up @@ -199,7 +459,7 @@ private function removeDeterminers(?string $string, ?string $language): ?string
return null;
}

$articles = $this->determiners;
$articles = MetaTitle::DETERMINERS;

$articlesLang = $articles['en'];

Expand Down

0 comments on commit 5da90da

Please sign in to comment.