Refine search
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); } } }
public Feature getFeature(AnnotationFS annotation) { if(f==null) { /* * TODO Ensure that the Feature will be reset for a new TypeSystem */ f = annotation.getCAS().getTypeSystem().getFeatureByFullName(feature); } return f; }
private Type getType(String typeName) { Type type = typeSystem.getType(typeName); if (type != null) { return type; } Iterator<Type> iterator = typeSystem.getTypeIterator(); while (iterator.hasNext()) { Type toCheck = iterator.next(); if (typeName.equals(toCheck.getShortName())) { return toCheck; } } throw new IllegalArgumentException("Unknown type: " + typeName); } }
@Test public void testSingleTokenRelationWithoutFeatureValue() throws Exception { JCas jcas = makeJCasOneSentence(); CAS cas = jcas.getCas(); List<Token> tokens = new ArrayList<>(select(jcas, Token.class)); Token gov = tokens.get(0); Token dep = tokens.get(tokens.size() - 1); Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation"); // One at the beginning // WebAnno legacy conventions // AnnotationFS fs1 = cas.createAnnotation(relationType, // min(dep.getBegin(), gov.getBegin()), // max(dep.getEnd(), gov.getEnd())); // DKPro Core conventions AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd()); FSUtil.setFeature(fs1, "Governor", gov); FSUtil.setFeature(fs1, "Dependent", dep); cas.addFsToIndexes(fs1); writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation")); }
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; }
@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")); } @Test
/** * 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 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(); } }
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; }
throws AnalysisEngineProcessException CAS cas = aJCas.getCas(); Type chunkType = cas.getTypeSystem().getType(Chunk.class.getName()); Feature chunkValue = chunkType.getFeatureByBaseName("chunkValue"); for (Sentence sentence : select(aJCas, Sentence.class)) { List<Token> tokens = selectCovered(aJCas, Token.class, sentence); String[] tokenTexts = new String[tokens.size()]; String[] tokenTags = new String[tokens.size()];
public String getMarkdownString(JCas jcas) { Feature feat = jcas.getTypeSystem().getType(type).getFeatureByBaseName(featureName); SortedSet<Insertion> insertions = new TreeSet<Insertion>(); for (Annotation a : JCasUtil.select(jcas, clazz)) { insertions.add(new Insertion(beginMark, a.getBegin())); insertions.add(new Insertion(endMark + "~" + a.getFeatureValueAsString(feat) + "~", a.getEnd())); } StringBuilder exportString = new StringBuilder(jcas.getDocumentText()); for (Insertion ins : insertions) { exportString.insert(ins.position, ins.content); } if (doubleNewline) return exportString.toString().replaceAll("\n", "\n\n"); else return exportString.toString().replaceAll("\n", " \n"); }
/** * 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); }
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); } } }
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(); }
private static boolean isSlotFeature(TypeSystem aTypeSystem, Feature feat) { // This could be written more efficiently using a single conjunction. The reason this // has not been done is to facilitate debugging. boolean multiValued = feat.getRange().isArray() || aTypeSystem .subsumes(aTypeSystem.getType(CAS.TYPE_NAME_LIST_BASE), feat.getRange()); if (!multiValued) { return false; } boolean linkInheritsFromTop = CAS.TYPE_NAME_TOP .equals(aTypeSystem.getParent(feat.getRange().getComponentType()).getName()); boolean hasTargetFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_TARGET) != null; boolean hasRoleFeature = feat.getRange().getComponentType() .getFeatureByBaseName(FEAT_SLOT_ROLE) != null; return linkInheritsFromTop && hasTargetFeature && hasRoleFeature; }
private Set<String> getTypes(CAS cas) { Set<String> types = new HashSet<String>(); Iterator<Type> typeIt = cas.getTypeSystem().getTypeIterator(); nextType: while (typeIt.hasNext()) { Type type = typeIt.next(); if (type.getName().equals(cas.getDocumentAnnotation().getType().getName())) { continue; } for (InExPattern p : cookedTypePatterns) { p.matchter.reset(type.getName()); if (p.matchter.matches()) { if (p.includeInOutput) { types.add(type.getName()); } else { types.remove(type.getName()); } continue nextType; } } } return types; }