Clean search imperatives before research
This commit is contained in:
@@ -72,19 +72,38 @@ func TaskLexiconFromHistory(history []interaction.HumanUtterance) TaskLexicon {
|
||||
return lexicon
|
||||
}
|
||||
|
||||
// SearchQueryWithLexicon keeps a learned source in the external query without
|
||||
// turning its alias into core vocabulary.
|
||||
// SearchQueryWithLexicon prepares a search-engine query without turning a
|
||||
// learned source alias into core vocabulary. The imperative that expresses the
|
||||
// user's intent is deliberately omitted: search engines must receive the
|
||||
// subject of the request, not mistake a Russian command such as "найди" for a
|
||||
// brand or site name.
|
||||
func SearchQueryWithLexicon(message string, lexicon TaskLexicon) string {
|
||||
decomposition := DecomposeTaskWithLexicon(message, lexicon)
|
||||
if decomposition.Intent == TaskIntentSearch && decomposition.Source != "" {
|
||||
if decomposition.Target != "" {
|
||||
return decomposition.Target + " " + decomposition.Source
|
||||
}
|
||||
return strings.TrimSpace(message) + " " + decomposition.Source
|
||||
return searchQueryWithoutImperative(message) + " " + decomposition.Source
|
||||
}
|
||||
if decomposition.Intent == TaskIntentSearch {
|
||||
return searchQueryWithoutImperative(message)
|
||||
}
|
||||
return strings.TrimSpace(message)
|
||||
}
|
||||
|
||||
func searchQueryWithoutImperative(message string) string {
|
||||
cleaned := strings.TrimSpace(message)
|
||||
fields := strings.Fields(cleaned)
|
||||
if len(fields) < 2 {
|
||||
return cleaned
|
||||
}
|
||||
first := strings.Trim(strings.ToLower(fields[0]), ".,!?:;")
|
||||
if !containsStem(first, "найд", "поищ", "подбер", "проверь") {
|
||||
return cleaned
|
||||
}
|
||||
return strings.TrimSpace(strings.TrimPrefix(cleaned, fields[0]))
|
||||
}
|
||||
|
||||
// DecomposeTaskWithLexicon performs a cheap semantic pass. The lexicon is
|
||||
// intentionally an input: a remembered alias may be revalidated or replaced
|
||||
// without changing the parser or shipping a new hard-coded branch.
|
||||
|
||||
Reference in New Issue
Block a user