Search: countries named in the phrase filter by company country (Q6)
"pigment Italie" only matched "pigment": the country was neither a tag nor in the AND query fields, and the model matched Italian-sounding names. Country names and demonyms (FR/EN, 259 countries, CountryForms generated from Drupal and Wikidata) are detected in the phrase, taken out of the keywords and of the model phrase, and become a condition: manufacturer or distributor country, or tag of the same name. Results: exact matches and neighbours of the country first, then the same search without country. Index: manufacturer_country and distributor_country (reference paths, reindexed when a company changes). A country alone lists its records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ dependencies:
|
|||||||
- field.storage.node.field_short_description
|
- field.storage.node.field_short_description
|
||||||
- field.storage.node.field_tags
|
- field.storage.node.field_tags
|
||||||
- field.storage.node.field_thesaurus
|
- field.storage.node.field_thesaurus
|
||||||
|
- field.storage.taxonomy_term.field_public_address
|
||||||
- field.storage.taxonomy_term.field_synonyms
|
- field.storage.taxonomy_term.field_synonyms
|
||||||
- search_api.server.materio
|
- search_api.server.materio
|
||||||
module:
|
module:
|
||||||
@@ -77,6 +78,17 @@ field_settings:
|
|||||||
dependencies:
|
dependencies:
|
||||||
module:
|
module:
|
||||||
- node
|
- node
|
||||||
|
distributor_country:
|
||||||
|
label: 'Distributor » Country'
|
||||||
|
datasource_id: 'entity:node'
|
||||||
|
property_path: 'field_distributor:entity:field_public_address:country_code'
|
||||||
|
type: string
|
||||||
|
dependencies:
|
||||||
|
config:
|
||||||
|
- field.storage.node.field_distributor
|
||||||
|
- field.storage.taxonomy_term.field_public_address
|
||||||
|
module:
|
||||||
|
- taxonomy
|
||||||
field_country_name_computed:
|
field_country_name_computed:
|
||||||
label: 'Country Name'
|
label: 'Country Name'
|
||||||
datasource_id: 'entity:node'
|
datasource_id: 'entity:node'
|
||||||
@@ -111,6 +123,17 @@ field_settings:
|
|||||||
dependencies:
|
dependencies:
|
||||||
config:
|
config:
|
||||||
- field.storage.node.field_short_description
|
- field.storage.node.field_short_description
|
||||||
|
manufacturer_country:
|
||||||
|
label: 'Manufacturer » Country'
|
||||||
|
datasource_id: 'entity:node'
|
||||||
|
property_path: 'field_manufacturer:entity:field_public_address:country_code'
|
||||||
|
type: string
|
||||||
|
dependencies:
|
||||||
|
config:
|
||||||
|
- field.storage.node.field_manufacturer
|
||||||
|
- field.storage.taxonomy_term.field_public_address
|
||||||
|
module:
|
||||||
|
- taxonomy
|
||||||
name:
|
name:
|
||||||
label: 'Manufacturer » Terme de taxonomie » Nom'
|
label: 'Manufacturer » Terme de taxonomie » Nom'
|
||||||
datasource_id: 'entity:node'
|
datasource_id: 'entity:node'
|
||||||
@@ -418,9 +441,11 @@ processor_settings:
|
|||||||
preprocess_query: -20
|
preprocess_query: -20
|
||||||
all_fields: false
|
all_fields: false
|
||||||
aggregated_field: { }
|
aggregated_field: { }
|
||||||
|
auto_aggregated_fulltext_field: { }
|
||||||
content_access:
|
content_access:
|
||||||
weights:
|
weights:
|
||||||
preprocess_query: -50
|
preprocess_query: -50
|
||||||
|
custom_value: { }
|
||||||
double_quote_workaround:
|
double_quote_workaround:
|
||||||
weights:
|
weights:
|
||||||
postprocess_query: 0
|
postprocess_query: 0
|
||||||
@@ -443,16 +468,19 @@ processor_settings:
|
|||||||
- uuid
|
- uuid
|
||||||
replacement: '|9999999998|'
|
replacement: '|9999999998|'
|
||||||
entity_status: { }
|
entity_status: { }
|
||||||
|
entity_type: { }
|
||||||
html_filter:
|
html_filter:
|
||||||
weights:
|
weights:
|
||||||
preprocess_index: -15
|
preprocess_index: -15
|
||||||
preprocess_query: -49
|
preprocess_query: -49
|
||||||
all_fields: true
|
all_fields: true
|
||||||
fields:
|
fields:
|
||||||
|
- distributor_country
|
||||||
- field_country_name_computed
|
- field_country_name_computed
|
||||||
- field_famille
|
- field_famille
|
||||||
- field_reference
|
- field_reference
|
||||||
- field_short_description
|
- field_short_description
|
||||||
|
- manufacturer_country
|
||||||
- name
|
- name
|
||||||
- name_1
|
- name_1
|
||||||
- processed
|
- processed
|
||||||
@@ -478,11 +506,11 @@ processor_settings:
|
|||||||
title: true
|
title: true
|
||||||
alt: true
|
alt: true
|
||||||
tags:
|
tags:
|
||||||
b: 2
|
b: 2.0
|
||||||
h1: 5
|
h1: 5.0
|
||||||
h2: 3
|
h2: 3.0
|
||||||
h3: 2
|
h3: 2.0
|
||||||
strong: 2
|
strong: 2.0
|
||||||
language_with_fallback: { }
|
language_with_fallback: { }
|
||||||
rendered_item: { }
|
rendered_item: { }
|
||||||
solr_date_range:
|
solr_date_range:
|
||||||
@@ -493,6 +521,7 @@ tracker_settings:
|
|||||||
indexing_order: fifo
|
indexing_order: fifo
|
||||||
options:
|
options:
|
||||||
cron_limit: 50
|
cron_limit: 50
|
||||||
|
delete_on_fail: true
|
||||||
index_directly: true
|
index_directly: true
|
||||||
track_changes_in_references: true
|
track_changes_in_references: true
|
||||||
server: materio
|
server: materio
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ final class NeighbourSearch {
|
|||||||
* Language of the results; the current language by default.
|
* Language of the results; the current language by default.
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
* Number of neighbours (topK).
|
* Number of neighbours (topK).
|
||||||
|
* @param callable|null $alter
|
||||||
|
* Adds conditions to the Search API query, applied by Solr as pre-filters
|
||||||
|
* of the kNN search (countries of materio_sapi, Q6).
|
||||||
*
|
*
|
||||||
* @return array<int, float>
|
* @return array<int, float>
|
||||||
* Scores keyed by nid, best first, none when materio_ai is switched off.
|
* Scores keyed by nid, best first, none when materio_ai is switched off.
|
||||||
@@ -63,12 +66,12 @@ final class NeighbourSearch {
|
|||||||
* @throws \Drupal\search_api\SearchApiException
|
* @throws \Drupal\search_api\SearchApiException
|
||||||
* When Solr fails.
|
* When Solr fails.
|
||||||
*/
|
*/
|
||||||
public function search(string $phrase, ?string $langcode = NULL, int $limit = 100): array {
|
public function search(string $phrase, ?string $langcode = NULL, int $limit = 100, ?callable $alter = NULL): array {
|
||||||
// Switched off: no text is sent to the model, keyword results only.
|
// Switched off: no text is sent to the model, keyword results only.
|
||||||
if (!$this->embedder->isEnabled()) {
|
if (!$this->embedder->isEnabled()) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return $this->searchVector($this->embedder->embed($phrase), $langcode, $limit);
|
return $this->searchVector($this->embedder->embed($phrase), $langcode, $limit, $alter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +83,7 @@ final class NeighbourSearch {
|
|||||||
* @return array<int, float>
|
* @return array<int, float>
|
||||||
* Scores keyed by nid, best first.
|
* Scores keyed by nid, best first.
|
||||||
*/
|
*/
|
||||||
public function searchVector(array $vector, ?string $langcode = NULL, int $limit = 100): array {
|
public function searchVector(array $vector, ?string $langcode = NULL, int $limit = 100, ?callable $alter = NULL): array {
|
||||||
$dimension = (int) $this->configFactory->get('materio_ai.settings')->get('dimension');
|
$dimension = (int) $this->configFactory->get('materio_ai.settings')->get('dimension');
|
||||||
if (count($vector) !== $dimension || $limit <= 0) {
|
if (count($vector) !== $dimension || $limit <= 0) {
|
||||||
return [];
|
return [];
|
||||||
@@ -94,6 +97,9 @@ final class NeighbourSearch {
|
|||||||
// Only the item IDs are needed.
|
// Only the item IDs are needed.
|
||||||
$query->setOption('search_api_retrieved_field_values', ['search_api_id' => 'search_api_id']);
|
$query->setOption('search_api_retrieved_field_values', ['search_api_id' => 'search_api_id']);
|
||||||
$query->addTag(self::TAG);
|
$query->addTag(self::TAG);
|
||||||
|
if ($alter) {
|
||||||
|
$alter($query);
|
||||||
|
}
|
||||||
|
|
||||||
$scores = [];
|
$scores = [];
|
||||||
foreach ($query->execute() as $item_id => $item) {
|
foreach ($query->execute() as $item_id => $item) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Drupal\Component\Utility\Unicode;
|
use Drupal\Component\Utility\Unicode;
|
||||||
use Drupal\materio_ai\Exception\ModelPausedException;
|
use Drupal\materio_ai\Exception\ModelPausedException;
|
||||||
|
use Drupal\materio_sapi\CountryDetector;
|
||||||
use Drupal\materio_sapi\KeywordText;
|
use Drupal\materio_sapi\KeywordText;
|
||||||
use Drupal\materio_sapi\RankFusion;
|
use Drupal\materio_sapi\RankFusion;
|
||||||
use Drupal\materio_sapi\ScoreCut;
|
use Drupal\materio_sapi\ScoreCut;
|
||||||
@@ -122,6 +123,25 @@ class Base extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
protected $knn_count = 0;
|
protected $knn_count = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Countries named in the phrase (Q6): ISO codes, and the phrase without them.
|
||||||
|
*
|
||||||
|
* @var array{codes: string[], forms: string[], rest: string}
|
||||||
|
*/
|
||||||
|
protected $countries = ['codes' => [], 'forms' => [], 'rest' => ''];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags and thesaurus terms named like the countries found (japon, chine…).
|
||||||
|
*
|
||||||
|
* @var int[]|null
|
||||||
|
*/
|
||||||
|
private ?array $countryTermIds = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the queries are restricted to the countries found (Q6).
|
||||||
|
*/
|
||||||
|
private bool $countryFilter = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reference query, run before the others.
|
* The reference query, run before the others.
|
||||||
*
|
*
|
||||||
@@ -188,32 +208,87 @@ class Base extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keys without the references (« bois R0208 » searches « bois »).
|
// Keys without the references (« bois R0208 » searches « bois »).
|
||||||
$words = KeywordText::words(preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? $this->phrase, $lang);
|
$text = preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? $this->phrase;
|
||||||
|
$words = KeywordText::words($text, $lang);
|
||||||
// Only stop words: search the phrase as typed, as before.
|
// Only stop words: search the phrase as typed, as before.
|
||||||
$keys = $words ? implode(' ', $words) : implode(' ', $this->keys);
|
$keys = $words ? implode(' ', $words) : implode(' ', $this->keys);
|
||||||
|
|
||||||
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
// A country named in the phrase is a condition, not a keyword (Q6):
|
||||||
// Exact material names (like "wood-skin"), then all words.
|
// « pigment Italie » searches « pigment » among the records of Italian
|
||||||
$exact += $this->phraseQuery($keys, $lang);
|
// companies or tagged Italie. Not for a term chosen in the autocomplete.
|
||||||
$exact += $this->andQuery($keys, $lang);
|
$this->countries = $this->terms ? $this->countries : CountryDetector::detect($text);
|
||||||
|
$this->countryFilter = (bool) $this->countries['codes'];
|
||||||
|
$this->knn_count = 0;
|
||||||
|
if (!$this->countryFilter) {
|
||||||
|
[$nids, $uuids, $this->exactematch_count] = $this->rank($keys, $words, $lang, $exact, TRUE);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$rest = KeywordText::words($this->countries['rest'], $lang);
|
||||||
|
if (!$rest) {
|
||||||
|
// The country alone (« italien »): all its records, no model.
|
||||||
|
$exact += $this->countryQuery($lang);
|
||||||
$this->exactematch_count = count($exact);
|
$this->exactematch_count = count($exact);
|
||||||
|
$this->results = ['uuids' => array_column($exact, 1), 'nids' => array_column($exact, 0)];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||||
|
// A title may hold the country (« papier japonais »): whole phrase.
|
||||||
|
$exact += $this->phraseQuery($keys, $lang);
|
||||||
|
}
|
||||||
|
$keys = implode(' ', $rest);
|
||||||
|
// The country first: its exact matches, then its neighbours…
|
||||||
|
[$nids, $uuids, $this->exactematch_count] = $this->rank($keys, $rest, $lang, $exact, FALSE);
|
||||||
|
// …then the same search everywhere, as without a country, so that the
|
||||||
|
// list does not stop after a handful of records (51 Portuguese records
|
||||||
|
// in all, « céramique Portugal » gave 2 results, 30/11). Counted as
|
||||||
|
// close results: only the records of the country are exact.
|
||||||
|
$this->countryFilter = FALSE;
|
||||||
|
[$more, $more_uuids] = $this->rank($keys, $rest, $lang, [], TRUE);
|
||||||
|
$nids = array_merge($nids, array_values(array_diff($more, $nids)));
|
||||||
|
$uuids += $more_uuids;
|
||||||
|
}
|
||||||
|
|
||||||
// Exact matches first, then the neighbours that stand out (H6), merged
|
|
||||||
// with the OR query when it is on (H5). No neighbours: the OR query alone.
|
|
||||||
$neighbours = $this->neighbours($lang);
|
|
||||||
$or = ($neighbours === NULL || self::OR_WITH_KNN) ? $this->orQuery($keys, $lang) : [];
|
|
||||||
$neighbours = $neighbours === NULL ? [] : ScoreCut::aboveMean($neighbours, self::KNN_SIGMA);
|
|
||||||
$this->knn_count = count($neighbours);
|
|
||||||
$nids = RankFusion::fuse(array_keys($exact), array_filter([array_keys($or), array_keys($neighbours)]));
|
|
||||||
|
|
||||||
$uuids = array_column($exact + $or, 1, 0) + $this->uuids(array_diff(array_keys($neighbours), array_keys($exact + $or)));
|
|
||||||
$this->results = [
|
$this->results = [
|
||||||
'uuids' => array_map(static fn ($nid) => $uuids[$nid], $nids),
|
'uuids' => array_map(static fn ($nid) => $uuids[$nid], $nids),
|
||||||
'nids' => $nids,
|
'nids' => $nids,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exact matches first, then the neighbours that stand out (H6), merged with
|
||||||
|
* the OR query when it is on (H5). No neighbours: the OR query alone.
|
||||||
|
*
|
||||||
|
* @param string $keys
|
||||||
|
* Keys without stop words.
|
||||||
|
* @param string[] $words
|
||||||
|
* The same, as a list.
|
||||||
|
* @param array<int, array{0: mixed, 1: string}> $exact
|
||||||
|
* Exact matches already found (references, titles).
|
||||||
|
* @param bool $titles
|
||||||
|
* Whether to search the keys in the titles.
|
||||||
|
*
|
||||||
|
* @return array{0: array<int|string>, 1: array<int, string>, 2: int}
|
||||||
|
* Node IDs in order, their UUIDs keyed by nid, number of exact matches.
|
||||||
|
*/
|
||||||
|
private function rank(string $keys, array $words, string $lang, array $exact, bool $titles): array {
|
||||||
|
if (count($words) <= self::SHORT_QUERY_WORDS) {
|
||||||
|
// Exact material names (like "wood-skin"), then all words.
|
||||||
|
if ($titles) {
|
||||||
|
$exact += $this->phraseQuery($keys, $lang);
|
||||||
|
}
|
||||||
|
$exact += $this->andQuery($keys, $lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
$neighbours = $this->neighbours($lang);
|
||||||
|
$or = ($neighbours === NULL || self::OR_WITH_KNN) ? $this->orQuery($keys, $lang) : [];
|
||||||
|
$neighbours = $neighbours === NULL ? [] : ScoreCut::aboveMean($neighbours, self::KNN_SIGMA);
|
||||||
|
$this->knn_count += count($neighbours);
|
||||||
|
$nids = RankFusion::fuse(array_keys($exact), array_filter([array_keys($or), array_keys($neighbours)]));
|
||||||
|
|
||||||
|
$uuids = array_column($exact + $or, 1, 0) + $this->uuids(array_diff(array_keys($neighbours), array_keys($exact + $or)));
|
||||||
|
return [$nids, $uuids, count($exact)];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nodes closest in meaning to the phrase (materio_ai, Solr kNN).
|
* Nodes closest in meaning to the phrase (materio_ai, Solr kNN).
|
||||||
*
|
*
|
||||||
@@ -230,14 +305,17 @@ class Base extends ControllerBase {
|
|||||||
if ($this->terms || !\Drupal::hasService('materio_ai.neighbour_search')) {
|
if ($this->terms || !\Drupal::hasService('materio_ai.neighbour_search')) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// References are keywords: they mean nothing to the model.
|
// References are keywords: they mean nothing to the model. Neither do
|
||||||
$phrase = trim(preg_replace(self::REFERENCE_PATTERN, ' ', $this->phrase) ?? '');
|
// countries (« italien » brought Milano, Veneto): they filter instead (Q6).
|
||||||
|
$phrase = $this->countries['codes'] ? $this->countries['rest'] : $this->phrase;
|
||||||
|
$phrase = trim(preg_replace(self::REFERENCE_PATTERN, ' ', $phrase) ?? '');
|
||||||
if ($phrase === '') {
|
if ($phrase === '') {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
$alter = $this->countryFilter ? fn ($query) => $this->addCountryCondition($query) : NULL;
|
||||||
try {
|
try {
|
||||||
// Empty when materio_ai is switched off.
|
// Empty when materio_ai is switched off.
|
||||||
return \Drupal::service('materio_ai.neighbour_search')->search($phrase, $lang, self::KNN_LIMIT) ?: NULL;
|
return \Drupal::service('materio_ai.neighbour_search')->search($phrase, $lang, self::KNN_LIMIT, $alter) ?: NULL;
|
||||||
}
|
}
|
||||||
catch (\Throwable $e) {
|
catch (\Throwable $e) {
|
||||||
// Paused model: its failure was logged when it happened.
|
// Paused model: its failure was logged when it happened.
|
||||||
@@ -345,9 +423,66 @@ class Base extends ControllerBase {
|
|||||||
'tag_name',
|
'tag_name',
|
||||||
'tag_synonyms',
|
'tag_synonyms',
|
||||||
]);
|
]);
|
||||||
|
$this->addCountryCondition($this->and_query);
|
||||||
return $this->collect($this->and_query);
|
return $this->collect($this->and_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every record of the countries named in the phrase (Q6).
|
||||||
|
*
|
||||||
|
* @return array<int, array{0: mixed, 1: string}>
|
||||||
|
* [nid, uuid] keyed by nid, in result order.
|
||||||
|
*/
|
||||||
|
private function countryQuery(string $lang): array {
|
||||||
|
$query = $this->keywordQuery('terms', 'AND', '', $lang, 'materio_sapi_search_country_query');
|
||||||
|
$this->addCountryCondition($query);
|
||||||
|
return $this->collect($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restricts a query to the countries named in the phrase, if any (Q6).
|
||||||
|
*
|
||||||
|
* A record matches when its manufacturer or its distributor is in one of
|
||||||
|
* the countries, or when it has a tag or thesaurus term of the same name
|
||||||
|
* (japon, chine, inde…: both kept, decided on 30/11).
|
||||||
|
*
|
||||||
|
* @param \Drupal\search_api\Query\QueryInterface $query
|
||||||
|
* The query, not executed yet.
|
||||||
|
*/
|
||||||
|
private function addCountryCondition($query): void {
|
||||||
|
$codes = $this->countries['codes'];
|
||||||
|
if (!$this->countryFilter || !$codes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$group = $query->createConditionGroup('OR');
|
||||||
|
$group->addCondition('manufacturer_country', $codes, 'IN');
|
||||||
|
$group->addCondition('distributor_country', $codes, 'IN');
|
||||||
|
if ($tids = $this->countryTermIds()) {
|
||||||
|
$group->addCondition('tag_tid', $tids, 'IN');
|
||||||
|
$group->addCondition('thesaurus_tid', $tids, 'IN');
|
||||||
|
}
|
||||||
|
$query->addConditionGroup($group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags and thesaurus terms named like the countries found.
|
||||||
|
*
|
||||||
|
* @return int[]
|
||||||
|
* Term IDs.
|
||||||
|
*/
|
||||||
|
private function countryTermIds(): array {
|
||||||
|
if ($this->countryTermIds === NULL) {
|
||||||
|
$forms = CountryDetector::forms($this->countries['codes']);
|
||||||
|
// Accent and case insensitive in MariaDB (utf8mb4 collation).
|
||||||
|
$this->countryTermIds = $forms ? array_map('intval', array_values(\Drupal::entityQuery('taxonomy_term')
|
||||||
|
->accessCheck(FALSE)
|
||||||
|
->condition('vid', ['tags', 'thesaurus'], 'IN')
|
||||||
|
->condition('name', $forms, 'IN')
|
||||||
|
->execute())) : [];
|
||||||
|
}
|
||||||
|
return $this->countryTermIds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any word, in every fulltext field.
|
* Any word, in every fulltext field.
|
||||||
*
|
*
|
||||||
@@ -363,6 +498,7 @@ class Base extends ControllerBase {
|
|||||||
// Hyphenated words as separate words, as the direct mode did: in terms mode
|
// Hyphenated words as separate words, as the direct mode did: in terms mode
|
||||||
// « bio-based » would be a quoted phrase (the phrase query keeps it whole).
|
// « bio-based » would be a quoted phrase (the phrase query keeps it whole).
|
||||||
$this->or_query = $this->keywordQuery('terms', 'OR', preg_replace('/(?<=\p{L})-(?=\p{L})/u', ' ', $keys), $lang, 'materio_sapi_search_or_query');
|
$this->or_query = $this->keywordQuery('terms', 'OR', preg_replace('/(?<=\p{L})-(?=\p{L})/u', ' ', $keys), $lang, 'materio_sapi_search_or_query');
|
||||||
|
$this->addCountryCondition($this->or_query);
|
||||||
return $this->collect($this->or_query);
|
return $this->collect($this->or_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\materio_sapi;
|
||||||
|
|
||||||
|
use Drupal\Component\Transliteration\PhpTransliteration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the countries named in a search phrase (Q6).
|
||||||
|
*
|
||||||
|
* « pigment Italie » or « verre italien » ask for a place, not for a word of
|
||||||
|
* the records: the country is taken out of the phrase and becomes a
|
||||||
|
* condition (company of the country, or tag of the same name). Longest form
|
||||||
|
* first (« Corée du Sud » before « Corée »). A word typed with accents must
|
||||||
|
* match a form with the same accents (« chiné » is not « Chine »); a word
|
||||||
|
* typed without accents matches any form once folded (« bresil »).
|
||||||
|
*/
|
||||||
|
final class CountryDetector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Most words in a form (« united states of america »).
|
||||||
|
*/
|
||||||
|
private const MAX_WORDS = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codes keyed by form, accents kept, then accents removed.
|
||||||
|
*
|
||||||
|
* @var array{0: array<string, string[]>, 1: array<string, string[]>}|null
|
||||||
|
*/
|
||||||
|
private static ?array $maps = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a phrase into the countries it names and the rest.
|
||||||
|
*
|
||||||
|
* @return array{codes: string[], forms: string[], rest: string}
|
||||||
|
* ISO codes found, the forms as typed, and the phrase without them.
|
||||||
|
*/
|
||||||
|
public static function detect(string $phrase): array {
|
||||||
|
[$exact, $plain] = self::maps();
|
||||||
|
// Words and what separates them, so that the rest keeps its punctuation.
|
||||||
|
$tokens = preg_split('/([\s\-\'’,;:\/()]+)/u', $phrase, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||||
|
$words = [];
|
||||||
|
foreach ($tokens as $i => $token) {
|
||||||
|
if (!preg_match('/^[\s\-\'’,;:\/()]+$/u', $token)) {
|
||||||
|
$words[] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$codes = [];
|
||||||
|
$forms = [];
|
||||||
|
$removed = [];
|
||||||
|
$count = count($words);
|
||||||
|
for ($w = 0; $w < $count;) {
|
||||||
|
$found = FALSE;
|
||||||
|
for ($n = min(self::MAX_WORDS, $count - $w); $n >= 1; $n--) {
|
||||||
|
$slice = array_slice($words, $w, $n);
|
||||||
|
$typed = implode(' ', array_map(static fn (int $i): string => $tokens[$i], $slice));
|
||||||
|
$key = self::fold($typed);
|
||||||
|
$match = self::plain($key) === $key ? ($plain[$key] ?? NULL) : ($exact[$key] ?? NULL);
|
||||||
|
if ($match) {
|
||||||
|
array_push($codes, ...$match);
|
||||||
|
$forms[] = $typed;
|
||||||
|
for ($i = $slice[0]; $i <= end($slice); $i++) {
|
||||||
|
$removed[$i] = TRUE;
|
||||||
|
}
|
||||||
|
$w += $n;
|
||||||
|
$found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) {
|
||||||
|
$w++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$rest = '';
|
||||||
|
foreach ($tokens as $i => $token) {
|
||||||
|
$rest .= isset($removed[$i]) ? ' ' : $token;
|
||||||
|
}
|
||||||
|
$rest = preg_replace(['/\s+/u', '/\s+([,;:])/u'], [' ', '$1'], $rest) ?? $rest;
|
||||||
|
return [
|
||||||
|
'codes' => array_values(array_unique($codes)),
|
||||||
|
'forms' => $forms,
|
||||||
|
'rest' => trim($rest, " ,;:/-"),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forms of the given countries, as stored (lowercase, accents kept).
|
||||||
|
*
|
||||||
|
* @param string[] $codes
|
||||||
|
* ISO codes.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
* Forms, for the tags of the same name.
|
||||||
|
*/
|
||||||
|
public static function forms(array $codes): array {
|
||||||
|
$forms = [];
|
||||||
|
foreach ($codes as $code) {
|
||||||
|
array_push($forms, ...(CountryForms::FORMS[$code] ?? []));
|
||||||
|
}
|
||||||
|
return array_values(array_unique($forms));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lowercase, hyphens and apostrophes as spaces, spaces collapsed.
|
||||||
|
*/
|
||||||
|
public static function fold(string $text): string {
|
||||||
|
$text = preg_replace('/[\-\'’]+/u', ' ', mb_strtolower($text)) ?? $text;
|
||||||
|
return trim(preg_replace('/\s+/u', ' ', $text) ?? $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accents removed.
|
||||||
|
*/
|
||||||
|
public static function plain(string $text): string {
|
||||||
|
static $transliteration;
|
||||||
|
$transliteration ??= new PhpTransliteration();
|
||||||
|
return $transliteration->removeDiacritics($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the lookup maps once.
|
||||||
|
*
|
||||||
|
* @return array{0: array<string, string[]>, 1: array<string, string[]>}
|
||||||
|
* Accents kept, accents removed.
|
||||||
|
*/
|
||||||
|
private static function maps(): array {
|
||||||
|
if (self::$maps === NULL) {
|
||||||
|
$exact = $plain = [];
|
||||||
|
foreach (CountryForms::FORMS as $code => $forms) {
|
||||||
|
foreach ($forms as $form) {
|
||||||
|
$exact[$form][] = $code;
|
||||||
|
$plain[self::plain($form)][] = $code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self::$maps = [
|
||||||
|
array_map('array_unique', $exact),
|
||||||
|
array_map('array_unique', $plain),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return self::$maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\materio_sapi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Names and demonyms of the countries, French and English (Q6).
|
||||||
|
*
|
||||||
|
* Generated by q6-generer-pays.py (recherche-ia project folder) from the
|
||||||
|
* country list of Drupal and the demonyms of Wikidata (P1549), reviewed on
|
||||||
|
* 30/11/2026. Do not edit by hand: change the script and generate again.
|
||||||
|
* Lowercase, hyphens and apostrophes as spaces, accents kept. Left out
|
||||||
|
* because they also name a material or a process: guernsey, jersey, panama, polish, suede, suède.
|
||||||
|
*/
|
||||||
|
final class CountryForms {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forms keyed by ISO 3166-1 alpha-2 code.
|
||||||
|
*/
|
||||||
|
public const FORMS = [
|
||||||
|
'AC' => ['ascension island', 'île de l ascension'],
|
||||||
|
'AD' => ['andorra', 'andorran', 'andorrane', 'andorranes', 'andorrans', 'andorre'],
|
||||||
|
'AE' => ['emirati', 'emirats arabes unis', 'emiri', 'emirian', 'emirians', 'uae', 'united arab emirates', 'émirats arabes unis', 'émirien', 'émirienne', 'émiriennes', 'émiriens'],
|
||||||
|
'AF' => ['afghan', 'afghane', 'afghanes', 'afghanistan', 'afghans'],
|
||||||
|
'AG' => ['antigua & barbuda', 'antigua and barbuda', 'antiguan', 'antiguans', 'antiguayen', 'antiguayene', 'antiguayenes', 'antiguayenne', 'antiguayennes', 'antiguayens', 'barbudan', 'barbudans'],
|
||||||
|
'AI' => ['anguilla', 'anguillan', 'anguillans'],
|
||||||
|
'AL' => ['albanais', 'albanaise', 'albanaises', 'albania', 'albanian', 'albanians', 'albanie'],
|
||||||
|
'AM' => ['armenia', 'armenian', 'armenians', 'arménie', 'arménien', 'arménienne', 'arméniennes', 'arméniens'],
|
||||||
|
'AN' => ['antilles néerlandaises', 'dutch antillean', 'dutch antilleans', 'netherlands antilles'],
|
||||||
|
'AO' => ['angola', 'angolais', 'angolaise', 'angolaises', 'angolan', 'angolans'],
|
||||||
|
'AQ' => ['antarctica', 'antarcticain', 'antarcticaine', 'antarcticaines', 'antarcticains', 'antarctican', 'antarcticans', 'antarctique'],
|
||||||
|
'AR' => ['argentin', 'argentina', 'argentine', 'argentines', 'argentinian', 'argentinians', 'argentins'],
|
||||||
|
'AS' => ['american samoa', 'american samoan', 'american samoans', 'samoa américaines'],
|
||||||
|
'AT' => ['austria', 'austrian', 'austrians', 'autriche', 'autrichien', 'autrichienne', 'autrichiennes', 'autrichiens'],
|
||||||
|
'AU' => ['aussie', 'aussies', 'australia', 'australian', 'australians', 'australie', 'australien', 'australienne', 'australiennes', 'australiens'],
|
||||||
|
'AW' => ['aruba', 'aruban', 'arubans'],
|
||||||
|
'AX' => ['åland islands', 'ålandic', 'îles aland'],
|
||||||
|
'AZ' => ['azerbaijan', 'azerbaijani', 'azerbaijanis', 'azerbaïdjan', 'azerbaïdjanais', 'azerbaïdjanaise', 'azerbaïdjanaises', 'azeri', 'azeris'],
|
||||||
|
'BA' => ['bosnia & herzegovina', 'bosnian', 'bosnians', 'bosnie herzégovine', 'bosnien', 'bosnienne', 'bosniennes', 'bosniens', 'herzegovinian', 'herzegovinians'],
|
||||||
|
'BB' => ['barbade', 'barbadian', 'barbadians', 'barbadien', 'barbadienne', 'barbadiennes', 'barbadiens', 'barbados'],
|
||||||
|
'BD' => ['bangladais', 'bangladaise', 'bangladaises', 'bangladesh', 'bangladeshi'],
|
||||||
|
'BE' => ['belge', 'belges', 'belgian', 'belgians', 'belgique', 'belgium'],
|
||||||
|
'BF' => ['burkina faso', 'burkinabe', 'burkinabè', 'burkinabèe', 'burkinabèes', 'burkinabès', 'burkinabé'],
|
||||||
|
'BG' => ['bulgare', 'bulgares', 'bulgaria', 'bulgarian', 'bulgarians', 'bulgarie'],
|
||||||
|
'BH' => ['bahrain', 'bahraini', 'bahreïn', 'bahreïnien', 'bahreïnienne', 'bahreïniennes', 'bahreïniens'],
|
||||||
|
'BI' => ['burundais', 'burundaise', 'burundaises', 'burundi', 'burundian', 'burundians'],
|
||||||
|
'BJ' => ['benin', 'beninese', 'bénin', 'béninien', 'béninienne', 'béniniennes', 'béniniens', 'béninois', 'béninoise', 'béninoises'],
|
||||||
|
'BL' => ['barthéloméen', 'barthéloméenne', 'barthéloméennes', 'barthéloméens', 'st. barthélemy'],
|
||||||
|
'BM' => ['bermuda', 'bermudan', 'bermudans', 'bermudes', 'bermudian', 'bermudians', 'bermudien', 'bermudienne', 'bermudiennes', 'bermudiens'],
|
||||||
|
'BN' => ['brunei', 'brunéien', 'brunéienne', 'brunéiennes', 'brunéiens'],
|
||||||
|
'BO' => ['bolivia', 'bolivian', 'bolivians', 'bolivie', 'bolivien', 'bolivienne', 'boliviennes', 'boliviens'],
|
||||||
|
'BQ' => ['caribbean netherlands', 'pays bas caribéens'],
|
||||||
|
'BR' => ['brazil', 'brazilian', 'brazilians', 'brésil', 'brésilien', 'brésilienne', 'brésiliennes', 'brésiliens'],
|
||||||
|
'BS' => ['bahamas', 'bahamian', 'bahamians', 'bahaméen', 'bahaméenne', 'bahaméennes', 'bahaméens'],
|
||||||
|
'BT' => ['bhoutan', 'bhoutanais', 'bhoutanaise', 'bhoutanaises', 'bhutan', 'bhutanese'],
|
||||||
|
'BV' => ['bouvet island', 'île bouvet'],
|
||||||
|
'BW' => ['batswana', 'botswana', 'botswanais', 'botswanaise', 'botswanaises', 'botswanan', 'botswanans', 'motswana'],
|
||||||
|
'BY' => ['belarus', 'belarusian', 'belarusians', 'biélorusse', 'biélorusses', 'biélorussie'],
|
||||||
|
'BZ' => ['belize', 'belizean', 'belizeans', 'bélizien', 'bélizienne', 'béliziennes', 'béliziens'],
|
||||||
|
'CA' => ['canada', 'canadian', 'canadians', 'canadien', 'canadienne', 'canadiennes', 'canadiens'],
|
||||||
|
'CC' => ['cocos (keeling) islands', 'îles cocos (keeling)'],
|
||||||
|
'CD' => ['congo kinshasa', 'congolais', 'congolaise', 'congolaises', 'congolese'],
|
||||||
|
'CF' => ['centrafricain', 'centrafricaine', 'centrafricaines', 'centrafricains', 'central african', 'central african republic', 'central africans', 'république centrafricaine'],
|
||||||
|
'CG' => ['congo brazzaville', 'congolais', 'congolaise', 'congolaises', 'congolese'],
|
||||||
|
'CH' => ['suisse', 'suisses', 'suissesse', 'suissesses', 'swiss', 'switzerland'],
|
||||||
|
'CI' => ['côte d ivoire', 'ivoirian', 'ivoirians', 'ivoirien', 'ivoirienne', 'ivoiriennes', 'ivoiriens', 'ivorian', 'ivorians'],
|
||||||
|
'CK' => ['cook islander', 'cook islands', 'îles cook'],
|
||||||
|
'CL' => ['chile', 'chilean', 'chileans', 'chili', 'chilien', 'chilienne', 'chiliennes', 'chiliens'],
|
||||||
|
'CM' => ['cameroon', 'cameroonian', 'cameroonians', 'cameroun', 'camerounais', 'camerounaise', 'camerounaises'],
|
||||||
|
'CN' => ['china', 'chine', 'chinese', 'chinois', 'chinoise', 'chinoises'],
|
||||||
|
'CO' => ['colombia', 'colombian', 'colombians', 'colombie', 'colombien', 'colombienne', 'colombiennes', 'colombiens'],
|
||||||
|
'CP' => ['clipperton island', 'île de clipperton'],
|
||||||
|
'CQ' => ['sark', 'sercq'],
|
||||||
|
'CR' => ['costa rica', 'costa rican', 'costa ricans', 'costaricien', 'costaricienne', 'costariciennes', 'costariciens'],
|
||||||
|
'CU' => ['cuba', 'cubain', 'cubaine', 'cubaines', 'cubains', 'cuban', 'cubans'],
|
||||||
|
'CV' => ['cabo verdean', 'cabo verdeans', 'cap verdien', 'cap verdienne', 'cap verdiennes', 'cap verdiens', 'cap vert', 'cape verde', 'cape verdean', 'cape verdeans', 'capverdien', 'capverdienne', 'capverdiennes', 'capverdiens'],
|
||||||
|
'CW' => ['curaçao', 'curaçaoan', 'curaçaoans'],
|
||||||
|
'CX' => ['christmas island', 'christmas islander', 'christmas islanders', 'île christmas'],
|
||||||
|
'CY' => ['chypre', 'chypriote', 'chypriotes', 'cypriot', 'cypriote', 'cypriotes', 'cyprus'],
|
||||||
|
'CZ' => ['czech', 'czech republic', 'czechia', 'république tchèque', 'tchèque', 'tchèques', 'tchéquie'],
|
||||||
|
'DE' => ['allemagne', 'allemand', 'allemande', 'allemandes', 'allemands', 'german', 'germans', 'germany'],
|
||||||
|
'DG' => ['diego garcia'],
|
||||||
|
'DJ' => ['djibouti', 'djiboutian', 'djiboutians', 'djiboutien', 'djiboutienne', 'djiboutiennes', 'djiboutiens'],
|
||||||
|
'DK' => ['dane', 'danemark', 'danish', 'danois', 'danoise', 'danoises', 'denmark'],
|
||||||
|
'DM' => ['dominica', 'dominican', 'dominicans', 'dominiquais', 'dominiquaise', 'dominiquaises', 'dominique'],
|
||||||
|
'DO' => ['dominicain', 'dominicaine', 'dominicaines', 'dominicains', 'dominican', 'dominican republic', 'dominicans', 'république dominicaine'],
|
||||||
|
'DZ' => ['algeria', 'algerian', 'algerians', 'algérie', 'algérien', 'algérienne', 'algériennes', 'algériens'],
|
||||||
|
'EA' => ['ceuta & melilla'],
|
||||||
|
'EC' => ['ecuador', 'ecuadoran', 'ecuadorans', 'ecuadorian', 'ecuadorians', 'équateur', 'équatorien', 'équatorienne', 'équatoriennes', 'équatoriens'],
|
||||||
|
'EE' => ['estonia', 'estonian', 'estonians', 'estonie', 'estonien', 'estonienne', 'estoniennes', 'estoniens'],
|
||||||
|
'EG' => ['egypt', 'egyptian', 'egyptians', 'égypte', 'égyptien', 'égyptienne', 'égyptiennes', 'égyptiens'],
|
||||||
|
'EH' => ['sahara occidental', 'western sahara'],
|
||||||
|
'ER' => ['eritrea', 'eritrean', 'eritreans', 'érythrée', 'érythréen', 'érythréenne', 'érythréennes', 'érythréens'],
|
||||||
|
'ES' => ['espagne', 'espagnol', 'espagnole', 'espagnoles', 'espagnols', 'spain', 'spaniard', 'spanish'],
|
||||||
|
'ET' => ['ethiopia', 'ethiopian', 'ethiopians', 'éthiopie', 'éthiopien', 'éthiopienne', 'éthiopiennes', 'éthiopiens', 'éthiopique', 'éthiopiques'],
|
||||||
|
'FI' => ['finland', 'finlandais', 'finlandaise', 'finlandaises', 'finlande', 'finn', 'finnish', 'finns'],
|
||||||
|
'FJ' => ['fidji', 'fidjien', 'fidjienne', 'fidjiennes', 'fidjiens', 'fiji', 'fijian', 'fijians'],
|
||||||
|
'FK' => ['falkland islands', 'îles malouines'],
|
||||||
|
'FM' => ['micronesia', 'micronesian', 'micronesians', 'micronésie', 'micronésien', 'micronésienne', 'micronésiennes', 'micronésiens'],
|
||||||
|
'FO' => ['faroe islander', 'faroe islands', 'faroese', 'féroïen', 'féroïene', 'féroïenes', 'féroïens', 'îles féroé'],
|
||||||
|
'FR' => ['france', 'français', 'française', 'françaises', 'french'],
|
||||||
|
'GA' => ['gabon', 'gabonais', 'gabonaise', 'gabonaises', 'gabonese'],
|
||||||
|
'GB' => ['anglais', 'anglaise', 'anglaises', 'angleterre', 'britain', 'britannique', 'britanniques', 'british', 'briton', 'britons', 'england', 'grande bretagne', 'great britain', 'pays de galles', 'royaume uni', 'scotland', 'uk', 'united kingdom', 'wales', 'écosse'],
|
||||||
|
'GD' => ['grenada', 'grenade', 'grenadian', 'grenadians', 'grenadien', 'grenadienne', 'grenadiennes', 'grenadiens'],
|
||||||
|
'GE' => ['georgia', 'georgian', 'georgians', 'géorgie', 'géorgien', 'géorgienne', 'géorgiennes', 'géorgiens'],
|
||||||
|
'GF' => ['french guiana', 'french guianese', 'guianese', 'guyanais', 'guyanaise', 'guyanaises', 'guyane française'],
|
||||||
|
'GG' => ['guernesey'],
|
||||||
|
'GH' => ['ghana', 'ghanaian', 'ghanaians', 'ghanéen', 'ghanéenne', 'ghanéennes', 'ghanéens'],
|
||||||
|
'GI' => ['gibraltar', 'gibraltarian', 'gibraltarians', 'gibraltarien', 'gibraltarienne', 'gibraltariennes', 'gibraltariens'],
|
||||||
|
'GL' => ['greenland', 'greenlandic', 'groenland', 'groenlandais', 'groenlandaise', 'groenlandaises'],
|
||||||
|
'GM' => ['gambia', 'gambian', 'gambians', 'gambie', 'gambien', 'gambienne', 'gambiennes', 'gambiens'],
|
||||||
|
'GN' => ['guinea', 'guinean', 'guineans', 'guinée', 'guinéen', 'guinéenne', 'guinéennes', 'guinéens'],
|
||||||
|
'GP' => ['guadeloupe', 'guadeloupean', 'guadeloupeans'],
|
||||||
|
'GQ' => ['equatoguinean', 'equatoguineans', 'equatorial guinea', 'equatorial guinean', 'equatorial guineans', 'guinée équatoriale', 'équatoguinéen', 'équatoguinéenne', 'équatoguinéennes', 'équatoguinéens'],
|
||||||
|
'GR' => ['grec', 'grecque', 'grecques', 'grecs', 'greece', 'greek', 'grèce'],
|
||||||
|
'GS' => ['géorgie du sud et les îles sandwich du sud', 'south georgia & south sandwich islands', 'south georgian', 'south georgians', 'south sandwich islander'],
|
||||||
|
'GT' => ['guatemala', 'guatemalan', 'guatemalans', 'guatémalien', 'guatémalienne', 'guatémaliennes', 'guatémaliens', 'guatémaltèque', 'guatémaltèques'],
|
||||||
|
'GU' => ['guam', 'guamanian', 'guamanians', 'guamanien', 'guamanienne', 'guamaniennes', 'guamaniens'],
|
||||||
|
'GW' => ['bissaoguinéen', 'bissaoguinéenne', 'bissaoguinéennes', 'bissaoguinéens', 'bissau guinean', 'bissau guineans', 'guinea bissau', 'guinea bissauan', 'guinea bissauans', 'guinée bissau', 'guinéen', 'guinéenne', 'guinéennes', 'guinéens'],
|
||||||
|
'GY' => ['guyana', 'guyanese', 'guyanien', 'guyanienne', 'guyaniennes', 'guyaniens'],
|
||||||
|
'HK' => ['hong kong', 'hong kong people', 'hong kong sar china', 'hongkongais', 'hongkongaise', 'hongkongaises', 'hongkonger'],
|
||||||
|
'HM' => ['heard & mcdonald islands', 'heard and mcdonald islander', 'îles heard et macdonald'],
|
||||||
|
'HN' => ['honduran', 'hondurans', 'honduras', 'hondurien', 'hondurienne', 'honduriennes', 'honduriens'],
|
||||||
|
'HR' => ['croate', 'croates', 'croatia', 'croatian', 'croatians', 'croatie'],
|
||||||
|
'HT' => ['haiti', 'haitian', 'haitians', 'haïti', 'haïtien', 'haïtienne', 'haïtiennes', 'haïtiens'],
|
||||||
|
'HU' => ['hongrie', 'hongrois', 'hongroise', 'hongroises', 'hungarian', 'hungarians', 'hungary'],
|
||||||
|
'IC' => ['canary islands', 'îles canaries'],
|
||||||
|
'ID' => ['indonesia', 'indonesian', 'indonesians', 'indonésie', 'indonésien', 'indonésienne', 'indonésiennes', 'indonésiens'],
|
||||||
|
'IE' => ['ireland', 'irish', 'irlandais', 'irlandaise', 'irlandaises', 'irlande'],
|
||||||
|
'IL' => ['israel', 'israeli', 'israelis', 'israélien', 'israélienne', 'israéliennes', 'israéliens', 'israël'],
|
||||||
|
'IM' => ['isle of man', 'manx', 'île de man'],
|
||||||
|
'IN' => ['inde', 'india', 'indian', 'indians', 'indien', 'indienne', 'indiennes', 'indiens'],
|
||||||
|
'IO' => ['british', 'british indian ocean territory', 'territoire britannique de l océan indien'],
|
||||||
|
'IQ' => ['irak', 'irakien', 'irakienne', 'irakiennes', 'irakiens', 'iraq', 'iraqi'],
|
||||||
|
'IR' => ['iran', 'iranian', 'iranians', 'iranien', 'iranienne', 'iraniennes', 'iraniens', 'persian', 'persians'],
|
||||||
|
'IS' => ['iceland', 'icelander', 'icelandic', 'islandais', 'islandaise', 'islandaises', 'islande'],
|
||||||
|
'IT' => ['italian', 'italians', 'italie', 'italien', 'italienne', 'italiennes', 'italiens', 'italy'],
|
||||||
|
'JE' => ['islander', 'jersey bean', 'jersey beans', 'jersey crapaud', 'jersey crapaude', 'jersey crapaudes', 'jersey crapauds', 'jerseyman', 'jerseymans', 'jerseywoman', 'jerseywomans', 'jèrriais(e)', 'jèrriais(e)e', 'jèrriais(e)es', 'jèrriais(e)s'],
|
||||||
|
'JM' => ['jamaica', 'jamaican', 'jamaicans', 'jamaïcain', 'jamaïcaine', 'jamaïcaines', 'jamaïcains', 'jamaïquain', 'jamaïquaine', 'jamaïquaines', 'jamaïquains', 'jamaïque'],
|
||||||
|
'JO' => ['jordan', 'jordanian', 'jordanians', 'jordanie', 'jordanien', 'jordanienne', 'jordaniennes', 'jordaniens'],
|
||||||
|
'JP' => ['japan', 'japanese', 'japon', 'japonais', 'japonaise', 'japonaises'],
|
||||||
|
'KE' => ['kenya', 'kenyan', 'kenyans', 'kényan', 'kényane', 'kényanes', 'kényans'],
|
||||||
|
'KG' => ['kirghiz', 'kirghize', 'kirghizes', 'kirghizistan', 'kirghizs', 'kyrgyz', 'kyrgyzstan', 'kyrgyzstani'],
|
||||||
|
'KH' => ['cambodge', 'cambodgien', 'cambodgienne', 'cambodgiennes', 'cambodgiens', 'cambodia', 'cambodian', 'cambodians'],
|
||||||
|
'KI' => ['gilbertin', 'gilbertine', 'gilbertines', 'gilbertins', 'i kiribati', 'kiribati'],
|
||||||
|
'KM' => ['comoran', 'comorans', 'comores', 'comorian', 'comorians', 'comorien', 'comorienne', 'comoriennes', 'comoriens', 'comoros'],
|
||||||
|
'KN' => ['christophien', 'christophienne', 'christophiennes', 'christophiens', 'kittitian', 'kittitians', 'nevisian', 'nevisians', 'saint christophe et niévès', 'st. kitts & nevis'],
|
||||||
|
'KP' => ['corée du nord', 'nord coréen', 'nord coréenne', 'nord coréennes', 'nord coréens', 'north korea', 'north korean', 'north koreans'],
|
||||||
|
'KR' => ['corée', 'corée du sud', 'coréen', 'coréenne', 'coréennes', 'coréens', 'korea', 'korean', 'koreans', 'south korea', 'south korean', 'south koreans', 'sud coréen', 'sud coréenne', 'sud coréennes', 'sud coréens'],
|
||||||
|
'KW' => ['koweït', 'koweïtien', 'koweïtienne', 'koweïtiennes', 'koweïtiens', 'kuwait', 'kuwaiti'],
|
||||||
|
'KY' => ['cayman islands', 'caymanian', 'caymanians', 'îles caïmans'],
|
||||||
|
'KZ' => ['kazakh', 'kazakhstan', 'kazakhstanais', 'kazakhstanaise', 'kazakhstanaises', 'kazakhstani'],
|
||||||
|
'LA' => ['lao', 'laos', 'laotian', 'laotians', 'laotien', 'laotienne', 'laotiennes', 'laotiens'],
|
||||||
|
'LB' => ['lebanese', 'lebanon', 'liban', 'libanais', 'libanaise', 'libanaises'],
|
||||||
|
'LC' => ['lucien', 'lucienne', 'luciennes', 'luciens', 'saint lucian', 'saint lucians', 'sainte lucie', 'st. lucia'],
|
||||||
|
'LI' => ['liechtenstein', 'liechtensteiner', 'liechtensteinois', 'liechtensteinoise', 'liechtensteinoises'],
|
||||||
|
'LK' => ['sri lanka', 'sri lankan', 'sri lankans', 'srilankais', 'srilankaise', 'srilankaises'],
|
||||||
|
'LR' => ['liberia', 'liberian', 'liberians', 'libéria', 'libérien', 'libérienne', 'libériennes', 'libériens'],
|
||||||
|
'LS' => ['basotho', 'lesothien', 'lesothienne', 'lesothiennes', 'lesothiens', 'lesotho', 'lésothan', 'lésothane', 'lésothanes', 'lésothans', 'mosotho'],
|
||||||
|
'LT' => ['lithuania', 'lithuanian', 'lithuanians', 'lituanie', 'lituanien', 'lituanienne', 'lituaniennes', 'lituaniens'],
|
||||||
|
'LU' => ['luxembourg', 'luxembourgeois', 'luxembourgeoise', 'luxembourgeoises', 'luxembourgian', 'luxembourgians', 'luxembourgish'],
|
||||||
|
'LV' => ['latvia', 'latvian', 'latvians', 'letton', 'lettonie', 'lettonne', 'lettonnes', 'lettons'],
|
||||||
|
'LY' => ['libya', 'libyan', 'libyans', 'libyen', 'libyene', 'libyenes', 'libyenne', 'libyennes', 'libyens', 'lybie'],
|
||||||
|
'MA' => ['maroc', 'marocain', 'marocaine', 'marocaines', 'marocains', 'moroccan', 'moroccans', 'morocco'],
|
||||||
|
'MC' => ['monacan', 'monacans', 'monaco', 'monegasque', 'monégasque', 'monégasques'],
|
||||||
|
'MD' => ['moldave', 'moldaves', 'moldavian', 'moldavians', 'moldavie', 'moldova', 'moldovan', 'moldovans'],
|
||||||
|
'ME' => ['montenegrin', 'montenegrins', 'montenegro', 'monténégrin', 'monténégrine', 'monténégrines', 'monténégrins', 'monténégro'],
|
||||||
|
'MF' => ['saint martinois', 'saint martinoise', 'saint martinoises', 'st. martin'],
|
||||||
|
'MG' => ['madagascar', 'malagasy', 'malgache', 'malgaches'],
|
||||||
|
'MH' => ['marshall islands', 'marshallais', 'marshallaise', 'marshallaises', 'marshallese', 'îles marshall'],
|
||||||
|
'MK' => ['macedonian', 'macedonians', 'macédoine du nord', 'macédonien', 'macédonienne', 'macédoniennes', 'macédoniens', 'north macedonia'],
|
||||||
|
'ML' => ['mali', 'malian', 'malians', 'malien', 'malienne', 'maliennes', 'maliens'],
|
||||||
|
'MM' => ['birman', 'birmane', 'birmanes', 'birmans', 'burmese', 'myanma', 'myanmar (birmanie)', 'myanmar (burma)'],
|
||||||
|
'MN' => ['mongol', 'mongole', 'mongoles', 'mongolia', 'mongolian', 'mongolians', 'mongolie', 'mongols'],
|
||||||
|
'MO' => ['macanese', 'macao sar china', 'région administrative spéciale de macao de la république populaire de chine'],
|
||||||
|
'MP' => ['chamorro', 'chamorros', 'northern mariana islander', 'northern mariana islanders', 'northern mariana islands', 'northern marianan', 'northern marianans', 'îles mariannes du nord'],
|
||||||
|
'MQ' => ['martinique'],
|
||||||
|
'MR' => ['mauritania', 'mauritanian', 'mauritanians', 'mauritanie', 'mauritanien', 'mauritanienne', 'mauritaniennes', 'mauritaniens'],
|
||||||
|
'MS' => ['montserrat', 'montserratian', 'montserratians'],
|
||||||
|
'MT' => ['malta', 'maltais', 'maltaise', 'maltaises', 'malte', 'maltese'],
|
||||||
|
'MU' => ['maurice', 'mauricien', 'mauricienne', 'mauriciennes', 'mauriciens', 'mauritian', 'mauritians', 'mauritius'],
|
||||||
|
'MV' => ['maldives', 'maldivian', 'maldivians', 'maldivien', 'maldivienne', 'maldiviennes', 'maldiviens'],
|
||||||
|
'MW' => ['malawi', 'malawian', 'malawians', 'malawite', 'malawites'],
|
||||||
|
'MX' => ['mexicain', 'mexicaine', 'mexicaines', 'mexicains', 'mexican', 'mexicans', 'mexico', 'mexique'],
|
||||||
|
'MY' => ['malais', 'malaise', 'malaises', 'malaisie', 'malaisien', 'malaisienne', 'malaisiennes', 'malaisiens', 'malaysia', 'malaysian', 'malaysians'],
|
||||||
|
'MZ' => ['mozambicain', 'mozambicaine', 'mozambicaines', 'mozambicains', 'mozambican', 'mozambicans', 'mozambique'],
|
||||||
|
'NA' => ['namibia', 'namibian', 'namibians', 'namibie', 'namibien', 'namibienne', 'namibiennes', 'namibiens'],
|
||||||
|
'NC' => ['calédonien', 'calédonienne', 'calédoniennes', 'calédoniens', 'new caledonia', 'new caledonian', 'new caledonians', 'nouvelle calédonie', 'néo calédonien', 'néo calédonienne', 'néo calédoniennes', 'néo calédoniens', 'néocalédonien', 'néocalédonienne', 'néocalédoniennes', 'néocalédoniens'],
|
||||||
|
'NE' => ['niger', 'nigerien', 'nigeriens', 'nigérien', 'nigérienne', 'nigériennes', 'nigériens'],
|
||||||
|
'NF' => ['norfolk island', 'norfolk islander', 'norfolk islanders', 'île norfolk'],
|
||||||
|
'NG' => ['nigeria', 'nigerian', 'nigerians', 'nigérian', 'nigériane', 'nigérianes', 'nigérians'],
|
||||||
|
'NI' => ['nicaragua', 'nicaraguan', 'nicaraguans', 'nicaraguayen', 'nicaraguayene', 'nicaraguayenes', 'nicaraguayenne', 'nicaraguayennes', 'nicaraguayens'],
|
||||||
|
'NL' => ['dutch', 'holland', 'hollandais', 'hollandaise', 'hollandaises', 'hollande', 'netherlands', 'néerlandais', 'néerlandaise', 'néerlandaises', 'pays bas'],
|
||||||
|
'NO' => ['norvège', 'norvégien', 'norvégienne', 'norvégiennes', 'norvégiens', 'norway', 'norwegian', 'norwegians'],
|
||||||
|
'NP' => ['nepal', 'nepalese', 'nepali', 'népal', 'népalais', 'népalaise', 'népalaises'],
|
||||||
|
'NR' => ['nauru', 'nauruan', 'nauruane', 'nauruanes', 'nauruans'],
|
||||||
|
'NU' => ['niue', 'niuean', 'niueans'],
|
||||||
|
'NZ' => ['new zealand', 'new zealander', 'nouvelle zélande', 'néo zélandais', 'néo zélandaise', 'néo zélandaises', 'néozélandais', 'néozélandaise', 'néozélandaises'],
|
||||||
|
'OM' => ['oman', 'omanais', 'omanaise', 'omanaises', 'omani'],
|
||||||
|
'PA' => ['panamanian', 'panamanians', 'panaméen', 'panaméenne', 'panaméennes', 'panaméens'],
|
||||||
|
'PE' => ['peru', 'peruvian', 'peruvians', 'pérou', 'péruvien', 'péruvienne', 'péruviennes', 'péruviens'],
|
||||||
|
'PF' => ['french polynesia', 'french polynesian', 'french polynesians', 'polynésie française', 'polynésien', 'polynésienne', 'polynésiennes', 'polynésiens'],
|
||||||
|
'PG' => ['néoguinéen', 'néoguinéenne', 'néoguinéennes', 'néoguinéens', 'papouasie nouvelle guinée', 'papouasien', 'papouasienne', 'papouasiennes', 'papouasiens', 'papua new guinea', 'papua new guinean', 'papua new guineans'],
|
||||||
|
'PH' => ['filipina', 'filipino', 'philippin', 'philippine', 'philippines', 'philippins'],
|
||||||
|
'PK' => ['pakistan', 'pakistanais', 'pakistanaise', 'pakistanaises', 'pakistani'],
|
||||||
|
'PL' => ['poland', 'pologne', 'polonais', 'polonaise', 'polonaises'],
|
||||||
|
'PM' => ['miquelonais', 'miquelonaise', 'miquelonaises', 'saint pierrais', 'saint pierraise', 'saint pierraises', 'saint pierre et miquelon', 'st. pierre & miquelon'],
|
||||||
|
'PN' => ['pitcairn islander', 'pitcairn islands', 'îles pitcairn'],
|
||||||
|
'PR' => ['porto rico', 'portoricain', 'portoricaine', 'portoricaines', 'portoricains', 'puerto rican', 'puerto ricans', 'puerto rico'],
|
||||||
|
'PS' => ['palestinian', 'palestinian territories', 'palestinians', 'palestinien', 'palestinienne', 'palestiniennes', 'palestiniens', 'territoires palestiniens'],
|
||||||
|
'PT' => ['portugais', 'portugaise', 'portugaises', 'portugal', 'portuguese'],
|
||||||
|
'PW' => ['palaois', 'palaoise', 'palaoises', 'palaos', 'palau', 'palauan', 'palauans'],
|
||||||
|
'PY' => ['paraguay', 'paraguayan', 'paraguayans', 'paraguayen', 'paraguayene', 'paraguayenes', 'paraguayenne', 'paraguayennes', 'paraguayens'],
|
||||||
|
'QA' => ['qatar', 'qatari', 'qatarien', 'qatarienne', 'qatariennes', 'qatariens'],
|
||||||
|
'QO' => ['océanie éloignée', 'outlying oceania'],
|
||||||
|
'RE' => ['réunion', 'réunionnais', 'réunionnaise', 'réunionnaises'],
|
||||||
|
'RO' => ['romania', 'romanian', 'romanians', 'roumain', 'roumaine', 'roumaines', 'roumains', 'roumanie'],
|
||||||
|
'RS' => ['serbe', 'serbes', 'serbia', 'serbian', 'serbians', 'serbie'],
|
||||||
|
'RU' => ['russe', 'russes', 'russia', 'russian', 'russians', 'russie'],
|
||||||
|
'RW' => ['rwanda', 'rwandais', 'rwandaise', 'rwandaises', 'rwandan', 'rwandans', 'rwandese'],
|
||||||
|
'SA' => ['arabie saoudite', 'saoudien', 'saoudienne', 'saoudiennes', 'saoudiens', 'saudi', 'saudi arabia', 'saudi arabian', 'saudi arabians'],
|
||||||
|
'SB' => ['salomonais', 'salomonaise', 'salomonaises', 'salomonien', 'salomonienne', 'salomoniennes', 'salomoniens', 'solomon islander', 'solomon islands', 'îles salomon'],
|
||||||
|
'SC' => ['seychelles', 'seychellois', 'seychelloise', 'seychelloises'],
|
||||||
|
'SD' => ['soudan', 'soudanais', 'soudanaise', 'soudanaises', 'sudan', 'sudanese'],
|
||||||
|
'SE' => ['suédois', 'suédoise', 'suédoises', 'sweden', 'swedish'],
|
||||||
|
'SG' => ['singapore', 'singaporean', 'singaporeans', 'singapour', 'singapourien', 'singapourienne', 'singapouriennes', 'singapouriens'],
|
||||||
|
'SH' => ['sainte hélène', 'st. helena'],
|
||||||
|
'SI' => ['slovene', 'slovenia', 'slovenian', 'slovenians', 'slovène', 'slovènes', 'slovénie'],
|
||||||
|
'SJ' => ['svalbard & jan mayen', 'svalbard et jan mayen'],
|
||||||
|
'SK' => ['slovak', 'slovakia', 'slovaque', 'slovaques', 'slovaquie'],
|
||||||
|
'SL' => ['sierra leone', 'sierra leonean', 'sierra leoneans', 'sierraléonais', 'sierraléonaise', 'sierraléonaises'],
|
||||||
|
'SM' => ['saint marin', 'saint marinais', 'saint marinaise', 'saint marinaises', 'sammarinese', 'san marino'],
|
||||||
|
'SN' => ['senegal', 'senegalese', 'sénégal', 'sénégalais', 'sénégalaise', 'sénégalaises', 'sénégalien', 'sénégalienne', 'sénégaliennes', 'sénégaliens'],
|
||||||
|
'SO' => ['somali', 'somalia', 'somalian', 'somalians', 'somalie', 'somalien', 'somalienne', 'somaliennes', 'somaliens'],
|
||||||
|
'SR' => ['suriname', 'surinamese', 'surinamien', 'surinamienne', 'surinamiennes', 'surinamiens'],
|
||||||
|
'SS' => ['soudan du sud', 'south sudan', 'south sudanese', 'sud soudanais', 'sud soudanaise', 'sud soudanaises', 'sudsoudanais', 'sudsoudanaise', 'sudsoudanaises'],
|
||||||
|
'ST' => ['santomean', 'santomeans', 'santoméen', 'santoméenne', 'santoméennes', 'santoméens', 'sao tomean', 'sao tomeans', 'sao tomé et principe', 'são tomé & príncipe', 'são toméan', 'são toméans'],
|
||||||
|
'SV' => ['el salvador', 'salvador', 'salvadoran', 'salvadorans', 'salvadorien', 'salvadorienne', 'salvadoriennes', 'salvadoriens'],
|
||||||
|
'SX' => ['sint maarten', 'st. maartener'],
|
||||||
|
'SY' => ['syria', 'syrian', 'syrians', 'syrie', 'syrien', 'syrienne', 'syriennes', 'syriens'],
|
||||||
|
'SZ' => ['emaswati', 'eswatini', 'eswatinien', 'eswatinienne', 'eswatiniennes', 'eswatiniens', 'liswati', 'swazi', 'swazis'],
|
||||||
|
'TA' => ['tristan da cunha'],
|
||||||
|
'TC' => ['turks & caicos islands', 'turks and caicos islander', 'îles turques et caïques'],
|
||||||
|
'TD' => ['chad', 'chadian', 'chadians', 'tchad', 'tchadien', 'tchadienne', 'tchadiennes', 'tchadiens'],
|
||||||
|
'TF' => ['french', 'french southern territories', 'terres australes françaises'],
|
||||||
|
'TG' => ['togo', 'togolais', 'togolaise', 'togolaises', 'togolese'],
|
||||||
|
'TH' => ['thai', 'thailand', 'thaïlandais', 'thaïlandaise', 'thaïlandaises', 'thaïlande'],
|
||||||
|
'TJ' => ['tadjik', 'tadjike', 'tadjikes', 'tadjikistan', 'tadjiks', 'tajikistan', 'tajikistani'],
|
||||||
|
'TK' => ['tokelau', 'tokelauan', 'tokelauans'],
|
||||||
|
'TL' => ['east timorese', 'timor leste', 'timor oriental', 'timorais', 'timoraise', 'timoraises'],
|
||||||
|
'TM' => ['turkmen', 'turkmenistan', 'turkmenistani', 'turkmens', 'turkmène', 'turkmènes', 'turkménistan'],
|
||||||
|
'TN' => ['tunisia', 'tunisian', 'tunisians', 'tunisie', 'tunisien', 'tunisienne', 'tunisiennes', 'tunisiens'],
|
||||||
|
'TO' => ['tonga', 'tongan', 'tongans', 'tongien', 'tongienne', 'tongiennes', 'tongiens'],
|
||||||
|
'TR' => ['turc', 'turcs', 'turkey', 'turkish', 'turque', 'turques', 'turquie', 'türkiye'],
|
||||||
|
'TT' => ['trinibagonien', 'trinibagonienne', 'trinibagoniennes', 'trinibagoniens', 'trinidad & tobago', 'trinidadian', 'trinidadians', 'trinidadien', 'trinidadienne', 'trinidadiennes', 'trinidadiens', 'trinité et tobago'],
|
||||||
|
'TV' => ['tuvalais', 'tuvalaise', 'tuvalaises', 'tuvalu', 'tuvaluan', 'tuvaluans'],
|
||||||
|
'TW' => ['taiwan', 'taiwanese', 'taiwans', 'taïwan', 'taïwanais', 'taïwanaise', 'taïwanaises'],
|
||||||
|
'TZ' => ['tanzania', 'tanzanian', 'tanzanians', 'tanzanie', 'tanzanien', 'tanzanienne', 'tanzaniennes', 'tanzaniens'],
|
||||||
|
'UA' => ['ukraine', 'ukrainian', 'ukrainians', 'ukrainien', 'ukrainienne', 'ukrainiennes', 'ukrainiens'],
|
||||||
|
'UG' => ['ouganda', 'ougandais', 'ougandaise', 'ougandaises', 'uganda', 'ugandan', 'ugandans'],
|
||||||
|
'UM' => ['u.s. outlying islands', 'îles éloignées des états unis'],
|
||||||
|
'US' => ['american', 'americans', 'américain', 'américaine', 'américaines', 'américains', 'etats unis', 'united states', 'united states of america', 'usa', 'états unien', 'états unienne', 'états uniennes', 'états uniens', 'états unis', 'états unis d amérique'],
|
||||||
|
'UY' => ['uruguay', 'uruguayan', 'uruguayans', 'uruguayen', 'uruguayene', 'uruguayenes', 'uruguayenne', 'uruguayennes', 'uruguayens'],
|
||||||
|
'UZ' => ['ouzbek', 'ouzbeke', 'ouzbekes', 'ouzbeks', 'ouzbekèke', 'ouzbekèkes', 'ouzbékistan', 'uzbek', 'uzbekistan', 'uzbekistani'],
|
||||||
|
'VA' => ['cité du vatican', 'vatican', 'vatican city', 'vaticans'],
|
||||||
|
'VC' => ['saint vincent et les grenadines', 'saint vincentian', 'saint vincentians', 'st. vincent & grenadines', 'vincentais', 'vincentaise', 'vincentaises', 'vincentian', 'vincentians', 'vincy'],
|
||||||
|
'VE' => ['venezuela', 'venezuelan', 'venezuelans', 'vénézuélien', 'vénézuélienne', 'vénézuéliennes', 'vénézuéliens'],
|
||||||
|
'VG' => ['britannique', 'britanniques', 'british virgin islands', 'insulaire des îles vierges britanniques', 'insulaire des îles vierges britanniquese', 'insulaire des îles vierges britanniqueses', 'îles vierges britanniques'],
|
||||||
|
'VI' => ['u.s. virgin islands', 'îles vierges américaines'],
|
||||||
|
'VN' => ['vietnam', 'vietnamese', 'vietnamien', 'vietnamienne', 'vietnamiennes', 'vietnamiens'],
|
||||||
|
'VU' => ['ni vanuatu', 'vanouatais', 'vanouataise', 'vanouataises', 'vanuatu', 'vanuatuan', 'vanuatuans'],
|
||||||
|
'WF' => ['futunan', 'futunans', 'wallis & futuna', 'wallis et futuna', 'wallisian', 'wallisians'],
|
||||||
|
'WS' => ['samoa', 'samoan', 'samoans', 'samoen', 'samoene', 'samoenes', 'samoenne', 'samoennes', 'samoens'],
|
||||||
|
'XK' => ['kosovan', 'kosovans', 'kosovar', 'kosovare', 'kosovares', 'kosovars', 'kosovo', 'kossovien', 'kossovienne', 'kossoviennes', 'kossoviens'],
|
||||||
|
'YE' => ['yemen', 'yemeni', 'yémen', 'yéménite', 'yéménites'],
|
||||||
|
'YT' => ['mahorais', 'mahoraise', 'mahoraises', 'mayotte'],
|
||||||
|
'ZA' => ['afrique du sud', 'south africa', 'south african', 'south africans', 'sud africain', 'sud africaine', 'sud africaines', 'sud africains'],
|
||||||
|
'ZM' => ['zambia', 'zambian', 'zambians', 'zambie', 'zambien', 'zambienne', 'zambiennes', 'zambiens'],
|
||||||
|
'ZW' => ['zimbabwe', 'zimbabwean', 'zimbabweans', 'zimbabwéen', 'zimbabwéenne', 'zimbabwéennes', 'zimbabwéens'],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\materio_sapi\Unit;
|
||||||
|
|
||||||
|
use Drupal\materio_sapi\CountryDetector;
|
||||||
|
use Drupal\Tests\UnitTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use PHPUnit\Framework\Attributes\Group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the countries found in a search phrase (Q6).
|
||||||
|
*/
|
||||||
|
#[CoversClass(CountryDetector::class)]
|
||||||
|
#[Group('materio_sapi')]
|
||||||
|
final class CountryDetectorTest extends UnitTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Phrases, countries found and the rest.
|
||||||
|
*/
|
||||||
|
public static function phrases(): array {
|
||||||
|
return [
|
||||||
|
'country name' => ['pigment Italie', ['IT'], 'pigment'],
|
||||||
|
'demonym alone' => ['italien', ['IT'], ''],
|
||||||
|
'feminine plural' => ['céramiques italiennes', ['IT'], 'céramiques'],
|
||||||
|
'english' => ['Italian marble', ['IT'], 'marble'],
|
||||||
|
'longest form first' => ['verre Corée du Sud', ['KR'], 'verre'],
|
||||||
|
'hyphenated' => ['vase Royaume-Uni', ['GB'], 'vase'],
|
||||||
|
'typed without accents' => ['bois bresil', ['BR'], 'bois'],
|
||||||
|
'accent must match' => ['tissu chiné', [], 'tissu chiné'],
|
||||||
|
'word of a country name' => ['new wood', [], 'new wood'],
|
||||||
|
'material, not a country' => ['cuir suède', [], 'cuir suède'],
|
||||||
|
'alias' => ['Made in USA, acier', ['US'], 'Made in, acier'],
|
||||||
|
'two countries' => ['papier japonais ou chinois', ['JP', 'CN'], 'papier ou'],
|
||||||
|
'none' => ['plastique écologique', [], 'plastique écologique'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Countries are found, longest form first, and taken out of the phrase.
|
||||||
|
*/
|
||||||
|
#[DataProvider('phrases')]
|
||||||
|
public function testDetect(string $phrase, array $codes, string $rest): void {
|
||||||
|
$result = CountryDetector::detect($phrase);
|
||||||
|
$this->assertSame($codes, $result['codes']);
|
||||||
|
$this->assertSame($rest, $result['rest']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user