Skip to content

Fix match output for optional nodes in queries with multiple alternatives - #348

Merged
thomaskrause merged 1 commit into
korpling:mainfrom
matthias-stemmler:bugfix/optional-node-output-multiple-alternatives
Nov 4, 2026
Merged

thomaskrause merged 1 commit into
korpling:mainfrom
matthias-stemmler:bugfix/optional-node-output-multiple-alternatives

Conversation

@matthias-stemmler

Copy link
Copy Markdown
Contributor

Hey there,

I found another bug (introduced in #299) caused by the confusion between global and alternative-local node indices, similar to #338: In alternatives other than the first, the check whether to include a node in the output uses the wrong index, so when there's an optional node before a non-optional node in such an alternative, the wrong nodes get included. E.g. for tok | tok? !. lemma, an unrelated node gets included instead of the lemma node.

This PR doesn't include the refactoring mentioned in #338 (comment). Instead, I'm just passing the alternative index (which is available where we need it since #342) along with the alternative-local node index. I also considered using variable names instead of node indices to avoid the confusion altogether, but this would have been too big of a change for this bugfix - it's probably better addressed in a dedicated refactoring.

@thomaskrause thomaskrause self-assigned this Nov 4, 2026

@thomaskrause thomaskrause left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It looks good to me and simplifies the interfaces of Conjunction and Disjunction which I do like a lot. The responsibility to differentiate between "global" and "conjunction local" offsets is moved to the caller, which with your newly added interfaces has a much better chance to select the correct one without hacks like the offset variable.

I made an internal TODO for myself to refactor the things mentioned in #338 (comment) but it seems until then this is a good solution.

pub fn get_variable_by_node_nr(&self, node_nr: usize) -> Option<String> {
let pos = node_nr.checked_sub(self.var_idx_offset)?;
self.nodes.get(pos).map(|spec| spec.var.clone())
self.nodes.get(node_nr).map(|spec| spec.var.clone())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only used at one other part of the code (where we need to find the variable name for the first node of the conjunction to add a meta constraint to it), this does indeed simplify the part where it is called. Good catch!

@thomaskrause
thomaskrause merged commit eabcefe into korpling:main Nov 4, 2026
10 checks passed
@matthias-stemmler
matthias-stemmler deleted the bugfix/optional-node-output-multiple-alternatives branch November 4, 2026 18:20
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