Skip to content

Commit

Permalink
use simpler xor pattern without negative lookahead for OneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
lapp0 committed May 17, 2024
1 parent 4985d16 commit 3bd28dc
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,7 @@ def to_regex(
to_regex(resolver, t, whitespace_pattern) for t in instance["oneOf"]
]

xor_patterns = []
# json schema validation ensured there is no overlapping schemas in oneOf
for subregex in subregexes:
other_subregexes = filter(lambda r: r != subregex, subregexes)
other_subregexes_str = "|".join([f"{s}" for s in other_subregexes])
negative_lookahead = f"(?!.*({other_subregexes_str}))"
xor_patterns.append(f"({subregex}){negative_lookahead}")
xor_patterns = [f"(?:{subregex})" for subregex in subregexes]

return rf"({'|'.join(xor_patterns)})"

Expand Down

0 comments on commit 3bd28dc

Please sign in to comment.