org.apache.uima.cas.FSIterator Java Examples

The following examples show how to use org.apache.uima.cas.FSIterator. 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: AnnotationIteratorTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param ba
 * @param setup
 * @param boundsUse
 * @param flags: TP  type priority
 *               NO  non overlapping
 *               LE  include annotation with ends beyond bounds
 *               ST  skip when same begin end type
 *               
 * @param count
 */
private void edge(Annotation ba, String setup, BoundsUse boundsUse, String flags, int count) {
  String[] fa = flags.split("\\:");
  cas.reset();
  AnnotationIndex<Annotation> ai = cas.getAnnotationIndex();
  FSIterator<Annotation> it;
  SelectFSs<Annotation> sa;
  
  setupEdges(setup);
  
  switch (boundsUse) {
  case notBounded: sa = ai.select(); break;
  case coveredBy:  sa = ai.select().coveredBy(ba); break;
  case sameBeginEnd: sa = ai.select().at(ba); break;
  default:
  case covering:   sa = ai.select().covering(ba); break;
  }   
  if (fa[0].equals("TP")) sa.typePriority();
  if (fa[1].equals("NO")) sa.nonOverlapping();
  if (fa[2].equals("LE")) sa.includeAnnotationsWithEndBeyondBounds();
  if (fa[3].equals("ST")) sa.skipWhenSameBeginEndType();
  
  assertEquals(count, sa.fsIterator().size());
}
 
Example #2
Source File: FsIterator_aggregation_common.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void moveToNextNvc() {
  FSIterator<T> it = nonEmptyIterators[current_it_idx];
  it.moveToNextNvc();

  if (it.isValid()) {
    return;
  }
  
  final int nbrIt = nonEmptyIterators.length;
  for (int i = current_it_idx + 1; i < nbrIt; i++) {
    it = nonEmptyIterators[i];
    it.moveToFirst();
    if (it.isValid()) {
      current_it_idx = i;
      return;
    }
  }
  current_it_idx = -1;  // invalid position
}
 
Example #3
Source File: CasExporter.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
protected String getExportFilePath(JCas cas, String extension) {
	AnnotationIndex<Annotation> index = cas.getAnnotationIndex(SourceDocumentInformation.type);
	FSIterator<Annotation> iterator = index.iterator();
	if (iterator.hasNext()) {
		SourceDocumentInformation annotation = (SourceDocumentInformation) iterator.next();
		File file = new File(annotation.getUri());
		String name = file.getName();
		int i = name.lastIndexOf('.');
		if (i == -1) {
			return name + "." + extension;
		} else {
			return name.substring(0, i) + "." + extension;
		}
	} else {
		return null;
	}
}
 
Example #4
Source File: JCasUtils.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
public static void showSdiWithCategory(JCas jcas) {
	FSIterator<Annotation> it = jcas.getAnnotationIndex(WordAnnotation.type).iterator();
	int wordCnt = 0;
	while(it.hasNext()) {
		wordCnt++;
		WordAnnotation a = (WordAnnotation) it.next();
		System.out.print(a.getCoveredText() + "_" + a.getTag());
		if(wordCnt < 12) {
			System.out.print(" ");
		} else {
			System.out.println();
			wordCnt = 0;
		}
			
	}
	System.out.println(Joiner.on(" ").join(it));
}
 
Example #5
Source File: IndexComparitorTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testSetUsesType() throws Exception {
  cas.reset();
  
  ir.addFS(createFs(type1, 1, 1));
  ir.addFS(createFs(type1Sub1, 1, 1));  // same fs keys, different type
  FeatureStructure testprobe = createFs(type1Sub1, 1, 1);  // not in index, used only for key values
  FeatureStructure testprobe2 = createFs(type1, 1, 1);
  
  assertEquals(2, sortedType1.size());
  assertEquals(2, setType1.size());
  
  FSIterator<FeatureStructure> it = setType1.iterator();
  it.moveTo(testprobe);
  assertEquals("Type1", it.get().getType().getShortName());
  it.moveTo(testprobe2);
  assertEquals("Type1", it.get().getType().getShortName());
  it.moveToFirst();
  assertEquals("Type1", it.next().getType().getShortName());
  assertEquals("Type1Sub1", it.next().getType().getShortName());
  
}
 
