Use categories

This commit is contained in:
dazedanon 2025-07-15 14:54:51 -05:00
parent e5feee6594
commit 9c36e6d7f7
2 changed files with 52 additions and 21 deletions

View file

@ -2480,33 +2480,63 @@ def batchList(input_list, batch_size):
return [input_list[i : i + batch_size] for i in range(0, len(input_list), batch_size)]
def createContext(fullPromptFlag, subbedT, format):
# Helper to extract (term, line) pairs from VOCAB only once
def parseVocab(vocab_text):
pairs = []
seen = set()
for line in vocab_text.splitlines():
line = line.strip()
if not line or line.startswith('#') or line.startswith('```'):
continue
m = re.match(r'^(.+?)(?:\s?[\(])', line) # term is everything before space + '(' or ''
if m:
term = m.group(1)
if term not in seen:
pairs.append((term, line))
seen.add(term)
return pairs
def parseVocabWithCategories(vocabText):
"""Parse vocabulary text and extract terms with their categories."""
pairs = []
seen = set()
currentCategory = None
for line in vocabText.splitlines():
line = line.strip()
if not line or line.startswith('```'):
continue
# Check if this is a category header
if line.startswith('#'):
currentCategory = line
continue
# Parse vocabulary term
m = re.match(r'^(.+?)(?:\s?[\(])', line) # term is everything before space + '(' or ''
if m:
term = m.group(1)
if term not in seen:
pairs.append((term, line, currentCategory))
seen.add(term)
return pairs
matchedVocabLines = []
vocabPairs = parseVocab(VOCAB)
def buildMatchedVocabText(vocabPairs, subbedT):
"""Build formatted vocabulary text with matched terms organized by category."""
matchedCategories = {}
# Use word boundaries for Japanese if appropriate, or allow substring as before.
for term, line in vocabPairs:
for term, line, category in vocabPairs:
# "term in subbedT" could be false positive; can use regex but Japanese doesn't always have spaces.
if term in subbedT:
matchedVocabLines.append(line)
if category not in matchedCategories:
matchedCategories[category] = []
matchedCategories[category].append(line)
matchedVocabText = f"```\n{'\n'.join(matchedVocabLines)}\n```" if matchedVocabLines else ""
# Format matched vocabulary with categories
if matchedCategories:
formattedLines = ["Here are some vocabulary and terms so that you know the proper spelling and translation.\n"]
for category, lines in matchedCategories.items():
if category: # Only add category header if it exists
formattedLines.append(category)
formattedLines.extend(lines)
formattedLines.append("") # Add blank line between categories
matchedVocabText = f"```\n{chr(10).join(formattedLines).rstrip()}\n```"
else:
matchedVocabText = ""
return matchedVocabText
def createContext(fullPromptFlag, subbedT, format):
vocabPairs = parseVocabWithCategories(VOCAB)
matchedVocabText = buildMatchedVocabText(vocabPairs, subbedT)
if fullPromptFlag:
system = PROMPT + matchedVocabText

View file

@ -1,6 +1,7 @@
Here are some vocabulary and terms so that you know the proper spelling and translation.
```
# Game Characters
イルヴィナ (Illyan) - Female
コヴァ Kova
ビビン Bibin
グリッド Grid