add a bunch of things for hierarchysearch

This commit is contained in:
stuart committed 2026-10-08 14:15:57 +02:00
1 parent 154faf3dd8
commit e4930b791e
2 files changed
+78

No files matched your search

+13
View File
@@ -26,6 +26,19 @@ __all__ = [
"SearchSymbolsRequest",
"GetSymbolsResponse",
"ReplaceFinishedRequest",
"SymbolLeaf",
"SentenceWord",
"WordsPreprocessResponse",
"DictionaryMatch",
"WordLookup",
"LookupRequest",
"LookupResponse",
"JevQuestion",
"JevRequest",
"JevOption",
"JevAnswer",
"JevResponse",
"GetLeafSymbolsRequest",
"UsageStatusResponse",
"ModelType",
"PreprocessorType",
+65
View File
@@ -100,6 +100,71 @@ class ReplaceFinishedRequest(ModifiedBaseModel):
replacement: Symbol
language: str
#### Symbol hierarchy (jev translator) ####
class SymbolLeaf(ModifiedBaseModel):
"""One leaf of the symbol hierarchy. A label with several parts ("bat|club") gives one leaf per part."""
model_config = ConfigDict(frozen=True)
group_id: str
part: int = 0
class SentenceWord(ModifiedBaseModel):
"""A word, or a phrase kept together ("thank you", "Kari Nordmann"), from a wordlist preprocessor."""
text: str
lemmas: List[str] = [] # base forms, most likely first
name: bool = False # a person's name: gets a generic person symbol
gender: Optional[str] = None # "fem" or "mask" for a name, if known
grammar: bool = False # a common grammar word ("the", "og"): skipped if the dictionary has no match
class WordsPreprocessResponse(ModifiedBaseModel):
words: List[SentenceWord]
class DictionaryMatch(ModifiedBaseModel):
leaf: SymbolLeaf
kind: Literal["label", "synonym", "related"]
class WordLookup(ModifiedBaseModel):
matches: List[DictionaryMatch] # labels first
matched: Optional[str] = None # the base form that found the matches, if exactly one did
class LookupRequest(ModifiedBaseModel):
words: List[SentenceWord]
class LookupResponse(ModifiedBaseModel):
words: List[WordLookup] # one per requested word
people: List[SymbolLeaf] # the generic person symbols offered for names
class JevQuestion(ModifiedBaseModel):
"""choose: which of `leaves` matches the word. search: which child of `category_id` (None: the top) does."""
name: str
kind: Literal["choose", "search"]
word: str # the form asked about
is_name: bool = False
gender: Optional[str] = None
leaves: List[SymbolLeaf] = []
category_id: Optional[str] = None
class JevRequest(ModifiedBaseModel):
sentence: str
questions: List[JevQuestion]
class JevOption(ModifiedBaseModel):
"""A symbol or a category the model gave probability p."""
p: float
leaf: Optional[SymbolLeaf] = None
category_id: Optional[str] = None
class JevAnswer(ModifiedBaseModel):
options: List[JevOption] = []
p_none: float = 0.0 # probability that none of the options matches
class JevResponse(ModifiedBaseModel):
answers: Dict[str, JevAnswer] # question name -> answer
class GetLeafSymbolsRequest(ModifiedBaseModel):
leaves: List[SymbolLeaf]
class UsageStatusResponse(ModifiedBaseModel):
"""Read-only snapshot of a caller's rate-limit window."""
limit: int