org.apache.uima.jcas.cas.FSList Java Examples

The following examples show how to use org.apache.uima.jcas.cas.FSList. 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: JCasTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testFSListAPI() {
  FSList<TOP> sl = new EmptyFSList<>(jcas);
  TOP fs1 = new TOP(jcas);
  TOP fs2 = new TOP(jcas);
  sl = sl.push(fs2);
  sl = sl.push(fs1);
 
  TOP[] fss = new TOP[2];
  int i = 0;
  Iterator<TOP> it = sl.iterator();
  while (it.hasNext()) {
    fss[i++] = it.next();
  }
  
  i = 0;   
  for (TOP s : sl) {
    fss[i++] = s;
  }
  
  TOP[] expected = {fs1, fs2};
  assert(Arrays.equals(expected, fss));
}
 
Example #2
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends TOP> List<T> create(FSList<T> aList, Type type) {
  TypeSystem ts = aList.getCAS().getTypeSystem();
  List<FeatureStructure> data = new ArrayList<FeatureStructure>();
  FSList<T> i = aList;
  while (i instanceof NonEmptyFSList) {
    NonEmptyFSList<T> l = (NonEmptyFSList<T>) i;
    TOP value = l.getHead();
    if (value != null && (type == null || ts.subsumes(type, value.getType()))) {
      data.add(l.getHead());
    }
    i = l.getTail();
  }

  return (List<T>) asList(data.toArray(new TOP[data.size()]));
}
 
Example #3
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends TOP> FSList<T> createFSList(CAS aCas, Collection<T> aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  if (aValues.size() == 0) {
    return aCas.emptyFSList();
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  Iterator<? extends FeatureStructure> i = aValues.iterator();
  while (i.hasNext()) {
    head.setFeatureValue(headFeature, i.next());
    if (i.hasNext()) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.emptyFSList());
    }
  }

  return (FSList<T>) list;
}
 
Example #4
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static <T extends TOP> Collection<T> create(FSList<T> aList) {
  return create(aList, (Type) null);
}
 
Example #5
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static <T extends TOP> FSList<T> createFSList(JCas aJCas, Collection<T> aCollection) {
  return createFSList(aJCas.getCas(), aCollection);
}
 
Example #6
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static <T extends TOP> FSList<T> createFSList(CAS aCas, T... aValues) {
  return createFSList(aCas, asList(aValues));
}
 
Example #7
Source File: SelectFSs_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public SelectFSs_impl(FSList source) {
  this(source._casView);
  isAltSource = true;
  sourceFSList = source;
}
 
Example #8
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 2 votes vote down vote up
/**
 * Fetch all annotations of the given type or its sub-types from the given FS list.
 * 
 * @param <T>
 *          the JCas type.
 * @param aList
 *          the FS list
 * @param aType
 *          the JCas wrapper class.
 * @return a new collection of all feature structures of the given type.
 */
public static <T extends TOP> Collection<T> create(FSList<T> aList, Class<? extends T> aType) {
  return create(aList, CasUtil.getType(aList.getCAS(), aType));
}
 
Example #9
Source File: JCasUtil.java    From uima-uimafit with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience method select all feature structure from the given type from a list.
 * 
 * @param <T>
 *          the JCas type.
 * @param list
 *          a feature structure list.
 * @param type
 *          the type.
 * @return A collection of the selected type.
 * @see <a href="package-summary.html#SortOrder">Order of selected feature structures</a>
 */
public static <T extends TOP> List<T> select(final FSList list, final Class<T> type) {
  return cast(FSCollectionFactory.create(list, CasUtil.getType(list.getCAS(), type.getName())));
}
 
Example #10
Source File: CasSerializerSupport.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Enqueues all Head values of FSList reachable from an FSList. 
 * This does NOT include the list nodes themselves.
 * 
 * @param addr
 *          Address of an FSList
 */
private void enqueueFSListElements(FSList<TOP> node) throws SAXException {
  node.walkList_saxException(n -> enqueueFsAndMaybeFeatures(((NonEmptyFSList<TOP>)n).getHead()), null);
}
 
Example #11
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aListFs - gets 
 * @generated
 * @return value of the feature 
 */
public FSList getAListFs() { return (FSList)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aListFs)));}
 
Example #12
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aListFs - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAListFs(FSList v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aListFs), v);
}
 
Example #13
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aListMrFs - gets 
 * @generated
 * @return value of the feature 
 */
public FSList getAListMrFs() { return (FSList)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aListMrFs)));}
 
Example #14
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aListMrFs - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAListMrFs(FSList v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aListMrFs), v);
}
 
Example #15
Source File: RefTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aListFs - gets 
 * @generated
 * @return value of the feature 
 */
public FSList getAListFs() { return (FSList)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aListFs)));}
 
Example #16
Source File: RefTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aListFs - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAListFs(FSList v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aListFs), v);
}