-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 665 #687
Open
ChaseDuncan
wants to merge
5
commits into
master
Choose a base branch
from
issue-665
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Issue 665 #687
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01bee8b
Fix 665: SpanLabelView may not enforce non-overlap constraint
ChaseDuncan a88173d
Removed extra line and some superfluous, empty comment.
ChaseDuncan 01e8bd4
Addressing comments
ChaseDuncan 786459c
Fixing TeamCity errors
ChaseDuncan 4c33f4f
Addressing CI failures
ChaseDuncan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...st/java/edu/illinois/cs/cogcomp/core/datastructures/textannotation/SpanLabelViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package edu.illinois.cs.cogcomp.core.datastructures.textannotation; | ||
|
||
import edu.illinois.cs.cogcomp.annotation.BasicTextAnnotationBuilder; | ||
import edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder; | ||
import edu.illinois.cs.cogcomp.core.datastructures.IntPair; | ||
import edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent; | ||
import edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView; | ||
import edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation; | ||
import edu.illinois.cs.cogcomp.nlp.tokenizer.Tokenizer; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Test that addConstituent(Constituent) does not allow overlapping spans | ||
*/ | ||
public class SpanLabelViewTest { | ||
SpanLabelView overlappingSpansView; | ||
SpanLabelView noOverlappingSpansView; | ||
TextAnnotation ta; | ||
Constituent baseConstituent; | ||
Constituent overlappingConstituent; | ||
|
||
private Tokenizer.Tokenization tokenization; | ||
|
||
String viewName = "VIEWNAME"; | ||
String viewGenerator = "VIEW-GENERATOR"; | ||
String text = "This is a test string; do not pay it any mind."; | ||
String corpusId = "TEST"; | ||
String textId = "ID"; | ||
|
||
double score = 42.0; | ||
int baseStart = 0; | ||
int baseEnd = 5; | ||
int overStart = 2; | ||
int overEnd = 6; | ||
|
||
private Tokenizer.Tokenization getTokenization(String text) { | ||
String[] tokens = text.split("\\s"); | ||
List<IntPair> characterOffsets = new ArrayList<>(); | ||
int[] sentenceEndArray = {tokens.length}; | ||
|
||
int charOffsetBegin = 0; | ||
int charOffsetEnd = 0; | ||
for (int i = 0; i < text.length(); i++) { | ||
char c = text.charAt(i); | ||
if (Character.isWhitespace(c)) { | ||
charOffsetEnd = i; | ||
IntPair tokenOffsets = new IntPair(charOffsetBegin, charOffsetEnd); | ||
characterOffsets.add(tokenOffsets); | ||
charOffsetBegin = charOffsetEnd + 1; | ||
} | ||
} | ||
IntPair tokenOffsets = new IntPair(charOffsetBegin, text.length()); | ||
characterOffsets.add(tokenOffsets); | ||
|
||
IntPair[] charOffsetArray = new IntPair[characterOffsets.size()]; | ||
|
||
for (int i = 0; i < characterOffsets.size(); i++) { | ||
charOffsetArray[i] = characterOffsets.get(i); | ||
} | ||
Tokenizer.Tokenization tokenization = | ||
new Tokenizer.Tokenization(tokens, charOffsetArray, sentenceEndArray); | ||
return tokenization; | ||
} | ||
|
||
@Before | ||
public void init(){ | ||
TextAnnotationBuilder taBuilder = new BasicTextAnnotationBuilder(); | ||
ta = taBuilder.createTextAnnotation(this.corpusId, this.textId, this.text, getTokenization(this.text)); | ||
boolean allowOverlappingSpans = true; | ||
overlappingSpansView = new SpanLabelView(this.viewName, this.viewGenerator, | ||
ta, this.score, allowOverlappingSpans); | ||
allowOverlappingSpans = false; | ||
noOverlappingSpansView = new SpanLabelView(this.viewName, this.viewGenerator, | ||
ta, this.score, allowOverlappingSpans); | ||
|
||
baseConstituent = new Constituent("BASE", this.score, this.viewName, ta, baseStart, baseEnd); | ||
overlappingConstituent = new Constituent("OVER", this.score, this.viewName, ta, overStart, overEnd); | ||
} | ||
|
||
@Test | ||
public void testOverlappingSpans(){ | ||
overlappingSpansView.addConstituent(baseConstituent); | ||
overlappingSpansView.addConstituent(overlappingConstituent); | ||
for(Constituent c : overlappingSpansView.getConstituents()){ | ||
if(c.getLabel().equals("BASE")) { | ||
assert c.getStartSpan() == this.baseStart; | ||
assert c.getEndSpan() == this.baseEnd; | ||
}else { | ||
assert c.getStartSpan() == this.overStart; | ||
assert c.getEndSpan() == this.overEnd; | ||
} | ||
} | ||
} | ||
|
||
@Test(expected=IllegalArgumentException.class) | ||
public void testNoOverlappingSpans(){ | ||
noOverlappingSpansView.addConstituent(baseConstituent); | ||
noOverlappingSpansView.addConstituent(overlappingConstituent); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small improvement: please move start/end assignments inside if{} block, as they aren't being used otherwise.