lh22zyta Claude Sonnet 4.6 commited on
Commit
c963bfc
·
1 Parent(s): fbad389

Parser fixes: reject multi-paragraph clean-passthrough, add \b to predicate regex

Browse files

- clean-passthrough fast path now requires single Prolog paragraph (no \n\n) so
multilingual outputs like 'este(T) :- \+ oeste(T).\n\nExplicación: ...' don't
pass trailing prose to swipl
- predicate counting regex pos_pred\( now uses \b word boundary so 'este\('
doesn't over-match 'oeste\(' (Spanish/French/Italian etc where the positive
predicate is a substring of the negative)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. ipt_verifier.py +15 -6
ipt_verifier.py CHANGED
@@ -143,13 +143,19 @@ def extract_hypothesis_with_meta(text: str, enable_line_parsing: bool = True) ->
143
  "structured_parse": False,
144
  }
145
 
146
- # Fast path: input is already clean Prolog (no markup/thinking/markers).
147
- # Avoids letting the line-extractor heuristics misfire on legitimate
148
- # multi-line rule bodies — e.g. lines starting with uppercase variables
149
- # like `CarA \= CarB,` that aren't recognised as continuations.
 
 
 
 
 
150
  stripped = text.strip()
151
  if (
152
  stripped.endswith(".")
 
153
  and "<think>" not in text
154
  and "</think>" not in text
155
  and "```" not in text
@@ -358,8 +364,11 @@ def verify(
358
  if enable_parsing:
359
  hypothesis = extract_hypothesis(hypothesis)
360
 
361
- pos_examples = re.findall(rf"{pos_pred}\(([^)]+)\)", validation_program)
362
- neg_examples = re.findall(rf"{neg_pred}\(([^)]+)\)", validation_program)
 
 
 
363
  arity = 1
364
  if pos_examples:
365
  arity = pos_examples[0].count(",") + 1
 
143
  "structured_parse": False,
144
  }
145
 
146
+ # Fast path: input is a SINGLE clean Prolog paragraph (no markup, no
147
+ # trailing prose). Avoids letting the line-extractor heuristics misfire on
148
+ # legitimate multi-line rule bodies — e.g. lines starting with uppercase
149
+ # variables like `CarA \= CarB,` that aren't recognised as continuations.
150
+ # The `\n\n` check rejects outputs like
151
+ # este(T) :- \+ oeste(T).
152
+ #
153
+ # Explicación: ...
154
+ # so multilingual / explanatory prose doesn't get passed to swipl.
155
  stripped = text.strip()
156
  if (
157
  stripped.endswith(".")
158
+ and "\n\n" not in stripped
159
  and "<think>" not in text
160
  and "</think>" not in text
161
  and "```" not in text
 
364
  if enable_parsing:
365
  hypothesis = extract_hypothesis(hypothesis)
366
 
367
+ # \b word boundary prevents over-counting when one predicate name is a
368
+ # substring of the other (e.g. Spanish este/oeste, French est/ouest):
369
+ # without \b, `este\(` would also match `oeste(` and inflate pos_negs.
370
+ pos_examples = re.findall(rf"\b{pos_pred}\(([^)]+)\)", validation_program)
371
+ neg_examples = re.findall(rf"\b{neg_pred}\(([^)]+)\)", validation_program)
372
  arity = 1
373
  if pos_examples:
374
  arity = pos_examples[0].count(",") + 1