use of org.apache.uima.cas.Type in project webanno by webanno.
the class ChainAdapter method newLink.
/**
* Create a new link annotation. Already adds the chain to the CAS.
*/
private AnnotationFS newLink(JCas aJCas, int aBegin, int aEnd) {
String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
AnnotationFS newLink = aJCas.getCas().createAnnotation(linkType, aBegin, aEnd);
aJCas.getCas().addFsToIndexes(newLink);
return newLink;
}
use of org.apache.uima.cas.Type in project webanno by webanno.
the class ChainAdapter method getSpan.
// get feature Value of existing span annotation
public Serializable getSpan(JCas aJCas, int aBegin, int aEnd, AnnotationFeature aFeature, String aLabelValue) {
List<Token> tokens = selectOverlapping(aJCas, Token.class, aBegin, aEnd);
int begin = tokens.get(0).getBegin();
int end = tokens.get(tokens.size() - 1).getEnd();
String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), linkType, begin, end)) {
if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
return getFeatureValue(aFeature, fs);
}
}
return null;
}
use of org.apache.uima.cas.Type in project webanno by webanno.
the class WebAnnoCasUtil method setLinkFeature.
private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) {
Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName());
Feature roleFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeRoleFeatureName());
Feature targetFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeTargetFeatureName());
// Create all the links
// FIXME: actually we could re-use existing link link feature structures
List<FeatureStructure> linkFSes = new ArrayList<>();
if (aValue != null) {
// remove duplicate links
Set<LinkWithRoleModel> links = new HashSet<>(aValue);
for (LinkWithRoleModel e : links) {
// set
if (e.targetAddr == -1) {
continue;
}
FeatureStructure link = aFS.getCAS().createFS(linkType);
link.setStringValue(roleFeat, e.role);
link.setFeatureValue(targetFeat, selectByAddr(aFS.getCAS(), e.targetAddr));
linkFSes.add(link);
}
}
setLinkFeatureValue(aFS, feature, linkFSes);
}
use of org.apache.uima.cas.Type in project webanno by webanno.
the class WebAnnoTsv3WriterTestBase method testZeroLengthSlotFeature1.
@Test
public void testZeroLengthSlotFeature1() 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(), t3.getEnd());
cas.addFsToIndexes(s2);
AnnotationFS s3 = cas.createAnnotation(type, t2.getBegin(), t3.getEnd());
cas.addFsToIndexes(s3);
FeatureStructure link1 = makeLinkFS(jcas, "p1", s2);
FeatureStructure link2 = makeLinkFS(jcas, "p2", s3);
makeLinkHostFS(jcas, t1.getBegin(), t1.getBegin(), link1, link2);
writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SLOT_FEATS, asList("webanno.custom.SimpleLinkHost:links"), WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList("webanno.custom.SimpleSpan", "webanno.custom.SimpleLinkHost"), WebannoTsv3Writer.PARAM_LINK_TYPES, asList("webanno.custom.LinkType"), WebannoTsv3Writer.PARAM_SLOT_TARGETS, asList("webanno.custom.SimpleSpan"));
}
use of org.apache.uima.cas.Type in project webanno by webanno.
the class WebAnnoTsv3WriterTestBase method testMultiTokenChain.
@Test
public void testMultiTokenChain() 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);
Token t4 = tokens.get(3);
Type head = cas.getTypeSystem().getType("webanno.custom.SimpleChain");
Type link = cas.getTypeSystem().getType("webanno.custom.SimpleLink");
makeChainHead(head, makeChainLink(link, cas, t1.getBegin(), t2.getEnd(), null, null, makeChainLink(link, cas, t3.getBegin(), t4.getEnd(), null, null, null)));
writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_CHAIN_LAYERS, asList("webanno.custom.Simple"));
}
Aggregations