Refine search
.getAnnotationIndex(containerType); String text = containerAnnotation.getCoveredText(); sentences[i] = cas.createAnnotation(sentenceType, sentPositions[i].getStart() + containerAnnotation.getBegin(), sentPositions[i].getEnd() + containerAnnotation.getBegin()); cas.getIndexRepository().addFS(sentences[i]); logger.log(Level.FINER, "\"" + sentences[i].getCoveredText() + "\"");
private void addChunkAnnotation(CAS tcas, AnnotationFS[] tokenAnnotations, String tag, int start, int end) { AnnotationFS chunk = tcas.createAnnotation(mChunkType, tokenAnnotations[start].getBegin(), tokenAnnotations[end - 1].getEnd()); chunk.setStringValue(mChunkFeature, tag); tcas.getIndexRepository().addFS(chunk); }
FSIndex<AnnotationFS> tokenAnnotationIndex = tcas.getAnnotationIndex(mTokenType); tokens[index] = tokenAnnotation.getCoveredText(); pos[index++] = tokenAnnotation.getFeatureValueAsString( mPosFeature);
public void process(CAS tcas) { FSIndex<AnnotationFS> sentenceIndex = tcas.getAnnotationIndex(mNameType); String text = nameAnnotation.getCoveredText(); if (CAS.TYPE_NAME_STRING.equals(mStructureFeature.getRange().getName())) { nameAnnotation.setStringValue(mStructureFeature, text); } else { if (CAS.TYPE_NAME_BYTE.equals(mStructureFeature.getRange().getName())) { nameAnnotation.setByteValue(mStructureFeature, number.byteValue()); } else if (CAS.TYPE_NAME_SHORT.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setShortValue(mStructureFeature, number.shortValue()); } else if (CAS.TYPE_NAME_INTEGER.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setIntValue(mStructureFeature, number.intValue()); } else if (CAS.TYPE_NAME_LONG.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setLongValue(mStructureFeature, number.longValue()); } else if (CAS.TYPE_NAME_FLOAT.equals(mStructureFeature.getRange() .getName())) { nameAnnotation.setFloatValue(mStructureFeature, number.floatValue()); } else if (CAS.TYPE_NAME_DOUBLE.equals(mStructureFeature.getRange() .getName())) { nameAnnotation .setDoubleValue(mStructureFeature, number.doubleValue());
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); } }
public static AnnotationFS makeLinkHostMultiSPanFeatureFS(JCas aJCas, int aBegin, int aEnd, Feature aSpanFeature, String aValue, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(HOST_TYPE); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); hostA1.setStringValue(aSpanFeature, aValue); aJCas.getCas().addFsToIndexes(hostA1); return hostA1; }
private void addTCSequenceAnnotation(JCas jcas) { Type type = jcas.getCas().getTypeSystem().getType(nameSequence); Collection<AnnotationFS> sequenceAnnotation = CasUtil.select(jcas.getCas(), type); for (AnnotationFS seq : sequenceAnnotation) { TextClassificationSequence tcs = new TextClassificationSequence(jcas, seq.getBegin(), seq.getEnd()); tcs.addToIndexes(); } }
/** * The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain * number and link number references, sorted in an ascending order <br> * Iterate over each chain number and link number references and construct the chain. */ private void addChainAnnotations(JCas aJCas) { for (Type linkType : chainAnnosPerTyep.keySet()) { for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) { Type chainType = aJCas.getCas().getTypeSystem().getType( linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN); Feature firstF = chainType.getFeatureByBaseName(FIRST); Feature nextF = linkType.getFeatureByBaseName(NEXT); FeatureStructure chain = aJCas.getCas().createFS(chainType); aJCas.addFsToIndexes(chain); AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1); AnnotationFS linkFs = firstFs; chain.setFeatureValue(firstF, firstFs); for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) { linkFs.setFeatureValue(nextF, chainAnnosPerTyep.get(linkType).get(chainNo).get(i)); linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i); } } } }
public static void addSourceDocumentInformation(CAS cas, File each) { Type sdiType = cas.getTypeSystem() .getType("org.apache.uima.examples.SourceDocumentInformation"); if (sdiType != null) { if (cas.getAnnotationIndex(sdiType).size() == 0) { AnnotationFS sdi = cas.createAnnotation(sdiType, cas.getDocumentAnnotation().getBegin(), cas.getDocumentAnnotation().getEnd()); Feature uriFeature = sdiType.getFeatureByBaseName("uri"); sdi.setStringValue(uriFeature, each.toURI().getPath()); cas.addFsToIndexes(sdi); } } }
annotationsPertype = annotationsPerPostion.get(l); Type type = getType(aJCas.getCas(), l); Feature dependentFeature = null; Feature governorFeature = null; for (Feature feature : type.getFeatures()) { if (feature.getShortName().equals(DEPENDENT)) { if (feature.getShortName().equals(GOVERNOR)) { governorFeature = feature; for (AnnotationFS fs : CasUtil.select(aJCas.getCas(), type)) { AnnotationFS depFs = (AnnotationFS) fs.getFeatureValue(dependentFeature); AnnotationFS govFs = (AnnotationFS) fs.getFeatureValue(governorFeature); Type govType = govFs.getType(); getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText())); if(ambigUnits.get(govType.getName()).get(govUnit)==null){ govUnit = getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText()); getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText())); if(ambigUnits.get(govType.getName()).get(depUnit)==null){ depUnit = getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText()); if (type.getName().equals(Dependency.class.getName())){ govType = aJCas.getCas().getTypeSystem().getType(POS.class.getName());
cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes."); TypeSystem ts = cas.getTypeSystem(); Type profType = ts.getType("de.tud.Prof"); Feature profNameFeature = profType.getFeatureByBaseName("fullName"); Feature profBossFeature = profType.getFeatureByBaseName("boss"); AnnotationFS proemel = cas.createAnnotation(profType, 0, 0); proemel.setStringValue(profNameFeature, "Hans Juergen Proeml"); cas.addFsToIndexes(proemel); AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38); gurevych.setStringValue(profNameFeature, "Iryna Gurevych"); gurevych.setFeatureValue(profBossFeature, proemel); cas.addFsToIndexes(gurevych); Feature someFeature = gurevych.getType().getFeatureByBaseName(feature); if (someFeature.getRange().isPrimitive()) { String value = gurevych.getFeatureValueAsString(someFeature); System.out.println(value); FeatureStructure value = gurevych.getFeatureValue(someFeature); System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature), value.getType());
private static List<AnnotationFS> getRelAnnosOnPosition(AnnotationFS aFs, AnnotationFS aOriginFs, AnnotationFS aTargetFs, JCas aJcas) { Type type = aFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); return selectCovered(aJcas.getCas(), type, aFs.getBegin(), aFs.getEnd()).stream() .filter(fs -> fs.getFeatureValue(sourceFeat).equals(aOriginFs) && fs.getFeatureValue(targetFeat).equals(aTargetFs)) .collect(Collectors.toList()); }
private List<Annotation> extractAnnotations(List<CAS> aCasses) { List<Annotation> annotations = new ArrayList<>(); for (CAS cas : aCasses) { Type annotationType = CasUtil.getType(cas, layerName); Feature labelFeature = annotationType.getFeatureByBaseName(featureName); for (AnnotationFS ann : CasUtil.select(cas, annotationType)) { String label = ann.getFeatureValueAsString(labelFeature); annotations.add(new Annotation(label, ann.getBegin(), ann.getEnd())); } } return annotations; } // end::extractAnnotations[]
private void copyFeatures(AnnotationFS oldFS, FeatureStructure newFS, CAS cas) { List<?> features = oldFS.getType().getFeatures(); Type newType = newFS.getType(); for (Object object : features) { Feature feature = (Feature) object; String shortName = feature.getShortName(); Feature newFeature = newType.getFeatureByBaseName(shortName); if (newFeature != null) { if (feature.getRange().isPrimitive()) { String value = oldFS.getFeatureValueAsString(feature); newFS.setFeatureValueFromString(newFeature, value); } else { FeatureStructure value = oldFS.getFeatureValue(feature); newFS.setFeatureValue(newFeature, value); } } } }
public void annotationAdded(AnnotationFS annotation, RuleMatch creator) { CAS cas = annotation.getCAS(); Type t = cas.getTypeSystem().getType(TYPE); Feature featureRule = t.getFeatureByBaseName(FEATURE_RULE); Feature featureAnnotation = t.getFeatureByBaseName(FEATURE_ANNOTATION); Feature featureScript = t.getFeatureByBaseName(FEATURE_SCRIPT); Feature featureId = t.getFeatureByBaseName(FEATURE_ID); String ruleString = "provided"; String ruleScript = ""; int ruleId = -1; if (creator != null) { ruleString = verbalizer.verbalize(creator.getRule()); ruleId = creator.getRule().getId(); ruleScript = creator.getRule().getParent().getScript().getRootBlock().getNamespace(); } FeatureStructure fs = cas.createFS(t); fs.setStringValue(featureRule, ruleString); fs.setFeatureValue(featureAnnotation, annotation); fs.setIntValue(featureId, ruleId); fs.setStringValue(featureScript, ruleScript); fsList.add(fs); }
public AnnotationDetails(FeatureStructure aFS) { addr = WebAnnoCasUtil.getAddr(aFS); type = aFS.getType().getName(); if (aFS instanceof AnnotationFS) { AnnotationFS annoFS = (AnnotationFS) aFS; begin = annoFS.getBegin(); end = annoFS.getEnd(); text = annoFS.getCoveredText(); } else { begin = -1; end = -1; text = null; } }
Stem stemAnnot = new Stem(jcas, fs.getBegin(), fs.getEnd()); stemAnnot.setValue(stemValue); stemAnnot.addToIndexes(jcas); Feature feat = fs.getType().getFeatureByBaseName("stem"); if (feat != null && feat.getRange() != null && jcas.getTypeSystem().subsumes(feat.getRange(), stemAnnot.getType())) { fs.setFeatureValue(feat, stemAnnot);
@Override public void delete(SourceDocument aDocument, String aUsername, JCas aJCas, VID aVid) { AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId()); aJCas.removeFsFromIndexes(fs); // delete associated attachFeature if (getAttachTypeName() != null) { Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName()); Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName()); if (attachFeature != null) { CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0) .setFeatureValue(attachFeature, null); } } publishEvent(new SpanDeletedEvent(this, aDocument, aUsername, getLayer(), fs)); }