Example #6
Source File: CasDoctorUtils.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas)
{
    TypeSystem ts = aCas.getTypeSystem();
    
    LowLevelCAS llcas = aCas.getLowLevelCAS();

    Set<FeatureStructure> allIndexedFS = collectIndexed(aCas);
    Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>(
        Comparator.comparingInt(llcas::ll_getFSRef));
    
    FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS(
            aCas.getTypeSystem().getTopType());

    i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs));

    // Remove all that are not annotations
    allReachableFS.entrySet().removeIf(e -> 
            !ts.subsumes(aCas.getAnnotationType(), e.getKey().getType()));
    
    // Remove all that are indexed
    allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue());

    // All that is left are non-index annotations
    return allReachableFS;
}
 
Example #7
Source File: XmiCasExporter.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
protected String getExportFilePath(JCas cas) {
	AnnotationIndex<Annotation> index = cas.getAnnotationIndex(SourceDocumentInformation.type);
	FSIterator<Annotation> iterator = index.iterator();
	if (iterator.hasNext()) {
		SourceDocumentInformation annotation = (SourceDocumentInformation) iterator.next();
		File file = new File(annotation.getUri());
		String name = file.getName();
		int i = name.lastIndexOf('.');
		if (i == -1) {
			return name + ".xmi";
		} else {
			return name.substring(0, i) + ".xmi";
		}
	} else {
		return null;
	}
}
 
Example #8
Source File: JCasTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testRandom() throws Exception {
	try {
		// System.out.print("Making Random: ");
		for (int i = 0; i < 50; i++) {
			root1.make();
			// System.out.print("m");
		}
		JFSIndexRepository jir = jcas.getJFSIndexRepository();
		FSIterator<Root> it = jir.<Root>getIndex("all", Root.type).iterator();
		// System.out.print("\nTesting Random: ");
		while (it.isValid()) {
			root1.test(it.get());
			// System.out.print("t");
			it.moveToNext();
		}
	} catch (Exception e) {
		JUnitExtension.handleException(e);
	}
}
 
Example #9
Source File: CasUtil.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Get the single instance of the specified type from the CAS.
 * 
 * @param cas
 *          a CAS containing the annotation.
 * @param type
 *          a UIMA type.
 * @return the single instance of the given type. throws IllegalArgumentException if not exactly
 *         one instance if the given type is present.
 */
public static FeatureStructure selectSingleFS(CAS cas, Type type) {
  FSIterator<FeatureStructure> iterator = cas.getIndexRepository().getAllIndexedFS(type);

  if (!iterator.hasNext()) {
    throw new IllegalArgumentException("CAS does not contain any [" + type.getName() + "]");
  }

  FeatureStructure result = iterator.next();

  if (iterator.hasNext()) {
    throw new IllegalArgumentException("CAS contains more than one [" + type.getName() + "]");
  }

  return result;
}
 
Example #10
Source File: AbstractNormalizeEntities.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Override
public void doProcess(JCas jCas) throws AnalysisEngineProcessException {

  FSIterator<Annotation> iter = jCas.getAnnotationIndex(Entity.type).iterator();

  while (iter.hasNext()) {
    Entity e = (Entity) iter.next();

    if (Strings.isNullOrEmpty(e.getValue())) {
      getMonitor().debug("No value set for entity '{}' - skipping", e.getCoveredText());
      continue;
    }

    if (this.shouldNormalize(e)) {
      String normalized = this.normalize(e);
      if (!normalized.equals(e.getValue())) {
        e.setValue(normalized);
        e.setIsNormalised(true);
      }
    }
  }
}
 
Example #11
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
@Override
public int size() {
  // Unfortunately FSIterator does not expose the sizes of its internal collection,
  // neither the current position although FSIteratorAggregate has a private field
  // with that information.
  if (sizeCache == -1) {
    synchronized (this) {
      if (sizeCache == -1) {
        FSIterator<T> clone = index.copy();
        clone.moveToFirst();
        sizeCache = 0;
        while (clone.isValid()) {
          sizeCache++;
          clone.moveToNext();
        }
      }
    }
  }

  return sizeCache;
}
 
