Refine search
public static boolean isSlotFeature(Feature aFeature) { if (aFeature.getRange().isArray()) { Type elementType = aFeature.getRange().getComponentType(); return elementType.getFeatureByBaseName(FEAT_SLOT_TARGET) != null && elementType.getFeatureByBaseName(FEAT_SLOT_ROLE) != null; } return false; }
public void process(CAS tcas) { FSIndex<AnnotationFS> sentenceIndex = tcas.getAnnotationIndex(mNameType); String language = tcas.getDocumentLanguage(); 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());
jcas.setDocumentText(metaText.toString() + sb.toString()); ae.process(jcas); metadata.add(CTAKES_META_PREFIX + annotation.getType().getShortName(), annotationBuilder.toString());
public static Feature getRequiredFeature(Type type, String featureName) throws AnalysisEngineProcessException { Feature feature = type.getFeatureByBaseName(featureName); if (feature == null) { throw new OpenNlpAnnotatorProcessException( ExceptionMessages.FEATURE_NOT_FOUND, new Object[] {type.getName(), featureName}); } return feature; }
public String verbalizeType(Type type) { if (type.getName().equals("uima.tcas.DocumentAnnotation")) { return "Document"; } else { return type.getShortName(); } }
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 AnnotationFS makeLinkHostFS(JCas aJCas, String aType, int aBegin, int aEnd, FeatureStructure... aLinks) { Type hostType = aJCas.getTypeSystem().getType(aType); AnnotationFS hostA1 = aJCas.getCas().createAnnotation(hostType, aBegin, aEnd); if (aLinks != null) { hostA1.setFeatureValue(hostType.getFeatureByBaseName("links"), FSCollectionFactory.createFSArray(aJCas, asList(aLinks))); } aJCas.getCas().addFsToIndexes(hostA1); return hostA1; }
/** * 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); } } } }
private static FeatureStructure makeLinkFS(JCas aJCas, String aType, String aSlotLabel, AnnotationFS aTarget) { Type linkType = aJCas.getTypeSystem().getType(aType); FeatureStructure linkA1 = aJCas.getCas().createFS(linkType); linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel); linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), aTarget); aJCas.getCas().addFsToIndexes(linkA1); return linkA1; }
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); } } }
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()); }
/** * Function for creating generic UIMA {@code FeatureStructure}s. * * @param featureStructure {@code FeatureStructure} to create a new object of the same type in the * target cas. * @return newly created {@code FeatureStructure} matching the type of the parameter {@code * FeatureStructure} */ private FeatureStructure defaultCreateType(FeatureStructure featureStructure) { String typeName = featureStructure.getType().getName(); Type targetType = targetCas.getTypeSystem().getType(typeName); return targetCas.createFS(targetType); }
/** * 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; }
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); }
/** * {@code FeatureCopier} used for features which are references to {@code FeatureStructure}s. * * @param fromFeature the {@link Feature} * @param fromFs the {@link FeatureStructure} to copy from * @param toFs the {@link FeatureStructure} to copy to */ private void defaultFeatureMapper(Feature fromFeature, FeatureStructure fromFs, FeatureStructure toFs) { TypeSystem typeSystem = fromFs.getCAS().getTypeSystem(); if (typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), fromFeature.getRange())) { STRING_COPIER.copy(fromFeature, fromFs, toFs); } else { FeatureStructure fromFeatureValue = fromFs.getFeatureValue(fromFeature); if (fromFeatureValue != null) { FeatureStructure toFeatureValue = fsEncounteredCallback.apply(fromFeatureValue); Feature toFeature = toFs.getType().getFeatureByBaseName(fromFeature.getShortName()); toFs.setFeatureValue(toFeature, toFeatureValue); } } }
@Override public void delete(JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, String aValue) { Type type = CasUtil.getType(aJCas.getCas(), getAnnotationTypeName()); Feature feature = type.getFeatureByBaseName(aFeature.getName()); for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { if (fs.getFeatureValueAsString(feature).equals(aValue)) { delete(aJCas, ((FeatureStructureImpl) fs).getAddress()); } } } }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas, String artifactID ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.createView("metadata"); metadataCas.setDocumentText(""); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); this.artifactID = artifactID; FeatureStructure documentIdFs = metadataCas.createFS(idType); documentIdFs.setStringValue(idFeat, artifactID); metadataCas.addFsToIndexes(documentIdFs); metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }
public static void collect(Set<FeatureStructure> aFSes, FeatureStructure aFS) { if (aFS != null && !aFSes.contains(aFS)) { aFSes.add(aFS); for (Feature f : aFS.getType().getFeatures()) { if (!f.getRange().isPrimitive() && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) { collect(aFSes, aFS.getFeatureValue(f)); } } } }
private static void forceSetFeatureValue(FeatureStructure aFS, String aFeatureName, String aValue) { CASImpl casImpl = (CASImpl) aFS.getCAS().getLowLevelCAS(); TypeSystemImpl ts = (TypeSystemImpl) aFS.getCAS().getTypeSystem(); Feature feat = aFS.getType().getFeatureByBaseName(aFeatureName); int featCode = ((FeatureImpl) feat).getCode(); int thisType = ((TypeImpl) aFS.getType()).getCode(); if (!ts.isApprop(thisType, featCode)) { throw new IllegalArgumentException("Feature structure does not have that feature"); } if (!ts.subsumes(ts.getType(CAS.TYPE_NAME_STRING), feat.getRange())) { throw new IllegalArgumentException("Not a string feature!"); } casImpl.ll_setStringValue(casImpl.ll_getFSRef(aFS), featCode, aValue); }
CASArtifact( @Nullable LabelAdapters labelAdapters, CAS cas ) { this.labelAdapters = labelAdapters; this.cas = cas; TypeSystem typeSystem = cas.getTypeSystem(); metadataType = typeSystem.getType("ArtifactMetadata"); keyFeature = metadataType.getFeatureByBaseName("key"); valueFeature = metadataType.getFeatureByBaseName("value"); metadataCas = cas.getView("metadata"); Type idType = typeSystem.getType("ArtifactID"); Feature idFeat = idType.getFeatureByBaseName("artifactID"); FSIndexRepository indexRepository = metadataCas.getIndexRepository(); artifactID = indexRepository.getIndex("artifactID", idType).iterator().get() .getStringValue(idFeat); metadataIndex = indexRepository.getIndex("metadata", metadataType); casMetadata = new CASMetadata(); }