Skip to content

Commit

Permalink
#1329 - Span annotations with slot features may disappear from WebAnn…
Browse files Browse the repository at this point in the history
…o TSV

- Add a placeholder in the TARGET column for slot features if there are no slots at all
- Updated existing unit tests with the placeholder
- Added an additional unit test
- Did not update the TSV version since the change is not necessarily incompatible
  • Loading branch information
reckart committed Feb 18, 2019
1 parent 70420f7 commit e8a992f
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,15 @@ private static void scanUnitForAmbiguousSlotReferences(TsvUnit aUnit)
for (AnnotationFS aFS : annotationsForColumn) {
FeatureStructure[] links = getFeature(aFS, col.uimaFeature,
FeatureStructure[].class);
for (FeatureStructure link : links) {
AnnotationFS targetFS = getFeature(link, TsvSchema.FEAT_SLOT_TARGET,
AnnotationFS.class);
if (targetFS == null) {
throw new IllegalStateException("Slot link has no target: " + link);
if (links != null) {
for (FeatureStructure link : links) {
AnnotationFS targetFS = getFeature(link, TsvSchema.FEAT_SLOT_TARGET,
AnnotationFS.class);
if (targetFS == null) {
throw new IllegalStateException("Slot link has no target: " + link);
}
aUnit.getDocument().addDisambiguationId(targetFS);
}
aUnit.getDocument().addDisambiguationId(targetFS);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,13 @@ private void setFeatures(TsvColumn aCol, TsvUnit aUnit, AnnotationFS aAnnotation
FeatureStructure[] links = getFeature(aAnnotation,
aCol.uimaFeature.getShortName(), FeatureStructure[].class);

assert values.length == links.length;
assert (links.length == 0 && values.length == 1 && NULL_VALUE.equals(values[0]))
|| (values.length == links.length);

for (int i = 0; i < values.length; i++) {
String value = values[i];

if (NULL_COLUMN.equals(value)) {
if (NULL_VALUE.equals(value) || NULL_COLUMN.equals(value)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ private static void writeSlotTarget(PrintWriter aOut, TsvDocument aDoc, TsvColum
}
}
else {
aOut.print(NULL_COLUMN);
// If the slot hosts has no slots, we use this column as a placeholder so we know
// the span of the slot host
aOut.print(NULL_VALUE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,35 @@ WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"),
WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan"));
}

@Test
public void testUnsetSlotFeature() throws Exception
{
JCas jcas = makeJCasOneSentence();
CAS cas = jcas.getCas();

List<Token> tokens = new ArrayList<>(select(jcas, Token.class));

Token t1 = tokens.get(0);
Token t2 = tokens.get(1);
Token t3 = tokens.get(2);

Type type = cas.getTypeSystem().getType("webanno.custom.SimpleSpan");
AnnotationFS s2 = cas.createAnnotation(type, t2.getBegin(), t2.getEnd());
cas.addFsToIndexes(s2);
AnnotationFS s3 = cas.createAnnotation(type, t3.getBegin(), t3.getEnd());
cas.addFsToIndexes(s3);

makeLinkHostFS(jcas, "webanno.custom.FlexLinkHost", t1.getBegin(), t1.getEnd(),
(FeatureStructure[]) null);

writeAndAssertEquals(jcas,
WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.FlexLinkHost:links"),
WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan",
"webanno.custom.SimpleLinkHost"),
WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.FlexLinkType"),
WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan"));
}

@Test
public void testSimpleSlotFeatureWithoutValues() throws Exception
{
Expand Down Expand Up @@ -1752,8 +1781,10 @@ private static AnnotationFS makeLinkHostFS(JCas aJCas, String aType, int aBegin,
{
Type hostType = aJCas.getTypeSystem().getType(aType);
AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd);
hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"),
FSCollectionFactory.createFSArray(aJCas, asList(aLinks)));
if (aLinks != null) {
hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"),
FSCollectionFactory.createFSArray(aJCas, asList(aLinks)));
}
aJCas.getCas().addFsToIndexes(hostA1);
return hostA1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,37 @@
</featureDescription>
</features>
</typeDescription>
<typeDescription>
<name>webanno.custom.FlexLinkHost</name>
<description/>
<supertypeName>uima.tcas.Annotation</supertypeName>
<features>
<featureDescription>
<name>links</name>
<description/>
<rangeTypeName>uima.cas.FSArray</rangeTypeName>
<elementType>webanno.custom.FlexLinkType</elementType>
<multipleReferencesAllowed>false</multipleReferencesAllowed>
</featureDescription>
</features>
</typeDescription>
<typeDescription>
<name>webanno.custom.FlexLinkType</name>
<description/>
<supertypeName>uima.cas.TOP</supertypeName>
<features>
<featureDescription>
<name>role</name>
<description/>
<rangeTypeName>uima.cas.String</rangeTypeName>
</featureDescription>
<featureDescription>
<name>target</name>
<description/>
<rangeTypeName>uima.tcas.Annotation</rangeTypeName>
</featureDescription>
</features>
</typeDescription>
<typeDescription>
<name>webanno.custom.SimpleChain</name>
<description/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


#Text=This is a test .
1-1 0-4 This _[1]|pr1[2] _|1-1[1]
1-1 0-4 This _[1]|pr1[2] *|1-1[1]
1-2 5-7 is _ _
1-3 8-9 a _ _
1-4 10-14 test _ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


#Text=This is a test .
1-1 0-4 This _ _[1]|_[2] _|_ val1[1]|val2[2]
1-1 0-4 This _ _[1]|_[2] *|* val1[1]|val2[2]
1-2 5-7 is * _ _ _
1-3 8-9 a * _ _ _
1-4 10-14 test _ _ _ _
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#FORMAT=WebAnno TSV 3.2
#T_SP=webanno.custom.SimpleSpan|
#T_SP=webanno.custom.FlexLinkHost|ROLE_webanno.custom.FlexLinkHost:links_webanno.custom.FlexLinkType|uima.tcas.Annotation


#Text=This is a test .
1-1 0-4 This _ _ *
1-2 5-7 is * _ _
1-3 8-9 a * _ _
1-4 10-14 test _ _ _
1-5 15-16 . _ _ _
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><xmi:XMI xmlns:pos="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/pos.ecore" xmlns:tcas="http:///uima/tcas.ecore" xmlns:xmi="http://www.omg.org/XMI" xmlns:cas="http:///uima/cas.ecore" xmlns:tweet="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/pos/tweet.ecore" xmlns:morph="http:///de/tudarmstadt/ukp/dkpro/core/api/lexmorph/type/morph.ecore" xmlns:dependency="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/dependency.ecore" xmlns:type6="http:///de/tudarmstadt/ukp/dkpro/core/api/semantics/type.ecore" xmlns:type="http:///de/tudarmstadt/ukp/dkpro/core/api/anomaly/type.ecore" xmlns:type7="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type.ecore" xmlns:type3="http:///de/tudarmstadt/ukp/dkpro/core/api/metadata/type.ecore" xmlns:type4="http:///de/tudarmstadt/ukp/dkpro/core/api/ner/type.ecore" xmlns:type5="http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore" xmlns:type2="http:///de/tudarmstadt/ukp/dkpro/core/api/coref/type.ecore" xmlns:constituent="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/constituent.ecore" xmlns:chunk="http:///de/tudarmstadt/ukp/dkpro/core/api/syntax/type/chunk.ecore" xmlns:custom="http:///webanno/custom.ecore" xmi:version="2.0">
<cas:NULL xmi:id="0"/>
<type3:DocumentMetaData xmi:id="1" sofa="12" begin="0" end="16" documentId="doc" isLastSegment="false"/>
<type5:Token xmi:id="19" sofa="12" begin="0" end="4"/>
<type5:Token xmi:id="28" sofa="12" begin="5" end="7"/>
<type5:Token xmi:id="37" sofa="12" begin="8" end="9"/>
<type5:Token xmi:id="46" sofa="12" begin="10" end="14"/>
<type5:Token xmi:id="55" sofa="12" begin="15" end="16"/>
<type5:Sentence xmi:id="64" sofa="12" begin="0" end="16"/>
<custom:SimpleSpan xmi:id="68" sofa="12" begin="5" end="7"/>
<custom:SimpleSpan xmi:id="72" sofa="12" begin="8" end="9"/>
<custom:FlexLinkHost xmi:id="76" sofa="12" begin="0" end="4"/>
<cas:Sofa xmi:id="12" sofaNum="1" sofaID="_InitialView" mimeType="text" sofaString="This is a test ."/>
<cas:View sofa="12" members="1 19 28 37 46 55 64 68 72 76"/>
</xmi:XMI>

0 comments on commit e8a992f

Please sign in to comment.