Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anyOf and oneOf implementation of the JSON Schema spec are incorrect #399

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

BruParis
Copy link

@BruParis BruParis commented Dec 1, 2023

This PR addresses issue #397.

It implements XOR regex using negative lookaheads.

The approach involves testing each oneOf pattern against all others using negative lookaheads. This is done in individual regex groups formatted as: "(pattern)(?!.*(other_pattern0|other_pattern1|...))". This means that 'pattern' is matched only if it is not followed by any of other_pattern0, other_pattern1, etc.

These individual groups are then combined using alternation "(|)".

This ensures exclusive matching, adhering to XOR logic.

The resulting regex has quadratic complexity. I did not find any alternatives, but it seems standard regex syntax does not permit a simpler implementation.

Implements XOR regex using negative lookaheads.
@rlouf
Copy link
Member

rlouf commented Dec 1, 2023

Wonderful, thank you!

@rlouf rlouf merged commit e1c9604 into dottxt-ai:main Dec 1, 2023
5 checks passed
@BruParis BruParis deleted the issue-oneOf branch December 1, 2023 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants