Java Code Examples for org.apache.uima.jcas.cas.FSArray#set()
The following examples show how to use
org.apache.uima.jcas.cas.FSArray#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TRExReader.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
private <K extends Constituent> K getConstituent(TAnnotation constituent, Class<K> clazz, JCas jCas) { Constituent result = getInstancedConstitient(jCas, constituent, clazz); if(constituent.boundaries != null) { result.setExplicit(true); result.setBegin(constituent.boundaries[0]); result.setEnd(constituent.boundaries[1]); } result.setUri(constituent.uri); List<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, result.getBegin(), result.getEnd()); FSArray array = new FSArray(jCas, tokens.size()); for (int i = 0; i < tokens.size(); i++) { array.set(i, tokens.get(i)); } array.addToIndexes(); result.setTokens(array); jCas.addFsToIndexes(clazz.cast(result)); return clazz.cast(result); }
Example 2
Source File: XCASDeserializer.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Same as above, but specialized for array values, not feature slot values * @param extId * @param extId the external ID identifying either a deserialized FS or an out-of-typesystem instance * @param pos the index in the array * @return the TOP instance to be set as the value in an array or as the value of a feature. * @return */ private void finalizeArrayRefValue(int extId, int pos, FSArray fs) { FSInfo fsInfo = fsTree.get(extId); if (fsInfo == null) { // this element may be a ref to an out-of-typesystem FS. // add it to the Out-of-typesystem array elements list (APL) if (extId != 0 && outOfTypeSystemData != null) { List<ArrayElement> ootsElements = outOfTypeSystemData.arrayElements.computeIfAbsent(fs, k -> new ArrayList<>()); // the "value" of the reference is the ID, but we prefix with a letter to indicate // that this ID refers to an array OOTS FS ArrayElement ootsElem = new ArrayElement(pos, "a" + Integer.toString(extId)); ootsElements.add(ootsElem); } fs.set(pos, null); } else { fs.set(pos, fsInfo.fs); } }
Example 3
Source File: JsonCasDeserializer.java From termsuite-core with Apache License 2.0 | 6 votes |
private static void fillWords(TermOccAnnotation toa, CAS cas) throws CASException, IOException { FSArray fs = (FSArray) cas.createArrayFS(toa.getPattern().size()); int i = 0; int begin = -1; int end = -1; while(i != toa.getPattern().size()){ if (begin != -1 && token == JsonToken.VALUE_NUMBER_INT){ end = parser.getValueAsInt(); } else if (token == JsonToken.VALUE_NUMBER_INT){ begin = parser.getValueAsInt(); } else if (end != -1){ List<WordAnnotation> wa = JCasUtil.selectCovered(cas.getJCas(),WordAnnotation.class,begin,end); fs.set(i,wa.get(0)); begin = -1; end = -1; i++; } token = parser.nextToken(); } toa.setWords(fs); }
Example 4
Source File: UimaTypesUtilsTest.java From baleen with Apache License 2.0 | 6 votes |
@Test public void testToList() { assertTrue(UimaTypesUtils.toList((StringArray) null).isEmpty()); assertTrue(UimaTypesUtils.toList((FSArray) null).isEmpty()); // Empty list FSArray array = new FSArray(jCas, 2); assertEquals(2, UimaTypesUtils.toList(array).size()); // Populate array.set(0, new Entity(jCas)); array.set(1, new Entity(jCas)); List<Entity> list = UimaTypesUtils.toList(array); assertEquals(2, list.size()); assertSame(array.get(0), list.get(0)); assertSame(array.get(0), list.get(0)); }
Example 5
Source File: PatternExtractor.java From baleen with Apache License 2.0 | 6 votes |
/** * Output pattern (save to the jCas) * * @param jCas the j cas * @param pattern the pattern */ private void outputPattern(final JCas jCas, final PatternExtract pattern) { final Pattern a = new Pattern(jCas); a.setBegin(pattern.getStart()); a.setEnd(pattern.getEnd()); a.setSource(pattern.getFrom()); a.setTarget(pattern.getTo()); final List<WordToken> tokens = pattern.getWordTokens(); final FSArray array = new FSArray(jCas, tokens.size()); int i = 0; for (final WordToken w : tokens) { array.set(i, w); i++; } a.setWords(array); addToJCasIndex(a); }
Example 6
Source File: UimaTypesUtils.java From baleen with Apache License 2.0 | 5 votes |
/** * Convert a collection (of annotation) to an FSArray * * @param jCas the jcas * @param collection the collection * @return the FS array */ public static FSArray toFSArray(JCas jCas, Collection<? extends FeatureStructure> collection) { if (collection == null || collection.isEmpty()) { return new FSArray(jCas, 0); } else { FSArray array = new FSArray(jCas, collection.size()); int i = 0; for (FeatureStructure fs : collection) { array.set(i, fs); i++; } return array; } }
Example 7
Source File: UimaTypesUtils.java From baleen with Apache License 2.0 | 5 votes |
/** * Convert an array of feature structures, to a FSArray * * @param jCas the jcas * @param fses the fses * @return the FS array */ public static FSArray toFSArray(JCas jCas, FeatureStructure... fses) { if (fses.length == 0) { return new FSArray(jCas, 0); } else { FSArray array = new FSArray(jCas, fses.length); int i = 0; for (FeatureStructure fs : fses) { array.set(i, fs); i++; } return array; } }
Example 8
Source File: WordNetLemmatizer.java From baleen with Apache License 2.0 | 5 votes |
private void copyExistingLemmas(final WordToken t, FSArray fsArray) { int i = 0; for (FeatureStructure fs : t.getLemmas().toArray()) { fsArray.set(i, fs); i++; } }
Example 9
Source File: RegexSpotter.java From termsuite-core with Apache License 2.0 | 5 votes |
private void addOccurrenceToCas(JCas jCas, RegexOccurrence occurrence) { TermOccAnnotation annotation = (TermOccAnnotation) jCas .getCas().createAnnotation( jCas.getCasType(TermOccAnnotation.type), occurrence.getBegin(), occurrence.getEnd()); StringArray patternFeature = new StringArray(jCas, occurrence.size()); FSArray innerWords = new FSArray(jCas, occurrence.size()); StringBuilder termLemma = new StringBuilder(); int i = 0; for (LabelledAnnotation la:occurrence.getLabelledAnnotations()) { patternFeature.set(i, la.getLabel()); WordAnnotation word = (WordAnnotation) la.getAnnotation(); termLemma.append(word.getLemma()); if(i<occurrence.size()-1) termLemma.append(TermSuiteConstants.WHITESPACE); WordAnnotation wordAnno = (WordAnnotation) la.getAnnotation(); if(wordAnno.getRegexLabel() != null) { if(!wordAnno.getRegexLabel().equals(la.getLabel())) { LOGGER.warn("Another label has already been set for WordAnnotation "+wordAnno.getCoveredText()+":"+wordAnno.getRegexLabel()+" ["+wordAnno.getBegin()+","+wordAnno.getEnd()+"]. Ignoring the new label "+la.getLabel()+" (rule: "+occurrence.getRule().getName()+")"); } } else wordAnno.setRegexLabel(la.getLabel()); innerWords.set(i, wordAnno); i++; } annotation.setWords(innerWords); annotation.setPattern(patternFeature); annotation.setSpottingRuleName(occurrence.getRule().getName()); annotation.setTermKey(TermSuiteUtils.getGroupingKey(annotation)); annotation.addToIndexes(); }
Example 10
Source File: EnsureTokensHaveLemmaAndPOS.java From bluima with Apache License 2.0 | 5 votes |
/** Convenience method to set POS tag */ public static void setPosTags(Token token, JCas jcas, String... posTags) { FSArray slots = new FSArray(jcas, posTags.length); for (int i = 0; i < posTags.length; i++) { POSTag posTag = new POSTag(jcas); posTag.setValue(posTags[i]); posTag.addToIndexes(); slots.set(i, posTag); } token.setPosTag(slots); }
Example 11
Source File: NeuronIndexer2Test.java From bluima with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { // INDEXING String indexName = "test_index" + System.currentTimeMillis(); String clusterName = "elasticsearch_neuroner_dev"; JCas jCas = getTestCas("many layer V prefrontal cortical pyramidal neurons"); Header header = createAnnot(jCas, Header.class, 0, 0); header.setDocId("17"); header.setCopyright("1976-01-16"); FSArray slots = new FSArray(jCas, 2); AuthorInfo ai = new AuthorInfo(jCas); ai.setForeName("fn1"); ai.setLastName("ln1"); slots.set(0, ai); AuthorInfo ai2 = new AuthorInfo(jCas); ai2.setForeName("fn2"); ai2.setLastName("ln2"); slots.set(1, ai2); header.setAuthors(slots); createAnnot(jCas, Layer.class, 5, 12, "layer V"); createAnnot(jCas, BrainRegionProp.class, 13, 32, "prefrontal cortical"); createAnnot(jCas, Morphology.class, 33, 42, "pyramidal").setOntologyId( "testOntoId"); createAnnot(jCas, NeuronTrigger.class, 43, 50, "neurons"); createAnnot(jCas, Neuron.class, 5, 50, "layer V prefrontal cortical pyramidal neurons"); JcasPipelineBuilder builder = new JcasPipelineBuilder(jCas); builder.add(NaiveSentenceSplitterAnnotator.class); builder.add(NeuronIndexer2.class, PARAM_INDEX_NAME, indexName, PARAM_CLUSTER_NAME, clusterName); builder.process(true); }
Example 12
Source File: JCasUtilTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testSelectOnArrays() throws Exception { String text = "Rot wood cheeses dew?"; tokenBuilder.buildTokens(jCas, text); Collection<TOP> allFS = select(jCas, TOP.class); FSArray allFSArray = new FSArray(jCas, allFS.size()); int i = 0; for (FeatureStructure fs : allFS) { allFSArray.set(i, fs); i++; } // Print what is expected // for (FeatureStructure fs : allFS) { // System.out.println("Type: " + fs.getType().getName() + "]"); // } // System.out.println("Tokens: [" + toText(select(jCas, Token.class)) + "]"); // Document Annotation, one sentence and 4 tokens. assertEquals(6, allFS.size()); assertEquals(toText(select(jCas, Token.class)), toText(select(allFSArray, Token.class))); assertEquals(toText((Iterable) select(jCas, Token.class)), toText((Iterable) select(allFSArray, Token.class))); }
Example 13
Source File: DocumentAnnotationTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testToString() throws InvalidXMLException, IOException, ResourceInitializationException, CASException { File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem_docmetadata.xml"); TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile)); source = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null); jcas = source.getJCas(); DocMeta d = new DocMeta(jcas); d.setFeat("a string"); d.setFeat2("b string"); d.setFeat3("c string"); FSArray fsa = new FSArray(jcas, 2); fsa.set(0, new Annotation(jcas, 1,2)); fsa.set(1, new Annotation(jcas, 3,4)); d.setArrayFs(fsa); IntegerArray intarr = new IntegerArray(jcas, 2); intarr.set(0, 10); intarr.set(1, -10); d.setArrayints(intarr); StringArray strarr = new StringArray(jcas, 2); strarr.set(0, "first"); strarr.set(1, "second"); d.setArraystr(strarr); System.out.println(d.toString()); }
Example 14
Source File: XmiCasDeserializer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Update existing array. The size has already been checked to be equal, but could be 0 * @param arrayType * @param values * @param existingArray */ private void updateExistingArray(List<String> values, CommonArrayFS existingArray) { final int sz = values.size(); if (existingArray instanceof FSArray) { final FSArray fsArray = (FSArray) existingArray; for (int i = 0; i < sz; i++) { String featVal = values.get(i); if (emptyVal(featVal)) { // can be empty if JSON fsArray.set(i, null); } else { maybeSetFsArrayElement(values, i, fsArray); final int xmiId = Integer.parseInt(featVal); final int pos = i; TOP tgtFs = maybeGetFsForXmiId(xmiId); if (null == tgtFs) { fixupToDos.add( () -> finalizeFSArrayRefValue(xmiId, fsArray, pos)); } else { fsArray.set(i, tgtFs); } } } return; } CommonPrimitiveArray existingPrimitiveArray = (CommonPrimitiveArray) existingArray; for (int i = 0; i < sz; i++) { existingPrimitiveArray.setArrayValueFromString(i, values.get(i)); } }
Example 15
Source File: XmiCasDeserializer.java From uima-uimaj with Apache License 2.0 | 5 votes |
private void maybeSetFsArrayElement(List<String> values, int i, FSArray fsArray) { String featVal = values.get(i); if (emptyVal(featVal)) { // can be empty if JSON fsArray.set(i, null); } else { final int xmiId = Integer.parseInt(featVal); final int pos = i; TOP tgtFs = maybeGetFsForXmiId(xmiId); if (null == tgtFs) { fixupToDos.add( () -> finalizeFSArrayRefValue(xmiId, fsArray, pos)); } else { fsArray.set(i, tgtFs); } } }
Example 16
Source File: JsonCasSerializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void arrayOrListRefstst(boolean tstArray) throws Exception { // using dynamic embedding // an element is multiply-referenced if it is both in the index (referenced by the "view") and is referenced // by an FSRef in a feature or a slot in an FSArray jcas.reset(); // make root FS that is indexed and has a ref RefTypes root = new RefTypes(jcas); root.addToIndexes(); // Test list or array with 1 non-embeddable RefTypes refa1 = new RefTypes(jcas); RefTypes refa2 = new RefTypes(jcas); RefTypes refa3 = new RefTypes(jcas); FSArray a = new FSArray(jcas, 3); a.set(0, refa1); a.set(1, refa2); a.set(2, refa3); NonEmptyFSList l0 = new NonEmptyFSList(jcas); NonEmptyFSList l1 = new NonEmptyFSList(jcas); NonEmptyFSList l2 = new NonEmptyFSList(jcas); EmptyFSList tailEnd = new EmptyFSList(jcas); l0.setTail(l1); l1.setTail(l2);; l2.setTail(tailEnd); l0.setHead(refa1); l1.setHead(refa2); l2.setHead(refa3);; if (tstArray) { root.setAArrayFS(a); // is not (yet) multiply referenced } else { root.setAListFs(l0); } String sfx = (tstArray) ? "a" : "l"; // all embeddable: // because ref1,2,3 are not index, and FSArray isn't either serializeAndCompare("array-all-embeddable-" + sfx + ".txt"); // 1 not embeddable, at all 3 positions refa1.addToIndexes(); // ref1 is multiply indexed serializeAndCompare("array-a1-not-" + sfx + ".txt"); refa1.removeFromIndexes(); refa2.addToIndexes(); serializeAndCompare("array-a2-not-" + sfx + ".txt"); refa2.removeFromIndexes(); refa3.addToIndexes(); serializeAndCompare("array-a3-not-" + sfx + ".txt"); // 3 not embeddable: refa1.addToIndexes(); refa2.addToIndexes(); serializeAndCompare("array-non-embeddable-" + sfx + ".txt"); // FSArray not embeddable if (tstArray) { a.addToIndexes(); } else { l0.addToIndexes(); } serializeAndCompare("array-self-non-embeddable-" + sfx + ".txt"); // all embeddable, FSArray not refa1.removeFromIndexes(); refa2.removeFromIndexes(); refa3.removeFromIndexes(); serializeAndCompare("array-self-items-all-embeddable-" + sfx + ".txt"); }
Example 17
Source File: FeatureStructureTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * This test tests V2 backwards compatibility * The goal is to match what V2 did for low level cas access * The area this is testing is the use of the LL int operations to change the type of an existing feature structure. */ public void testLLsetType() { LowLevelCAS llc = cas.getLowLevelCAS(); FSArray fsa = new FSArray(ts.getType(CAS.TYPE_NAME_FS_ARRAY), cas, 3); fsa.addToIndexes(); // otherwise won't be replaced later NonEmptyFSList fsl = new NonEmptyFSList(ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST), cas); fsl.addToIndexes(); // otherwise won't be replaced later Annotation token = this.cas.createFS(tokenType); cas.setId2FSsMaybeUnconditionally(token); // set up some refs; these must be updated if the type changes in a way to require a new FS fsa.set(0, token); // set the 0th element of a FS Array to point to the "token" fsl.setHead(token); // set the head element of a FS List to point to the "token" int tokId = token._id(); // set some feature values; some of these are copied (if there's room, etc.) TOP ttfv = cas.createFS(tokenTypeType); token.setFeatureValue(tokenTypeFeat, ttfv); token.setFloatValue(tokenFloatFeat, 1.1f); assertEquals(1.1f, token.getFloatValue(tokenFloatFeat)); token.setDoubleValue(tokenDoubleFeat, 1.7d); assertEquals(1.7d, token.getDoubleValue(tokenDoubleFeat)); token.setBegin(3); token.setEnd(5); Sofa sofa = (Sofa) token.getSofa(); assertTrue(sofa != null); assertTrue(fsa.get(0) == token); assertTrue(fsl.getHead() == token); // change the type to just Annotation // because this is a supertype, it should not create a new FS llc.ll_setIntValue(tokId, 0, TypeSystemConstants.annotTypeCode); Annotation fs = cas.getFsFromId(tokId); assertTrue(fs == token); assertTrue(fs._id() == token._id()); assertEquals(ts.annotType, fs._getTypeImpl()); assertEquals(fs.getBegin(), 3); assertEquals(fs.getEnd(), 5); assertEquals(sofa, fs.getSofa()); assertTrue(fsa.get(0) == fs); assertTrue(fsl.getHead() == fs); // Change Annotation back to Token type llc.ll_setIntValue(tokId, 0, tokenType.getCode()); token = cas.getFsFromId(tokId); assertTrue(fs == token); assertTrue(fs._id() == token._id()); assertEquals(fs.getBegin(), 3); assertEquals(fs.getEnd(), 5); assertEquals(sofa, fs.getSofa()); assertEquals(1.1f, token.getFloatValue(tokenFloatFeat)); assertEquals(ttfv, token.getFeatureValue(tokenTypeFeat)); assertTrue(fsa.get(0) == token); assertTrue(fsl.getHead() == token); // change type where the type forces a copy // token -> token_type_type // These types are completely orthogonal, one doesn't subsume the other llc.ll_setIntValue(tokId, 0, tokenTypeType.getCode()); TOP ttt = cas.getFsFromId(tokId); assertTrue(ttt != token); assertTrue(ttt._id() == tokId); assertEquals(ttt._getTypeImpl(), tokenTypeType); assertTrue(fsa.get(0) == ttt); assertTrue(fsl.getHead() == ttt); llc.ll_setIntValue(tokId, 0, tokenType.getCode()); token = cas.getFsFromId(tokId); assertTrue(ttt != token); assertTrue(ttt._id() == token._id()); assertEquals(token.getBegin(), 0); assertEquals(token.getEnd(), 0); assertEquals(sofa, token.getSofa()); assertEquals(0.0f, token.getFloatValue(tokenFloatFeat)); assertEquals(null, token.getFeatureValue(tokenTypeFeat)); assertTrue(fsa.get(0) == token); assertTrue(fsl.getHead() == token); }
Example 18
Source File: CASImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
@Override public void ll_setRefArrayValue(int fsRef, int position, int value) { FSArray array = getFsFromId_checked(fsRef); array.set(position, getFsFromId_checked(value)); // that set operation does required journaling }
Example 19
Source File: JsonCasSerializerTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
private FeatureStructure setAllValues(int v) throws CASException { cas = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA); // create the default initial view sofa. JCas jcas = cas.getJCas(); boolean s1 = v == 0; boolean s2 = v == 1; FeatureStructure fs = cas.createFS(allTypesType); cas.addFsToIndexes(fs); FeatureStructure fs2 = cas.createFS(allTypesType); fs.setBooleanValue(allTypesType.getFeatureByBaseName("aBoolean"), s1 ? true : false); fs.setByteValue (allTypesType.getFeatureByBaseName("aByte"), s1 ? (byte) -117 : (byte) 0); fs.setShortValue (allTypesType.getFeatureByBaseName("aShort"), s1 ? (short) -112 : (short) 0); fs.setIntValue (allTypesType.getFeatureByBaseName("aInteger"), s1 ? 0 : 1); fs.setLongValue (allTypesType.getFeatureByBaseName("aLong"), s2 ? 4321 : 1234); fs.setFloatValue (allTypesType.getFeatureByBaseName("aFloat"), s1 ? 1.3F : Float.NaN); fs.setDoubleValue (allTypesType.getFeatureByBaseName("aDouble"), s2 ? Float.NEGATIVE_INFINITY : 2.6); fs.setStringValue (allTypesType.getFeatureByBaseName("aString"), "some \"String\""); fs.setFeatureValue(allTypesType.getFeatureByBaseName("aFS"), fs2); FeatureStructure fsAboolean = cas.createBooleanArrayFS(s1 ? 1 : 0); ByteArray fsAbyte = new ByteArray(jcas, s1 ? 2 : 0); if (s1) { fsAbyte.set(0, (byte) 15); fsAbyte.set(1, (byte) 0xee); } FeatureStructure fsAshort = cas.createShortArrayFS(s2 ? 2 : 0); FeatureStructure fsAstring = cas.createStringArrayFS(s1 ? 1 : 0); fsa1 = cas.createFS(allTypesType); fsa2 = cas.createFS(allTypesType); fsa3 = cas.createFS(allTypesType); fsaa = new FSArray(jcas, 3); fsaa.set(0, fsa1); fsaa.set(1, fsa2); fsaa.set(2, fsa3);; FeatureStructure fsMrAboolean = cas.createBooleanArrayFS(1); FeatureStructure fsMrAbyte = cas.createByteArrayFS(2); FeatureStructure fsMrAshort = cas.createShortArrayFS(0); FeatureStructure fsMrAstring = cas.createStringArrayFS(1); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayBoolean"), fsAboolean); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayByte"), fsAbyte); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayShort"), fsAshort); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayString"), fsAstring); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrBoolean"), fsMrAboolean); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrByte"), fsMrAbyte); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrShort"), fsMrAshort); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrString"), fsMrAstring); FeatureStructure fsLinteger0 = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST)); FeatureStructure fsLstring0 = cas.createFS(tsi.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST)); FeatureStructure fsLstring1 = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_STRING_LIST)); fsLstring0.setStringValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST + ":head"), "testStr"); fsLstring0.setFeatureValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST + ":tail"), fsLstring1); FeatureStructure fsLfs0 = cas.createFS(tsi.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST)); FeatureStructure fsLfs1 = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_FS_LIST)); fsLfs0.setFeatureValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_FS_LIST + ":tail"), fsLfs1); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListInteger"), fsLinteger0); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListString"), fsLstring0); fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListFs"), fsLfs0); cas.addFsToIndexes(fs); return fs; }
Example 20
Source File: DeidAwareTermConsumer.java From ctakes-docker with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void consumeTypeIdHits( final JCas jcas, final String codingScheme, final int cTakesSemantic, final CollectionMap<TextSpan, Long, ? extends Collection<Long>> textSpanCuis, final CollectionMap<Long, Concept, ? extends Collection<Concept>> cuiConcepts ) throws AnalysisEngineProcessException { List<IdentifiedAnnotation> toRemove = new ArrayList<>(); // Find the spans associated with de-id strings: String docText = jcas.getDocumentText(); for(String phiString : phiArray){ int searchInd=0; int startInd=0; int endInd; while((startInd = docText.indexOf(phiString, searchInd)) >= 0){ endInd = startInd + phiString.length(); for(IdentifiedAnnotation covered : JCasUtil.selectCovered(jcas, IdentifiedAnnotation.class, startInd, endInd)){ toRemove.add(covered); } searchInd = startInd+1; //System.err.println("Found phi string " + phiString + " at index: " + startInd + " to: " + endInd); } } // Remove all those identified annotations that fall within de-id strings. for(IdentifiedAnnotation annot : toRemove){ annot.removeFromIndexes(); } // Collection of UmlsConcept objects final Collection<UmlsConcept> umlsConceptList = new ArrayList<>(); try { for ( Map.Entry<TextSpan, ? extends Collection<Long>> spanCuis : textSpanCuis ) { umlsConceptList.clear(); for ( Long cuiCode : spanCuis.getValue() ) { umlsConceptList.addAll( createUmlsConcepts( jcas, codingScheme, cTakesSemantic, cuiCode, cuiConcepts ) ); } final FSArray conceptArr = new FSArray( jcas, umlsConceptList.size() ); int arrIdx = 0; for ( UmlsConcept umlsConcept : umlsConceptList ) { conceptArr.set( arrIdx, umlsConcept ); arrIdx++; } final IdentifiedAnnotation annotation = createSemanticAnnotation( jcas, cTakesSemantic ); annotation.setTypeID( cTakesSemantic ); annotation.setBegin( spanCuis.getKey().getStart() ); annotation.setEnd( spanCuis.getKey().getEnd() ); annotation.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP ); annotation.setOntologyConceptArr( conceptArr ); annotation.addToIndexes(); } } catch ( CASRuntimeException crtE ) { // What is really thrown? The jcas "throwFeatMissing" is not a great help throw new AnalysisEngineProcessException( crtE ); } }