Java Code Examples for org.apache.uima.cas.FeatureStructure#getStringValue()

The following examples show how to use org.apache.uima.cas.FeatureStructure#getStringValue() . 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: CASArtifact.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public String put(String key, String value) {
  FeatureStructure check = metadataCas.createFS(metadataType);
  check.setStringValue(keyFeature, key);
  FeatureStructure fs = metadataIndex.find(check);
  String existing = null;
  if (fs != null) {
    existing = fs.getStringValue(valueFeature);
    metadataCas.removeFsFromIndexes(fs);
  } else {
    fs = check;
  }
  fs.setStringValue(valueFeature, value);
  metadataCas.addFsToIndexes(fs);
  return existing;
}
 
Example 2
Source File: WebAnnoCasUtil.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName)
{
    Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName);

    if (feature == null) {
        throw new IllegalArgumentException("Type [" + aFS.getType().getName()
                + "] has no feature called [" + aFeatureName + "]");
    }

    switch (feature.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
        return (T) aFS.getStringValue(feature);
    case CAS.TYPE_NAME_BOOLEAN:
        return (T) (Boolean) aFS.getBooleanValue(feature);
    case CAS.TYPE_NAME_FLOAT:
        return (T) (Float) aFS.getFloatValue(feature);
    case CAS.TYPE_NAME_INTEGER:
        return (T) (Integer) aFS.getIntValue(feature);
    default:
        throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName()
                + "] with type [" + feature.getRange().getName() + "]");
    }
}
 
Example 3
Source File: DiffAdapter_ImplBase.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public List<? extends Position> generateSubPositions(int aCasId, AnnotationFS aFs,
        LinkCompareBehavior aLinkCompareBehavior)
{
    List<Position> subPositions = new ArrayList<>();
    
    for (LinkFeatureDecl decl : linkFeatures) {
        Feature linkFeature = aFs.getType().getFeatureByBaseName(decl.getName());
        ArrayFS array = (ArrayFS) aFs.getFeatureValue(linkFeature);
        if (array == null) {
            continue;
        }
        for (FeatureStructure linkFS : array.toArray()) {
            String role = linkFS.getStringValue(linkFS.getType().getFeatureByBaseName(
                    decl.getRoleFeature()));
            AnnotationFS target = (AnnotationFS) linkFS.getFeatureValue(linkFS.getType()
                    .getFeatureByBaseName(decl.getTargetFeature()));
            Position pos = getPosition(aCasId, aFs, decl.getName(), role, target.getBegin(),
                    target.getEnd(), aLinkCompareBehavior);
            subPositions.add(pos);
        }
    }
    
    return subPositions;
}
 
Example 4
Source File: RunAE.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Entity process complete.
 *
 * @param aCas the a cas
 * @param aStatus the a status
 * @see org.apache.uima.collection.StatusCallbackListener#entityProcessComplete(org.apache.uima.cas.CAS,
 *      org.apache.uima.collection.EntityProcessStatus)
 */
@Override
public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
  if (aStatus.isException()) {
    Iterator iter = aStatus.getExceptions().iterator();
    while (iter.hasNext()) {
      ((Throwable) iter.next()).printStackTrace();
    }
  } else if (genProgressMessages) {
    // retrieve the filename of the input file from the CAS
    // (it was put there by the FileSystemCollectionReader)
    if (!(xcasInput || xmiInput)) {
      Type fileLocType = aCas.getTypeSystem().getType(
              "org.apache.uima.examples.SourceDocumentInformation");
      Feature fileNameFeat = fileLocType.getFeatureByBaseName("uri");
      FSIterator it = aCas.getAnnotationIndex(fileLocType).iterator();
      FeatureStructure fileLoc = it.get();
      File inFile = new File(fileLoc.getStringValue(fileNameFeat));
      System.out.println("Processed Document " + inFile.getName());
    } else {
      System.out.println("doc" + docsProcessed++ + " processed successfully");
    }
  }
}
 
Example 5
Source File: RunAE.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Entity process complete.
 *
 * @param aCas the a cas
 * @param aStatus the a status
 * @see org.apache.uima.collection.StatusCallbackListener#entityProcessComplete(org.apache.uima.cas.CAS,
 *      org.apache.uima.collection.EntityProcessStatus)
 */
public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
  if (aStatus.isException()) {
    Iterator iter = aStatus.getExceptions().iterator();
    while (iter.hasNext()) {
      ((Throwable) iter.next()).printStackTrace();
    }
  } else if (genProgressMessages) {
    // retrieve the filename of the input file from the CAS
    // (it was put there by the FileSystemCollectionReader)
    if (!(xcasInput || xmiInput)) {
      Type fileLocType = aCas.getTypeSystem().getType(
              "org.apache.uima.examples.SourceDocumentInformation");
      Feature fileNameFeat = fileLocType.getFeatureByBaseName("uri");
      FSIterator it = aCas.getAnnotationIndex(fileLocType).iterator();
      FeatureStructure fileLoc = it.get();
      File inFile = new File(fileLoc.getStringValue(fileNameFeat));
      System.out.println("Processed Document " + inFile.getName());
    } else {
      System.out.println("doc" + docsProcessed++ + " processed successfully");
    }
  }
}
 
