@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
@Override public int size() { return metadataIndex.size(); } };
public String toString() { if (isIndex) { return "" + fsIndex.size() + " entries"; } return "Expand to show"; }
@Override public int size() { return this.index.size(); }
/** * Return a label identifying the content of the helper. * * @return the label string. */ public String toString() { return indexName + "[" + fsIndex.getType().getName() + ", " + fsIndex.size() + " entries]"; } }
public static <T extends TOP> T getFeatureStructureAtIndex(JCas jCas, Class<T> cls, int index) { try { int type = (Integer) cls.getField("type").get(null); FSIndex fsIndex = jCas.getAnnotationIndex(type); if (index < 0) throw new IllegalArgumentException("index less than zero: index=" + index); if (index >= fsIndex.size()) throw new IllegalArgumentException("index greater than or equal to fsIndex.size(): index=" + index); FSIterator iterator = fsIndex.iterator(); Object obj = null; for (int i = 0; i <= index; i++) { obj = iterator.next(); } return cls.cast(obj); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), iae); } catch (NoSuchFieldException nsfe) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), nsfe); } }
public static <T extends TOP> T getFeatureStructureAtIndex(JCas jCas, Class<T> cls, int index) { try { int type = (Integer) cls.getField("type").get(null); FSIndex fsIndex = jCas.getAnnotationIndex(type); if (index < 0) throw new IllegalArgumentException("index less than zero: index=" + index); if (index >= fsIndex.size()) throw new IllegalArgumentException("index greater than or equal to fsIndex.size(): index=" + index); FSIterator iterator = fsIndex.iterator(); Object obj = null; for (int i = 0; i <= index; i++) { obj = iterator.next(); } return cls.cast(obj); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), iae); } catch (NoSuchFieldException nsfe) { throw new IllegalArgumentException("class passed in caused an exception: class=" + cls.getCanonicalName(), nsfe); } }
/** * This method exists simply as a convenience method for unit testing. It is not very efficient and should not, in * general be used outside the context of unit testing. */ public static <T extends Annotation> T get(JCas jCas, Class<T> cls, int index) { int type; try { type = (Integer) cls.getField("type").get(null); } catch (IllegalAccessException e) { throw new RuntimeException(); } catch (NoSuchFieldException e) { throw new RuntimeException(); } // TODO we should probably iterate from the end rather than // iterating forward from the begining. FSIndex<?> fsIndex = jCas.getAnnotationIndex(type); if (index < 0) index = fsIndex.size() + index; if (index < 0 || index >= fsIndex.size()) return null; FSIterator<?> iterator = fsIndex.iterator(); Object returnValue = iterator.next(); for (int i = 0; i < index; i++) { returnValue = iterator.next(); } return cls.cast(returnValue); }
/** * Creates the type tree. * * @param type the type * @param ts the ts * @param label the label * @param ir the ir * @return the default mutable tree node */ private DefaultMutableTreeNode createTypeTree(org.apache.uima.cas.Type type, TypeSystem ts, String label, FSIndexRepository ir) { int size = ir.getIndex(label, type).size(); TypeTreeNode typeNode = new TypeTreeNode(type, label, size); DefaultMutableTreeNode node = new DefaultMutableTreeNode(typeNode); // UIMA-2565 - Clash btw. cas.Type and Window.Type on JDK 7 // also on method parameter "type" List<org.apache.uima.cas.Type> types = ts.getDirectSubtypes(type); final int max = types.size(); for (int i = 0; i < max; i++) { if (ir.getIndex(label, types.get(i)) == null) { continue; } DefaultMutableTreeNode child = createTypeTree(types.get(i), ts, label, ir); node.add(child); } return node; }
/** * Process the given CAS object. */ public void processCas(CAS cas) { FSIndex<AnnotationFS> sentenceIndex = cas.getAnnotationIndex(mSentenceType); Span[] sentSpans = new Span[sentenceIndex.size()]; int i = 0; for (AnnotationFS sentenceAnnotation : sentenceIndex) { sentSpans[i++] = new Span(sentenceAnnotation.getBegin(), sentenceAnnotation.getEnd()); } // TODO: The line cleaning should be done more carefully sentenceSamples.add(new SentenceSample(cas.getDocumentText().replace('\n', ' '), sentSpans)); }
public void processCas(CAS cas) throws ResourceProcessException { FSIndex categoryIndex = cas.getAnnotationIndex(mCategoryType); if (categoryIndex.size() > 0) { AnnotationFS categoryAnnotation = (AnnotationFS) categoryIndex.iterator().next(); // add to event collection DocumentSample sample = new DocumentSample( categoryAnnotation.getStringValue(mCategoryFeature), cas.getDocumentText()); documentSamples.add(sample); } }
@Override protected void setBestCategory(CAS tcas, String bestCategory) { FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType); AnnotationFS categoryAnnotation; if (categoryIndex.size() > 0) { categoryAnnotation = categoryIndex.iterator().next(); } else { categoryAnnotation = tcas.createAnnotation(mCategoryType, 0, tcas.getDocumentText().length()); tcas.getIndexRepository().addFS(categoryAnnotation); } categoryAnnotation.setStringValue(mCategoryFeature, bestCategory); } }
String label = it.next(); FSIndex index1 = ir.getIndex(label); IndexTreeNode nodeObj = new IndexTreeNode(label, index1.getType(), index1.size()); DefaultMutableTreeNode node = new DefaultMutableTreeNode(nodeObj); root.add(node);
final int size = index.size(); this.rootString = "<html><font color=green>" + indexName + "</font> - <font color=blue>" + index.getType().getName() + "</font> [" + size + "]</html>";
if (idx.size() > 0) { List<SofaChangeAnnotation> edits = new ArrayList<SofaChangeAnnotation>();
iElementCount += (sofaIndex.size()); // one View element per sofa iElementCount += getElementCountForSharedData(); } else {