This commit is contained in:
team 1
2026-05-05 12:12:51 +02:00
parent da374edcf4
commit 2c041a88c0
12 changed files with 429 additions and 282 deletions

View File

@@ -13,6 +13,7 @@ final class NdjsonHybridRetrieverConfig
*/
public function __construct(
private array $config = [],
private ?DomainVocabularyConfig $vocabulary = null,
) {
}
@@ -216,55 +217,82 @@ final class NdjsonHybridRetrieverConfig
/** @return string[] */
public function genericProductTokens(): array
{
return $this->requiredStringList('generic_product_tokens');
return $this->configuredStringListOrVocabularyView(
'generic_product_tokens',
'vocabulary_views.generic_product_tokens'
);
}
/** @return string[] */
public function importantShortModelTokens(): array
{
return $this->requiredStringList('important_short_model_tokens');
return $this->configuredStringListOrVocabularyView(
'important_short_model_tokens',
'vocabulary_views.important_short_model_tokens'
);
}
/** @return string[] */
public function familyDescriptorTokens(): array
{
return $this->requiredStringList('family_descriptor_tokens');
return $this->configuredStringListOrVocabularyView(
'family_descriptor_tokens',
'vocabulary_views.family_descriptor_tokens'
);
}
/** @return string[] */
public function looksLikeReagentTokens(): array
{
return $this->requiredStringList('looks_like_reagent_tokens');
return $this->configuredStringListOrVocabularyView(
'looks_like_reagent_tokens',
'vocabulary_views.looks_like_reagent_tokens'
);
}
/** @return string[] */
public function looksLikeSafetyDocs(): array
{
return $this->requiredStringList('looks_like_safety_docs');
return $this->configuredStringListOrVocabularyView(
'looks_like_safety_docs',
'vocabulary_views.looks_like_safety_docs'
);
}
/** @return string[] */
public function looksLikeReagentWords(): array
{
return $this->requiredStringList('looks_like_reagent_words');
return $this->configuredStringListOrVocabularyView(
'looks_like_reagent_words',
'vocabulary_views.looks_like_reagent_words'
);
}
/** @return string[] */
public function looksLikeDocumentWords(): array
{
return $this->requiredStringList('looks_like_document_words');
return $this->configuredStringListOrVocabularyView(
'looks_like_document_words',
'vocabulary_views.looks_like_document_words'
);
}
/** @return string[] */
public function looksLikeSafetyWords(): array
{
return $this->requiredStringList('looks_like_safety_words');
return $this->configuredStringListOrVocabularyView(
'looks_like_safety_words',
'vocabulary_views.looks_like_safety_words'
);
}
/** @return string[] */
public function looksLikeDeviceWords(): array
{
return $this->requiredStringList('looks_like_device_words');
return $this->configuredStringListOrVocabularyView(
'looks_like_device_words',
'vocabulary_views.looks_like_device_words'
);
}
/**
@@ -471,6 +499,74 @@ final class NdjsonHybridRetrieverConfig
return $out;
}
/** @return string[] */
private function configuredStringListOrVocabularyView(string $configPath, string $viewPathConfigPath): array
{
if ($this->hasKey($configPath)) {
return $this->requiredStringList($configPath);
}
if ($this->vocabulary === null) {
throw $this->missing($configPath);
}
$viewPath = $this->requiredPathString($viewPathConfigPath);
$terms = $this->vocabulary->view($viewPath, []);
if ($terms === []) {
throw $this->invalid($viewPathConfigPath, sprintf('references empty vocabulary view "%s"', $viewPath));
}
return $terms;
}
private function requiredPathString(string $key): string
{
$value = $this->requiredPathValue($key);
if (!is_scalar($value)) {
throw $this->invalid($key, 'must be a non-empty string');
}
$value = trim((string) $value);
if ($value === '') {
throw $this->invalid($key, 'must be a non-empty string');
}
return $value;
}
private function requiredPathValue(string $key): mixed
{
$current = $this->config;
foreach (explode('.', $key) as $segment) {
if (!is_array($current) || !array_key_exists($segment, $current)) {
throw $this->missing($key);
}
$current = $current[$segment];
}
return $current;
}
private function hasKey(string $key): bool
{
$current = $this->config;
foreach (explode('.', $key) as $segment) {
if (!is_array($current) || !array_key_exists($segment, $current)) {
return false;
}
$current = $current[$segment];
}
return true;
}
private function requiredValue(string $key): mixed
{
if (!array_key_exists($key, $this->config)) {