Example 6
Source File: SubjectObjectFeatureSupport.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<LinkWithRoleModel> wrapFeatureValue(AnnotationFeature aFeature, CAS aCAS,
        Object aValue)
{
    if (aValue instanceof ArrayFS) {
        ArrayFS array = (ArrayFS) aValue;

        Type linkType = aCAS.getTypeSystem().getType(aFeature.getLinkTypeName());
        Feature roleFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeRoleFeatureName());
        Feature targetFeat = linkType
                .getFeatureByBaseName(aFeature.getLinkTypeTargetFeatureName());

        ArrayList<LinkWithRoleModel> links = new ArrayList<>();
        for (FeatureStructure link : array.toArray()) {
            LinkWithRoleModel m = new LinkWithRoleModel();
            m.role = link.getStringValue(roleFeat);
            m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat));
            m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
                .getCoveredText();
            links.add(m);
        }
        
        return links;
    }
    else if (aValue == null ) {
        return new ArrayList<>();
    }
    else {
        throw new IllegalArgumentException(
                "Unable to handle value [" + aValue + "] of type [" + aValue.getClass() + "]");
    }
}
 
Example 7
Source File: CASArtifact.java    From biomedicus with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String get(Object key) {
  if (!(key instanceof String)) {
    return null;
  }
  FeatureStructure check = metadataCas.createFS(metadataType);
  check.setStringValue(keyFeature, (String) key);
  FeatureStructure fs = metadataIndex.find(check);
  return fs.getStringValue(valueFeature);
}
 
Example 8
Source File: SlotFeatureSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<LinkWithRoleModel> wrapFeatureValue(AnnotationFeature aFeature, CAS aCAS,
        Object aValue)
{
    if (aValue instanceof ArrayFS) {
        ArrayFS array = (ArrayFS) aValue;

        Type linkType = aCAS.getTypeSystem().getType(aFeature.getLinkTypeName());
        Feature roleFeat = linkType.getFeatureByBaseName(aFeature
                .getLinkTypeRoleFeatureName());
        Feature targetFeat = linkType.getFeatureByBaseName(aFeature
                .getLinkTypeTargetFeatureName());

        ArrayList<LinkWithRoleModel> links = new ArrayList<>();
        for (FeatureStructure link : array.toArray()) {
            LinkWithRoleModel m = new LinkWithRoleModel();
            m.role = link.getStringValue(roleFeat);
            m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat));
            m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
                    .getCoveredText();
            links.add(m);
        }
        
        return links;
    }
    else if (aValue == null ) {
        return new ArrayList<>();
    }
    else {
        throw new IllegalArgumentException(
                "Unable to handle value [" + aValue + "] of type [" + aValue.getClass() + "]");
    }
}
 
Example 9
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 10
Source File: Primitives.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the primitive value.
 *
 * @param structure the structure
 * @param feature the feature
 * @return the primitive value as object
 */
public static Object getPrimitive(FeatureStructure structure, Feature feature) {
  
  TypeSystem ts = structure.getCAS().getTypeSystem();
  
  Class<?> primitiveClass = getPrimitiveClass(ts, feature);
  
  Object result;

  if (Boolean.class.equals(primitiveClass)) {
    result = structure.getBooleanValue(feature);
  } else if (Byte.class.equals(primitiveClass)) {
    result = structure.getByteValue(feature);
  } else if (Short.class.equals(primitiveClass)) {
    result = structure.getShortValue(feature);
  } else if (Integer.class.equals(primitiveClass)) {
    result = structure.getIntValue(feature);
  } else if (Long.class.equals(primitiveClass)) {
    result = structure.getLongValue(feature);
  } else if (Float.class.equals(primitiveClass)) {
    result = structure.getFloatValue(feature);
  } else if (Double.class.equals(primitiveClass)) {
    result = structure.getDoubleValue(feature);
  } else if (String.class.equals(primitiveClass)) {
    result = structure.getStringValue(feature);
    
    if (result == null)
      result = "";
  } else {
    throw new IllegalStateException("Unexpected type: " 
        + feature.getRange().getName());
  }

  return result;
}
 
Example 11
Source File: CPMUtils.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a value associated with a given feature.
 *
 * @param aCas -
 *          Cas containing data to extract
 * @param aFeature -
 *          feature to locate in the CAS
 * @param aName -
 *          name of the feature
 * @return - value as String
 * @throws Exception the exception
 */
public static String getFeatureAsString(CAS aCas, Feature aFeature, String aName)
        throws Exception {
  Feature seqNo2 = aFeature.getRange().getFeatureByBaseName(aName);
  FeatureStructure documentMetaData = aCas.getView(CAS.NAME_DEFAULT_SOFA).getDocumentAnnotation()
          .getFeatureValue(aFeature);
  return documentMetaData.getStringValue(seqNo2);

}