Skip to content

Commit

Permalink
rspan(...,'all') should optionally expand span. Bugfix.
Browse files Browse the repository at this point in the history
Before, it would replace the current span with a span that
covers all matched relations, but what we want is actually to
adjust the span we have to include any matched relations, if
necessary. I.e. we never want to shrink our span with this call.

Also fixes a bug where the adjustment wasn't always done.
  • Loading branch information
jan-niestadt committed Jun 20, 2024
1 parent d258ca7 commit b828884
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public enum SpanMode {
// Return a span covering both source and target
FULL_SPAN("full"),

// Return a span covering source and target of all matched relations
// Expand the current span so it covers sources and targets of all matched relations
// (only valid for rspan(), not rel())
ALL_SPANS("all");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ private void setAdjustedStartEnd() {
startAdjusted = endAdjusted = -1;
} else {
if (spanMode == RelationInfo.SpanMode.ALL_SPANS) {
// We need all match info because we want the full span including all matched relations
// We need all match info because we want to expand the current span to include all matched relations
if (matchInfo == null)
matchInfo = new MatchInfo[context.numberOfMatchInfos()];
else
Arrays.fill(matchInfo, null);
in.getMatchInfo(matchInfo);
startAdjusted = Integer.MAX_VALUE;
endAdjusted = Integer.MIN_VALUE;
startAdjusted = in.startPosition();
endAdjusted = in.endPosition();
for (int i = 0; i < matchInfo.length; i++) {
MatchInfo info = matchInfo[i];
if (info != null && info.getType() == MatchInfo.Type.RELATION) {
Expand All @@ -125,11 +125,6 @@ private void setAdjustedStartEnd() {
endAdjusted = info.getSpanEnd();
}
}
if (startAdjusted == Integer.MAX_VALUE) {
// No relations matched; use the original span
startAdjusted = in.startPosition();
endAdjusted = in.endPosition();
}
} else {
RelationInfo relationInfo = in.getRelationInfo();
if (relationInfo == null) {
Expand Down Expand Up @@ -175,6 +170,8 @@ public int advanceStartPosition(int target) throws IOException {
// Call the naive implementation.
if (BLSpans.naiveAdvanceStartPosition(this, target) == NO_MORE_POSITIONS) {
startPos = startAdjusted = endAdjusted = NO_MORE_POSITIONS;
} else {
setAdjustedStartEnd();
}
} else {
// We know our spans will be in order, so we can use the more efficient advanceStartPosition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,12 @@ else if (curChar == 94)
{ jjCheckNAddStates(9, 11); }
break;
case 13:
{ jjCheckNAddStates(12, 14); }
break;
case 14:
case 16:
{ jjCheckNAddStates(12, 14); }
if ((0xffffffffdfffffffL & l) != 0L)
{ jjCheckNAddStates(12, 14); }
break;
case 18:
if ((0x7fffffe87fffffeL & l) == 0L)
Expand All @@ -732,9 +735,12 @@ else if (curChar == 94)
jjstateSet[jjnewStateCnt++] = 12;
break;
case 23:
{ jjCheckNAddStates(15, 17); }
break;
case 24:
case 26:
{ jjCheckNAddStates(15, 17); }
if ((0xffffffffdfffffffL & l) != 0L)
{ jjCheckNAddStates(15, 17); }
break;
case 28:
if ((0x7fffffe87fffffeL & l) == 0L)
Expand All @@ -744,9 +750,12 @@ else if (curChar == 94)
jjstateSet[jjnewStateCnt++] = 28;
break;
case 31:
{ jjCheckNAddStates(18, 20); }
break;
case 32:
case 34:
{ jjCheckNAddStates(18, 20); }
if ((0xffffffffdfffffffL & l) != 0L)
{ jjCheckNAddStates(18, 20); }
break;
case 36:
if ((0x7fffffe87fffffeL & l) == 0L)
Expand Down

0 comments on commit b828884

Please sign in to comment.