Java Code Examples for org.apache.uima.cas.ArrayFS#get()

The following examples show how to use org.apache.uima.cas.ArrayFS#get() . 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: ArrayValue.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {

  if (FeatureStructure.class.equals(adapter)) {
    if (arrayFS instanceof ArrayFS) {
      ArrayFS array = (ArrayFS) arrayFS;

      return array.get(slot());
    }
  }

  if (AnnotationFS.class.equals(adapter)) {
    FeatureStructure fs = (FeatureStructure) getAdapter(FeatureStructure.class);

    if (fs instanceof AnnotationFS) {
      return fs;
    }
  }

  return null;
}
 
Example 2
Source File: EditViewPage.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean updateSelection(IStructuredSelection selection) {

  boolean result = false;

  if (selection.size() == 1) {
    if (selection.getFirstElement() instanceof FeatureValue) {
      FeatureValue featureValue = (FeatureValue) selection.getFirstElement();

      result = !featureValue.getFeature().getRange().isPrimitive() &&
          featureValue.getFeatureStructure().getFeatureValue(featureValue.getFeature()) != null;
    }
    else if (selection.getFirstElement() instanceof ArrayValue) {
      ArrayValue arrayValue = (ArrayValue) selection.getFirstElement();

        if (arrayValue.getFeatureStructure() instanceof ArrayFS) {
          ArrayFS array = (ArrayFS) arrayValue.getFeatureStructure();

          result = array.get(arrayValue.slot()) != null;
        }
    }
  }

  return result;

}
 
Example 3
Source File: FsCopiers.java    From biomedicus with Apache License 2.0 5 votes vote down vote up
/**
 * Copies one array of fs references to another.
 *
 * @param from the array to copy from
 * @param to the array to copy to
 */
private void copyFsArray(FeatureStructure from, FeatureStructure to) {
  ArrayFS sourceFses = (ArrayFS) from;
  ArrayFS targetFses = (ArrayFS) to;
  for (int index = 0; index < sourceFses.size(); index++) {
    FeatureStructure arrayMember = sourceFses.get(index);
    FeatureStructure toFs = featureStructureEncounteredCallback.apply(arrayMember);
    targetFses.set(index, toFs);
  }
}
 
Example 4
Source File: AgreementUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static Object extractLinkFeatureValueForAgreement(FeatureStructure aFs, String aFeature,
        int aLinkIndex, LinkCompareBehavior aLCB)
{
    ArrayFS links = (ArrayFS) aFs.getFeatureValue(aFs.getType().getFeatureByBaseName(
            aFeature));
    FeatureStructure link = links.get(aLinkIndex);
    
    switch (aLCB) {
    case LINK_TARGET_AS_LABEL:
        // FIXME The target feature name should be obtained from the feature
        // definition!
        AnnotationFS target = (AnnotationFS) link.getFeatureValue(link.getType()
                .getFeatureByBaseName("target"));
        
        return target.getBegin() + "-" + target.getEnd() + " ["
                + target.getCoveredText() + "]";
    case LINK_ROLE_AS_LABEL:
        // FIXME The role feature name should be obtained from the feature
        // definition!
        String role = link.getStringValue(link.getType().getFeatureByBaseName(
                "role"));
        
        return role;
    default:
        throw new IllegalStateException("Unknown link target comparison mode ["
                + aLCB + "]");
    }        
}
 
Example 5
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch all annotations of the given type or its sub-types from the given FS array.
 * 
 * @param aArray
 *          the FS array
 * @param aType
 *          the CAS type.
 * @return a new collection of all feature structures of the given type.
 */
public static <T extends FeatureStructure> List<T> create(ArrayFS<T> aArray, Type aType) {
  TypeSystem ts = aArray.getCAS().getTypeSystem();
  List<FeatureStructure> data = new ArrayList<FeatureStructure>(aArray.size());
  for (int i = 0; i < aArray.size(); i++) {
    FeatureStructure value = aArray.get(i);
    if (value != null && (aType == null || ts.subsumes(aType, value.getType()))) {
      data.add(value);
    }
  }
  return (List<T>) asList(data.toArray(new FeatureStructure[data.size()]));
}
 
Example 6
Source File: EditViewPage.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean updateSelection(IStructuredSelection selection) {

  boolean result = false;

  if (selection.size() == 1) {
    if (selection.getFirstElement() instanceof FeatureValue) {
      FeatureValue featureValue = (FeatureValue) selection.getFirstElement();

      result = !featureValue.getFeature().getRange().isPrimitive() &&
          featureValue.getFeatureStructure().getFeatureValue(featureValue.getFeature()) == null;
    }
    else if (selection.getFirstElement() instanceof ArrayValue) {
      ArrayValue value = (ArrayValue) selection.getFirstElement();

      if (value.getFeatureStructure() instanceof ArrayFS) {
        ArrayFS array = (ArrayFS) value.getFeatureStructure();

        if (array.get(value.slot()) == null) {
          result = true;
        }
      }
    }
  }

  return result;
}