@Override public void addFsToIndexes(FeatureStructure fs) { testLiveness(); delegate.addFsToIndexes(fs); }
/** * Creates a tag-annotation over a constituent * * @param aBegin * start-index of the constituent span * @param aEnd * end-index of the constituent span * @param aTag * the tag value */ public void createTagAnnotation(int aBegin, int aEnd, String aTag) { Tag newTag = new Tag(jCas, aBegin, aEnd); newTag.setValue(aTag); jCas.addFsToIndexes(newTag); }
/** * Add an annotation starting at the specified position and ending at the current end of the text. * The created annotation is returned and further properties can be set on it. The annotation is * already added to the indexes. * * @param <T> * annotation type * @param aBegin * begin offset. * @param aClass * annotation type * @return annotation instance - can be used to set features or determine offsets */ @SuppressWarnings("unchecked") public <T> T add(int aBegin, Class<T> aClass) { Type type = getType(jcas, aClass); int end = documentText.length(); AnnotationFS fs = jcas.getCas().createAnnotation(type, aBegin, end); jcas.addFsToIndexes(fs); return (T) fs; }
/** * Append a text annotated with the specified annotation. The created annotation is returned and * further properties can be set on it. The annotation is already added to the indexes. * * @param aText * covered text * @param aClass * annotation type * @param <T> * annotation type * @return annotation instance - can be used to set features or determine offsets */ @SuppressWarnings("unchecked") public <T> T add(String aText, Class<T> aClass) { Type type = getType(jcas, aClass); int begin = documentText.length(); add(aText); int end = documentText.length(); AnnotationFS fs = jcas.getCas().createAnnotation(type, begin, end); jcas.addFsToIndexes(fs); return (T) fs; }
/** * Modify existing non-stackable annotations from one of the users annotation */ private static void modifySpanAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs, JCas aJCas) { Feature[] features = getAllFeatures(aOldFs); for (Feature f : features) { if (isLinkOrBasicFeatures(aOldFs, f)) { continue; } setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f)); } aJCas.addFsToIndexes(aNewFs); }
/** * Modify existing non-stackable annotations from one of the users annotation */ private static void modifySpanAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs, JCas aJCas) { Feature[] features = getAllFeatures(aOldFs); for (Feature f : features) { if (isLinkOrBasicFeatures(aOldFs, f)) { continue; } setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f)); } aJCas.addFsToIndexes(aNewFs); }
private static void modifyRelationAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs, JCas aJCas) { Feature[] features = getAllFeatures(aOldFs); Type type = aOldFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); for (Feature f : features) { if (isLinkOrBasicFeatures(aOldFs, f)) { continue; } if (f.equals(sourceFeat)) { continue; } else if (f.equals(targetFeat)) { continue; } setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f)); } aJCas.addFsToIndexes(aNewFs); }
private static void modifyRelationAnnotation(AnnotationFS aOldFs, AnnotationFS aNewFs, JCas aJCas) { Feature[] features = getAllFeatures(aOldFs); Type type = aOldFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); for (Feature f : features) { if (isLinkOrBasicFeatures(aOldFs, f)) { continue; } if (f.equals(sourceFeat)) { continue; } else if (f.equals(targetFeat)) { continue; } setFeatureValue(aNewFs, f, getFeatureValue(aOldFs, f)); } aJCas.addFsToIndexes(aNewFs); }
/** * Create a new chain head feature structure. Already adds the chain to the CAS. */ private FeatureStructure newChain(JCas aJCas, AnnotationFS aFirstLink) { Type chainType = getAnnotationType(aJCas.getCas()); FeatureStructure newChain = aJCas.getCas().createFS(chainType); newChain.setFeatureValue(chainType.getFeatureByBaseName(chainFirstFeatureName), aFirstLink); aJCas.addFsToIndexes(newChain); return newChain; }
private AnnotationFS createTokenAnno(JCas aJCas, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(Token.class.getTypeName()); AnnotationFS token = aJCas.getCas().createAnnotation(type, aBegin, aEnd); aJCas.addFsToIndexes(token); return token; }
/** * Create a new chain head feature structure. Already adds the chain to the CAS. */ private FeatureStructure newChain(JCas aJCas, AnnotationFS aFirstLink) { Type chainType = CasUtil.getType(aJCas.getCas(), getChainTypeName()); FeatureStructure newChain = aJCas.getCas().createFS(chainType); newChain.setFeatureValue(chainType.getFeatureByBaseName(getChainFirstFeatureName()), aFirstLink); aJCas.addFsToIndexes(newChain); return newChain; }
/** * Create a new chain head feature structure. Already adds the chain to the CAS. */ private FeatureStructure newChain(JCas aJCas, AnnotationFS aFirstLink) { Type chainType = CasUtil.getType(aJCas.getCas(), getChainTypeName()); FeatureStructure newChain = aJCas.getCas().createFS(chainType); newChain.setFeatureValue(chainType.getFeatureByBaseName(getChainFirstFeatureName()), aFirstLink); aJCas.addFsToIndexes(newChain); return newChain; }
private void processDependency(JCas jcas, Token childToken, BasicConstructionNode parentNode, String relationName, ArrayList<Token> tokenAnnotations, Sentence sentenceAnno) throws AbstractNodeCasException, ParserRunException { // Taken mostly from de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.StanfordAnnotator.createDependencyAnnotation() // Known issue in DKPro if (relationName.equalsIgnoreCase("AUX")) { relationName = "AUX0"; } String dependencyTypeName = DEPPACKAGE + relationName.toUpperCase(); Type type = jcas.getTypeSystem().getType(dependencyTypeName); if (type == null) { throw new ParserRunException("Type [" + dependencyTypeName + "] mapped to tag [" + relationName + "] is not defined in type system"); } Token parentTokenAnno = AbstractNodeCASUtils.nodeToToken(tokenAnnotations, parentNode); AnnotationFS anno = jcas.getCas().createAnnotation(type, sentenceAnno.getBegin(), sentenceAnno.getEnd()); anno.setStringValue(type.getFeatureByBaseName("DependencyType"), relationName); anno.setFeatureValue(type.getFeatureByBaseName("Governor"), parentTokenAnno); anno.setFeatureValue(type.getFeatureByBaseName("Dependent"), childToken); jcas.addFsToIndexes(anno); } }
private static void copyRelationAnnotation(AnnotationFS aOldFs, AnnotationFS asourceFS, AnnotationFS aTargetFs, JCas aJCas) { Feature[] features = getAllFeatures(aOldFs); Type type = aOldFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); AnnotationFS newFs = aJCas.getCas().createAnnotation(type, aOldFs.getBegin(), aOldFs.getEnd()); for (Feature f : features) { if (isLinkOrBasicFeatures(aOldFs, f)) { continue; } if (f.equals(sourceFeat)) { newFs.setFeatureValue(f, asourceFS); } else if (f.equals(targetFeat)) { newFs.setFeatureValue(f, aTargetFs); } else { setFeatureValue(newFs, f, getFeatureValue(aOldFs, f)); } } aJCas.addFsToIndexes(newFs); }
private AnnotationFS createNEAnno(JCas aJCas, String aValue, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(NamedEntity.class.getTypeName()); AnnotationFS clickedFs = aJCas.getCas().createAnnotation(type, aBegin, aEnd); Feature value = type.getFeatureByBaseName("value"); clickedFs.setStringValue(value, aValue); aJCas.addFsToIndexes(clickedFs); return clickedFs; }
private AnnotationFS createPOSAnno(JCas aJCas, String aValue, int aBegin, int aEnd) { Type type = aJCas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = aJCas.getCas().createAnnotation(type, aBegin, aEnd); Feature posValue = type.getFeatureByBaseName("PosValue"); clickedFs.setStringValue(posValue, aValue); aJCas.addFsToIndexes(clickedFs); return clickedFs; }
/** * Fill the document metadata information * * @param jCas ye olde ... * @throws SQLException - */ private void setMetadata( final JCas jCas ) throws SQLException { final Metadata metadata = new Metadata( jCas ); metadata.setPatientIdentifier( getResult( _patientIdentifier ) ); final Long patientId = getResultLong( _patientId ); if ( patientId != null ) { metadata.setPatientID( patientId ); } final SourceData sourcedata = createSourceData( jCas ); metadata.setSourceData( sourcedata ); final Demographics demographics = createDemographics( jCas ); metadata.setDemographics( demographics ); jCas.addFsToIndexes( metadata ); }
@Test public void simpleCopyToDiffExistingAnnoWithNoStackingTest() throws Exception { JCas jcas = createJCas(); Type type = jcas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = createPOSAnno(jcas, "NN", 0, 0); JCas mergeCAs = createJCas(); AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0); Feature posValue = type.getFeatureByBaseName("PosValue"); existingFs.setStringValue(posValue, "NE"); mergeCAs.addFsToIndexes(existingFs); MergeCas.addSpanAnnotation(new AnnotatorStateImpl(CURATION), annotationSchemaService, posLayer, mergeCAs, clickedFs, false); assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size()); }
@Test public void simpleCopyToSameExistingAnnoTest() throws Exception { JCas jcas = createJCas(); Type type = jcas.getTypeSystem().getType(POS.class.getTypeName()); AnnotationFS clickedFs = createPOSAnno(jcas, "NN", 0, 0); JCas mergeCas = createJCas(); AnnotationFS existingFs = mergeCas.getCas().createAnnotation(type, 0, 0); Feature posValue = type.getFeatureByBaseName("PosValue"); existingFs.setStringValue(posValue, "NN"); mergeCas.addFsToIndexes(existingFs); Assertions.assertThatExceptionOfType(AnnotationException.class) .isThrownBy(() -> MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, posLayer, mergeCas, clickedFs, false)) .withMessageContaining("annotation already exists"); }
@Test public void simpleCopyToDiffExistingAnnoWithStackingTest() throws Exception { AnnotatorState state = new AnnotatorStateImpl(CURATION); state.setUser(new User()); neLayer.setAllowStacking(true); JCas jcas = createJCas(); Type type = jcas.getTypeSystem().getType(NamedEntity.class.getTypeName()); AnnotationFS clickedFs = createNEAnno(jcas, "NN", 0, 0); JCas mergeCAs = createJCas(); createTokenAnno(mergeCAs, 0, 0); AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0); Feature posValue = type.getFeatureByBaseName("value"); existingFs.setStringValue(posValue, "NE"); mergeCAs.addFsToIndexes(existingFs); MergeCas.addSpanAnnotation(state, annotationSchemaService, neLayer, mergeCAs, clickedFs, true); assertEquals(2, selectCovered(mergeCAs.getCas(), type, 0, 0).size()); }