Example #12
Source File: SelectFSs_impl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private FSIterator<T> make_or_copy_snapshot(LowLevelIterator<T> baseIterator, boolean bkwd) {
  FSIterator<T> it;
  T[] a = (T[]) asArray(baseIterator, FeatureStructure.class);  // array is in forward order because 
                                        // it's produced by a backwards iterator, but then the array is reversed
  it = new FsIterator_subtypes_snapshot<>(
      a,
      (LowLevelIndex<T>) index,
      IS_ORDERED,
      baseIterator.getComparator());
  
  if (!bkwd) {
    it = new FsIterator_backwards<>(it);
  }

  return (limit == -1)
      ? it
        // rewrap with limit - needs to be outer shell to get right invalid behavior
      : new FsIterator_limited<>(it, limit);
}
 
Example #13
Source File: FSTreeModel.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Update.
 *
 * @param indexName the index name
 * @param index the index
 * @param cas1 the cas 1
 */
public void update(String indexName, FSIndex index, CAS cas1) {
  // this.indexName = indexName;
  this.cas = (CASImpl) cas1;
  final int size = index.size();
  this.rootString = "<html><font color=green>" + indexName + "</font> - <font color=blue>"
          + index.getType().getName() + "</font> [" + size + "]</html>";
  this.root = new FSNode(this, FSNode.DISPLAY_NODE, null, 0, null);
  this.fss = new ArrayList<>();
  FSIterator<TOP> it = index.iterator();
  int count = 0;
  for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
    TOP fs = it.get();
    this.fss.add(new FSNode(this, getNodeType(fs.getType()), fs, fs._id(), count));
    ++count;
  }
  List<FSTreeNode> kids = createArrayChildren(0, size, this.fss, this);
  this.root.setChildren(kids);
  Object[] path = new Object[1];
  path[0] = this.root;
  TreeModelEvent event = new TreeModelEvent(this.root, path);
  for (int i = 0; i < this.treeModelListeners.size(); i++) {
    this.treeModelListeners.get(i).treeStructureChanged(event);
  }
}
 
Example #14
Source File: Dumper.java    From bluima with Apache License 2.0 6 votes vote down vote up
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

    String pmId = getHeaderDocId(jCas);
    System.out.println(pmId + " -----------------------------");
    FSIterator<Annotation> it = jCas.getAnnotationIndex().iterator();
    StringBuffer sb = new StringBuffer();
    while (it.hasNext()) {
        Annotation a = it.next();
        sb.append(a.getCoveredText() + '\n');
        a.prettyPrint(2, 2, sb, false);
        sb.append('\n');

    }
    System.out.println(sb);
}
 
Example #15
Source File: HeidelTimeOpenNLP.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Identify the part of speech (POS) of a MarchResult.
 * 
 * @param tokBegin
 * @param tokEnd
 * @param s
 * @param jcas
 * @return
 */
public String getPosFromMatchResult(int tokBegin, int tokEnd, Sentence s, JCas jcas) {
	// get all tokens in sentence
	HashMap<Integer, Token> hmTokens = new HashMap<Integer, Token>();
	FSIterator iterTok = jcas.getAnnotationIndex(Token.type).subiterator(s);
	while (iterTok.hasNext()) {
		Token token = (Token) iterTok.next();
		hmTokens.put(token.getBegin(), token);
	}
	// get correct token
	String pos = "";
	if (hmTokens.containsKey(tokBegin)) {
		Token tokenToCheck = hmTokens.get(tokBegin);
		pos = tokenToCheck.getPos() == null ? "" : tokenToCheck.getPos();
	}
	return pos;
}
 
