Skip to content

Fix C runtime parser: register all case-variant sequences in lookahead - #205

Open
martingercke wants to merge 1 commit into
GrammaticalFramework:masterfrom
martingercke:fix-parser-lookahead-case-ties
Open

Fix C runtime parser: register all case-variant sequences in lookahead#205
martingercke wants to merge 1 commit into
GrammaticalFramework:masterfrom
martingercke:fix-parser-lookahead-case-ties

Conversation

@martingercke

Copy link
Copy Markdown

Fixes #204.

pgf_parsing_lookahead registered only one sequence per exact match. With case-insensitive matching, capitalized/lowercase twin sequences (e.g. "Schule"/"schule" in the German WordNet grammar) compare equal, so only one of them entered state->lexicon_idx — decided by array-index parity. Lemmas indexed on the unregistered twin were unparseable (Schule, Brot, Stadt, … fail with "Unexpected token" although lookupMorpho finds them).

This patch registers the entire contiguous run of comparator-equal sequences on an exact match (left/right scans via a small helper) and recurses strictly outside that run.

  • No change for unambiguous matches (the run has length 1).
  • lookupMorpho and linearization untouched.
  • Verified against master 1c086bed2 (unmodified build before/after) with the German WordNet grammar compiled by the master-branch compiler: all affected words parse correctly after the fix; a regression battery (Food example grammar, German sentences, morphology lookups) is unchanged.

pgf_parsing_lookahead is a 'find all prefixes' binary search over
concr->sequences that assumes a strict total order: on an exact match it
registers exactly one sequence in state->lexicon_idx and recurses with
length bounds that exclude any other sequence of the same length.

With case-insensitive matching, a capitalized lexical sequence and its
lowercase twin (e.g. "Schule"/"schule" in the German WordNet grammar)
compare equal and sit adjacently - a tie. Only one of the twins got
registered, decided by array-index parity. Lemmas indexed on the
unregistered twin were never predicted, making those words unparseable
(e.g. parse -cat=N "Schule"/"Brot"/"Stadt" failed with 'Unexpected
token' although lookupMorpho finds them), while others (Birne, Haus)
worked by luck.

Fix: on an exact match, register the entire contiguous run of sequences
that are equal under the comparator, then recurse strictly outside that
run. No behavior change for unambiguous matches; lookupMorpho and
linearization are untouched.

Fixes GrammaticalFramework#204
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.

C runtime parser: words with case-variant lexical sequences are unparseable

1 participant