Includes earlier uncommitted work: Tomie and Unity adapters, benchmark, structured output, call metrics. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
18 lines
662 B
Python
18 lines
662 B
Python
"""Naninovel managed-text dictionary helpers."""
|
|
|
|
|
|
def parse_dictionary(text):
|
|
result, seen = [], set()
|
|
for line_number, line in enumerate(text.splitlines(), 1):
|
|
if not line.strip() or line.lstrip().startswith((";", "#", "//")):
|
|
continue
|
|
key, separator, value = line.partition(":")
|
|
if not separator or not key.strip() or not value.strip():
|
|
continue
|
|
key = key.strip()
|
|
if key in seen:
|
|
raise ValueError(f"Duplicate dictionary key at line {line_number}: {key}")
|
|
seen.add(key)
|
|
result.append({"id": key, "text": value.lstrip(), "line": line_number})
|
|
return result
|