Example #16
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<CAS> getViewIterator(String localViewNamePrefix) {
  // do sofa mapping for current component
  String absolutePrefix = null;
  if (getCurrentComponentInfo() != null) {
    absolutePrefix = getCurrentComponentInfo().mapToSofaID(localViewNamePrefix);
  }
  if (absolutePrefix == null) {
    absolutePrefix = localViewNamePrefix;
  }

  // find Sofas with this prefix
  List<CAS> viewList = new ArrayList<>();
  FSIterator<Sofa> sofaIter = getSofaIterator();
  while (sofaIter.hasNext()) {
    SofaFS sofa = sofaIter.next();
    String sofaId = sofa.getSofaID();
    if (sofaId.startsWith(absolutePrefix)) {
      if ((sofaId.length() == absolutePrefix.length())
          || (sofaId.charAt(absolutePrefix.length()) == '.')) {
        viewList.add(getView(sofa));
      }
    }
  }
  return viewList.iterator();
}
 
Example #17
Source File: HeidelTimeOpenNLP.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Postprocessing: Remove invalid timex expressions. These are already marked as
 * invalid: timexValue().equals("REMOVE")
 * 
 * @param jcas
 */
public void removeInvalids(JCas jcas) {

	/*
	 * Iterate over timexes and add invalids to HashSet (invalids cannot be removed
	 * directly since iterator is used)
	 */
	FSIterator iterTimex = jcas.getAnnotationIndex(Timex3.type).iterator();
	HashSet<Timex3> hsTimexToRemove = new HashSet<Timex3>();
	while (iterTimex.hasNext()) {
		Timex3 timex = (Timex3) iterTimex.next();
		if (timex.getTimexValue().equals("REMOVE")) {
			hsTimexToRemove.add(timex);
		}
	}

	// remove invalids, finally
	for (Timex3 timex3 : hsTimexToRemove) {
		timex3.removeFromIndexes();
		this.timex_counter--;
		Logger.printDetail(timex3.getTimexId() + " REMOVING PHASE: " + "found by:" + timex3.getFoundByRule()
		+ " text:" + timex3.getCoveredText() + " value:" + timex3.getTimexValue());
	}
}
 
Example #18
Source File: AnnotationIndexImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void addChildren(AnnotationTreeNodeImpl<T> node, FSIterator<T> it) {
  AnnotationTreeNodeImpl<T> dtr;
  T annot;
  while (it.isValid()) {
    annot = it.get();
    it.moveToNext();
    dtr = new AnnotationTreeNodeImpl<T>();
    dtr.set(annot);
    node.addChild(dtr);
    addChildren(dtr, subiterator(annot, false, true));
  }
}
 
Example #19
Source File: RegExAnnotator.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method that determines which subranges of the document text should be annotated by this
 * annotator. This is done as follows:
 * <ul>
 * <li>If <code>mContainingAnnotationTypes</code> is <code>null</code>, the entire document
 * is eligible for annotation.</li>
 * <li>If <code>mContainingAnnotationTypes</code> is not <code>null</code>, then each of its
 * elements is expected to be an Annotation Type name. The CAS is queried for existing annotations
 * of any of these Types, and the only subranges of the document eligible for annotation are those
 * subranges contained within such annotations.</li>
 * </ul>
 * 
 * @param aCAS
 *          CAS currently being processed
 * 
 * @return an array of integers indicating the document subranges eligible for annotation. Begin
 *         and end positions of the subranges are stored in successive elements of the array. For
 *         example, elements 0 and 1 are the start and end of the first subrange; elements 2 and 3
 *         are the start and end of the second subrange, and so on.
 */
protected int[] getRangesToAnnotate(CAS aCAS) {
  if (mContainingAnnotationTypes == null || mContainingAnnotationTypes.length == 0) {
    // ContainingAnnotationTypes is not set - the whole document is eligible
    return new int[] { 0, aCAS.getDocumentText().length() };
  } else {
    // get iterator over all annotations in the CAS
    FSIterator<AnnotationFS> iterator = aCAS.getAnnotationIndex().iterator();

    // filter the iterator so that only instances of Types in the
    // mContainingAnnotationTypes array are returned
    FSTypeConstraint constraint = aCAS.getConstraintFactory().createTypeConstraint();
    for (int i = 0; i < mContainingAnnotationTypes.length; i++) {
      constraint.add(mContainingAnnotationTypes[i]);
    }
    iterator = aCAS.createFilteredIterator(iterator, constraint);

    // iterate over annotations and add them to an ArrayList
    List<AnnotationFS> annotationList = new ArrayList<>();
    while (iterator.isValid()) {
      annotationList.add(iterator.get());
      iterator.moveToNext();
    }

    // For each Annotation in the list, add its start and end
    // positions to the result array.
    int numRanges = annotationList.size();
    int[] result = new int[numRanges * 2];
    for (int j = 0; j < numRanges; j++) {
      AnnotationFS curFS = (AnnotationFS) annotationList.get(j);
      result[j * 2] = curFS.getBegin();
      result[j * 2 + 1] = curFS.getEnd();
    }
    return result;
  }
}
 
