Skip to content

Include token in subgraph even if not covered by segmentation node#334

Merged
thomaskrause merged 3 commits intokorpling:mainfrom
matthias-stemmler:fix-subgraph-for-uncovered-token
Apr 17, 2026
Merged

Include token in subgraph even if not covered by segmentation node#334
thomaskrause merged 3 commits intokorpling:mainfrom
matthias-stemmler:fix-subgraph-for-uncovered-token

Conversation

@matthias-stemmler
Copy link
Copy Markdown
Contributor

This fixes a regression I introduced in #289: When subgraph is called with a token and a segmentation, and the token is not covered by any segmentation node, then the token is not included in the subgraph.

In #289 I had filtered out matched tokens to ensure that tokens are sorted, claiming that new_overlapped_nodes_iterator already included the matched tokens. However, if a segmentation is specified, this is only true for tokens that are covered by a segmentation node.

The fix changes get_left_right_token_with_offset_with_segmentation so that instead of failing, it returns just the covered tokens without context in case none of them is covered by a segmentation node.

I hope this doesn't break any other invariants. At least the existing tests are still green. 🙂

@matthias-stemmler
Copy link
Copy Markdown
Contributor Author

I added another test to close the (pre-existing) gap in test coverage. The remaining CI failure seems to be a permissions issue.

@thomaskrause thomaskrause self-assigned this Apr 15, 2026
@thomaskrause thomaskrause self-requested a review April 17, 2026 08:42
Copy link
Copy Markdown
Member

@thomaskrause thomaskrause left a comment

Choose a reason for hiding this comment

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

Looks good to me!

let right_seg = *covering_segmentation_nodes
.last()
.ok_or(GraphAnnisError::NoCoveredTokenForSubgraph)?;
let (left_seg, right_seg) = match covering_segmentation_nodes[..] {
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.

I was wondering if it was better to keep the error at part of the code and handle it in the calling function, thus falling back to the covered token borders in any case when there is an error. The method name could otherwise be a little bit misleading because one could expect it to only work when the segmentation coverage is given.

Since get_left_right_token_with_offset_with_segmentation is only part of the internal API of subgraph.rs and not (crate) public this probably does not make a lot of a difference where the fallback is implemented.

Also, the fallback at this position makes sense, since the segmentation parameter is only used to extend the context to the left and right, not to reduce the already existing context given by the covered token by throwing an error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had similar thoughts when deciding where to put the fallback, and concluded on the reasoning you're giving in your last paragraph. The with_segmentation in the method name could be understood as "extend the context according to the segmentation if there is segmentation coverage" (and otherwise don't extend it).

Handling it at the call site by applying the fallback in case of any error can potentially obscure other, unrelated, errors, so I thought keeping it here is the safer option.

@thomaskrause
Copy link
Copy Markdown
Member

Thanks for the fix! The failing workflow is actually just the part where the verify.sh output is added as a comment to the PR. I might have to adapt this to check if the permission before trying to add the comment.

I added a commit with a changelog entry, which would also probably run the CI again with the correct permissions.

@thomaskrause thomaskrause enabled auto-merge April 17, 2026 08:54
@thomaskrause thomaskrause disabled auto-merge April 17, 2026 08:58
@thomaskrause thomaskrause merged commit d54b0b7 into korpling:main Apr 17, 2026
9 of 10 checks passed
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