p59 + p60
This commit is contained in:
@@ -14,6 +14,7 @@ final class NdjsonHybridRetrieverConfig
|
||||
public function __construct(
|
||||
private array $config = [],
|
||||
private ?DomainVocabularyConfig $vocabulary = null,
|
||||
private ?GenreConfig $genreConfig = null,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -146,7 +147,8 @@ final class NdjsonHybridRetrieverConfig
|
||||
/** @return array<string, string[]> */
|
||||
public function exactSelectionTokenVariantPrefixes(): array
|
||||
{
|
||||
return $this->requiredStringListMap('exact_selection_token_variant_prefixes');
|
||||
return $this->genreStringListMap('retrieval_and_language.exact_selection.token_variant_prefixes')
|
||||
?: $this->requiredStringListMap('exact_selection_token_variant_prefixes');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
@@ -158,43 +160,50 @@ final class NdjsonHybridRetrieverConfig
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorQuestionTokens(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_question_tokens');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_question_tokens')
|
||||
?: $this->requiredStringList('exact_selection_indicator_question_tokens');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorQuestionPhrases(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_question_phrases');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_question_phrases')
|
||||
?: $this->requiredStringList('exact_selection_indicator_question_phrases');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorTableHeadingPatterns(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_table_heading_patterns');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_table_heading_patterns')
|
||||
?: $this->requiredStringList('exact_selection_indicator_table_heading_patterns');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorTableHeaderPatterns(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_table_header_patterns');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_table_header_patterns')
|
||||
?: $this->requiredStringList('exact_selection_indicator_table_header_patterns');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorTableRowPatterns(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_table_row_patterns');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_table_row_patterns')
|
||||
?: $this->requiredStringList('exact_selection_indicator_table_row_patterns');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorTableRequiredPrimaryTerms(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_table_required_primary_terms');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_table_required_primary_terms')
|
||||
?: $this->requiredStringList('exact_selection_indicator_table_required_primary_terms');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function exactSelectionIndicatorTableRequiredContextTerms(): array
|
||||
{
|
||||
return $this->requiredStringList('exact_selection_indicator_table_required_context_terms');
|
||||
return $this->genreStringList('retrieval_and_language.exact_selection.indicator_table_required_context_terms')
|
||||
?: $this->requiredStringList('exact_selection_indicator_table_required_context_terms');
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
@@ -370,6 +379,23 @@ final class NdjsonHybridRetrieverConfig
|
||||
];
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function genreStringList(string $path): array
|
||||
{
|
||||
return $this->genreConfig?->getValueStringList($path) ?? [];
|
||||
}
|
||||
|
||||
/** @return array<string, string[]> */
|
||||
private function genreStringListMap(string $path): array
|
||||
{
|
||||
$value = $this->genreConfig?->getValueArray($path) ?? [];
|
||||
if ($value === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->normalizeStringListMap($value);
|
||||
}
|
||||
|
||||
private function requiredInt(string $key, int $min = PHP_INT_MIN, ?int $max = null): int
|
||||
{
|
||||
$value = $this->requiredValue($key);
|
||||
@@ -458,6 +484,35 @@ final class NdjsonHybridRetrieverConfig
|
||||
return $out;
|
||||
}
|
||||
|
||||
/** @return array<string, string[]> */
|
||||
private function normalizeStringListMap(array $value): array
|
||||
{
|
||||
$out = [];
|
||||
foreach ($value as $mapKey => $items) {
|
||||
if (!is_string($mapKey) || trim($mapKey) === '' || !is_array($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cleanItems = [];
|
||||
foreach ($items as $item) {
|
||||
if (!is_scalar($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = trim((string) $item);
|
||||
if ($item !== '' && !in_array($item, $cleanItems, true)) {
|
||||
$cleanItems[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
if ($cleanItems !== []) {
|
||||
$out[trim($mapKey)] = $cleanItems;
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string[]>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user