Example #20
Source File: ArrayIndexTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private static final int countIndexMembers(FSIndex<? extends FeatureStructure> idx) {
  FSIterator<? extends FeatureStructure> it = idx.iterator();
  int count = 0;
  for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
    ++count;
  }
  return count;
}
 
Example #21
Source File: ShowAnnotatedTextHandler.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
  String title = this.main.getIndexLabel() + " - " + this.main.getIndex().getType().getName();
  MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
  f.addWindowListener(new CloseAnnotationViewHandler(this.main));
  FSIterator it = this.main.getIndex().iterator();
  final String text = this.main.getCas().getDocumentText();
  System.out.println("Creating extents.");
  AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(), this.main
      .getStyleMap());
  System.out.println("Initializing text frame.");
  f.init(text, extents, this.main.getDimension(MainFrame.annotViewSizePref));
  System.out.println("Done.");
}
 
Example #22
Source File: ConsumerCasUtils.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public static FeatureStructure getTcasFS(CAS aCasView, String aTypeS) {
  org.apache.uima.cas.FeatureStructure idFS = null;
  Type type = aCasView.getTypeSystem().getType(aTypeS);
  if (type != null) {
    FSIterator<AnnotationFS> idIter = aCasView.getAnnotationIndex(type).iterator();
    while (idIter.isValid()) {
      idFS = idIter.get();
      idIter.moveToNext();
    }
  }
  return idFS;
}
 
Example #23
Source File: CasTreeViewer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a tree from a CAS.
 *
 * @param aCAS          CAS from which annotations will be extracted
 * @return the tree node
 * @throws CASException the CAS exception
 */
private TreeNode buildTree(CAS aCAS) throws CASException {
  // get iterator over all annotations
  FSIterator iterator = aCAS.getAnnotationIndex().iterator();

  // create artifical root node encompassing entire document
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("Document");
  // add children to this node
  _buildTree(root, iterator, 0, aCAS.getDocumentText().length());

  return root;
}
 
Example #24
Source File: IteratorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void fastFailTst(FSIndex<FeatureStructure> index, boolean isShouldFail) {
  FSIterator<FeatureStructure> it = index.iterator();
  it.moveToLast();
  it.moveToFirst();
  // moved to first, 2.7.0, because new bag iterator is more forgiving re concurrentmodexception
  FeatureStructure a = it.get();
  
  cas.removeFsFromIndexes(a);
  cas.addFsToIndexes(a);    
  
  expectCCE(a, it, isShouldFail);
  expectCCE(a, it, false);  // ok because above expectCCE reset the iterator   
}
 
Example #25
Source File: SimpleTextSegmenter.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void process(JCas aJCas) throws AnalysisEngineProcessException {
  mDoc = aJCas.getDocumentText();
  mPos = 0;
  // retrieve the filename of the input file from the CAS so that it can be added
  // to each segment
  FSIterator it = aJCas.getAnnotationIndex(SourceDocumentInformation.type).iterator();
  if (it.hasNext()) {
    SourceDocumentInformation fileLoc = (SourceDocumentInformation) it.next();
    mDocUri = fileLoc.getUri();
  } else {
    mDocUri = null;
  }
}
 
Example #26
Source File: CasUtil.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the n annotations following the given annotation
 * 
 * @param cas
 *          a CAS.
 * @param type
 *          a UIMA type.
 * @param annotation
 *          anchor annotation
 * @param count
 *          number of annotations to collect
 * @return List of aType annotations following anchor annotation
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
public static List<AnnotationFS> selectFollowing(CAS cas, Type type, AnnotationFS annotation,
        int count) {
  if (!cas.getTypeSystem().subsumes(cas.getAnnotationType(), type)) {
    throw new IllegalArgumentException("Type [" + type.getName() + "] is not an annotation type");
  }

  // Seek annotation in index
  // withSnapshotIterators() not needed here since we copy the FSes to a list anyway    
  FSIterator<AnnotationFS> itr = cas.getAnnotationIndex(type).iterator();
  itr.moveTo(annotation);

  // When seeking forward, there is no need to check if the insertion point is beyond the
  // index. If it was, there would be nothing beyond it that could be found and returned.
  // The moveTo operation also does not yield an iterator being invalid because it points
  // *before the first* index entry, at max it points *to the first* index entry, so this
  // case also does not need to be handled.

  // No need to do additional seeks here (as done in selectCovered) because the current method
  // does not have to worry about type priorities - it never returns annotations that have
  // the same offset as the reference annotation.

  // make sure we're past the end of the reference annotation
  while (itr.isValid() && itr.get().getBegin() < annotation.getEnd()) {
    itr.moveToNext();
  }

  // add annotations from the iterator into the result list
  List<AnnotationFS> followingAnnotations = new ArrayList<AnnotationFS>();
  for (int i = 0; i < count && itr.isValid(); i++, itr.moveToNext()) {
    followingAnnotations.add(itr.get());
  }
  return followingAnnotations;
}
 
Example #27
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private SofaFS getSofa(String sofaName) {
  FSIterator<Sofa> iterator = this.svd.baseCAS.getSofaIterator();
  while (iterator.hasNext()) {
    SofaFS sofa = iterator.next();
    if (sofaName.equals(sofa.getSofaID())) {
      return sofa;
    }
  }
  throw new CASRuntimeException(CASRuntimeException.SOFANAME_NOT_FOUND, sofaName);
}
 
Example #28
Source File: CasUtil.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Get all annotations of the given type at the specified offsets.
 * 
 * @param aCas
 *          the CAS containing the annotations.
 * @param aType
 *          the type of annotations to fetch.
 * @param aBegin
 *          the begin offset.
 * @param aEnd
 *          the end offset.
 * @return the annotations at the specified offsets.
 */
public static List<AnnotationFS> selectAt(final CAS aCas, final Type aType, int aBegin, int aEnd) {
  List<AnnotationFS> list = new ArrayList<AnnotationFS>();
  
  // withSnapshotIterators() not needed here since we copy the FSes to a list anyway
  FSIterator<AnnotationFS> it = aCas.getAnnotationIndex(aType).iterator();

  // Skip annotations whose start is before the start parameter.
  while (it.isValid() && (it.get()).getBegin() < aBegin) {
    it.moveToNext();
  }

  // Skip annotations whose end is after the end parameter.
  while (it.isValid() && (it.get()).getEnd() > aEnd) {
    it.moveToNext();
  }
  
  while (it.isValid()) {
    AnnotationFS a = it.get();
    // If the offsets do not match the specified offets, we're done
    if (a.getBegin() != aBegin || a.getEnd() != aEnd) {
      break;
    }
    it.moveToNext();
    list.add(a);
  }
  
  return list;
}
 
Example #29
Source File: FsIterator_subtypes_ordered.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public FSIterator<T> copy() {
  FsIterator_subtypes_ordered<T> it = new FsIterator_subtypes_ordered<>(iicp, comparatorMaybeNoTypeWithoutId);
  if (!isValid()) {
    it.moveToPrevious();  // mark new one also invalid
  } else {
    T posFs = getNvc();
    it.moveToNoReinit(posFs);  // moves to left-most position
    while(it.get() != posFs) {
      it.moveToNext();
    }
  }
  return it;
}
 
Example #30
Source File: SelectFSs_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private T getNullChk() {
  FSIterator<T> it = fsIterator();
  if (it.isValid()) {
    return it.getNvc();
  }
  if (!isNullOK) {  // if not specified, isNullOK == false
    throw new CASRuntimeException(CASRuntimeException.SELECT_GET_NO_INSTANCES, ti.getName(), maybeMsgPosition());
  }
  return null;
  
}