Package org.apache.uima.cas

Examples of org.apache.uima.cas.Feature


  }
 
  public static Feature getOptionalFeature(Type type, String featureName, String rangeType)
    throws AnalysisEngineProcessException{

    Feature feature = type.getFeatureByBaseName(featureName);
   
    checkFeatureType(feature, rangeType);
   
    return feature;
  }
View Full Code Here


                "org.apache.uima.examples.SourceDocumentInformation");
        if (srcDocInfoType != null) {
          FSIterator it = aCas.getIndexRepository().getAllIndexedFS(srcDocInfoType);
          if (it.hasNext()) {
            FeatureStructure srcDocInfoFs = it.get();
            Feature uriFeat = srcDocInfoType.getFeatureByBaseName("uri");
            Feature offsetInSourceFeat = srcDocInfoType.getFeatureByBaseName("offsetInSource");
            String uri = srcDocInfoFs.getStringValue(uriFeat);
            int offsetInSource = srcDocInfoFs.getIntValue(offsetInSourceFeat);
            File inFile;
            try {
              inFile = new File(new URL(uri).getPath());
View Full Code Here

      // type system
      CAS cas = ae.newCAS();
      TypeSystem ts = cas.getTypeSystem();
      Type t1 = ts.getType("Type1");
      Assert.assertEquals("Type1", t1.getName());
      Feature f1 = t1.getFeatureByBaseName("Feature1");
      Feature f1a = ts.getFeatureByFullName("Type1:Feature1");
      Assert.assertEquals(f1, f1a);
      Assert.assertEquals("Feature1", f1.getShortName());
      Assert.assertEquals(t1, f1.getDomain());

      Type t2 = ts.getType("Type2");
      Assert.assertEquals("Type2", t2.getName());
      Feature f2 = t2.getFeatureByBaseName("Feature2");
      Feature f2a = ts.getFeatureByFullName("Type2:Feature2");
      Assert.assertEquals(f2, f2a);
      Assert.assertEquals("Feature2", f2.getShortName());
      Assert.assertEquals(t2, f2.getDomain());

      Type et = ts.getType("EnumType");
View Full Code Here

                              .getFile("TextAnalysisEngineImplTest/NewlineResegmenter.xml")));
      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(segmenterDesc);
      CAS inputCas1 = ae.newCAS();
      Type sdiType = inputCas1.getTypeSystem().getType(
              "org.apache.uima.examples.SourceDocumentInformation");
      Feature uriFeat = sdiType.getFeatureByBaseName("uri");
      inputCas1.setDocumentText("This is");
      FeatureStructure sdiFS = inputCas1.createFS(sdiType);
      sdiFS.setStringValue(uriFeat, "cas1");
      inputCas1.getIndexRepository().addFS(sdiFS);
      CAS inputCas2 = ae.newCAS();
View Full Code Here

  private void copyFeatures(AnnotationFS oldFS, FeatureStructure newFS, CAS cas) {
    List<?> features = oldFS.getType().getFeatures();
    Type newType = newFS.getType();
    for (Object object : features) {
      Feature feature = (Feature) object;
      String shortName = feature.getShortName();
      Feature newFeature = newType.getFeatureByBaseName(shortName);
      if (newFeature != null) {
        if (feature.getRange().isPrimitive()) {
          String value = oldFS.getFeatureValueAsString(newFeature);
          newFS.setFeatureValueFromString(newFeature, value);
        } else {
View Full Code Here

    for (AnnotationFS each : annotations) {
      stream.getCas().removeFsFromIndexes(each);
    }
    Collection<AnnotationFS> featureAnnotations = expr.getFeatureAnnotations(annotations, stream,
            element.getParent(), false);
    Feature feature = expr.getFeature(element.getParent());
    IRutaExpression arg = expr.getArg();
    for (AnnotationFS each : featureAnnotations) {
      setFeatureValue(each, feature, arg, element, stream);
    }
    for (AnnotationFS each : annotations) {
View Full Code Here

  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
    RutaBlock parent = element.getParent();
    String featureString = featureStringExpression.getStringValue(parent, match, element, stream);
    List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOf(element);
    for (AnnotationFS annotationFS : matchedAnnotations) {
      Feature feature = annotationFS.getType().getFeatureByBaseName(featureString);
      if (feature != null) {
        Type range = feature.getRange();
        String rangeName = range.getName();
        stream.getCas().removeFsFromIndexes(annotationFS);
        if (rangeName.equals(UIMAConstants.TYPE_STRING) && expr instanceof IStringExpression) {
          IStringExpression stringExpr = (IStringExpression) expr;
          String string = stringExpr.getStringValue(parent, match, element, stream);
          annotationFS.setStringValue(feature, string);
        } else if (rangeName.equals(UIMAConstants.TYPE_INTEGER)
                && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          int v = numberExpr.getIntegerValue(parent, match, element, stream);
          annotationFS.setIntValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_DOUBLE) && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          double v = numberExpr.getDoubleValue(parent, match, element, stream);
          annotationFS.setDoubleValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_FLOAT) && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          float v = (float) numberExpr.getFloatValue(parent, match, element, stream);
          annotationFS.setFloatValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_BYTE) && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          byte v = (byte) numberExpr.getIntegerValue(parent, match, element, stream);
          annotationFS.setByteValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_SHORT) && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          short v = (short) numberExpr.getIntegerValue(parent, match, element, stream);
          annotationFS.setShortValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_LONG) && expr instanceof INumberExpression) {
          INumberExpression numberExpr = (INumberExpression) expr;
          long v = numberExpr.getIntegerValue(parent, match, element, stream);
          annotationFS.setLongValue(feature, v);
        } else if (rangeName.equals(UIMAConstants.TYPE_BOOLEAN)
                && expr instanceof IBooleanExpression) {
          IBooleanExpression booleanExpr = (IBooleanExpression) expr;
          boolean v = booleanExpr.getBooleanValue(parent, match, element, stream);
          annotationFS.setBooleanValue(feature, v);
        } else if (expr instanceof TypeExpression) {
          TypeExpression typeExpr = (TypeExpression) expr;
          Type t = typeExpr.getType(parent);
          List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(annotationFS, t);
          if (feature.getRange().isArray()) {
            annotationFS.setFeatureValue(feature, UIMAUtils.toFSArray(stream.getJCas(), inWindow));
          } else {
            AnnotationFS annotation = inWindow.get(0);
            annotationFS.setFeatureValue(feature, annotation);
          }
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.apache.uima.jcas.JCas#getRequiredFeature(org.apache.uima.cas.Type, java.lang.String)
   */
  public Feature getRequiredFeature(Type t, String s) throws CASException {
    Feature f = t.getFeatureByBaseName(s);
    if (null == f) {
      CASException casEx = new CASException(CASException.JCAS_FEATURENOTFOUND_ERROR, new String[] {
          t.getName(), s });
      throw casEx;
    }
View Full Code Here

   * @see org.apache.uima.jcas.JCas#getRequiredFeatureDE(org.apache.uima.cas.Type, java.lang.String,
   *      java.lang.String, boolean)
   */

  public Feature getRequiredFeatureDE(Type t, String s, String rangeName, boolean featOkTst) {
    Feature f = t.getFeatureByBaseName(s);
    Type rangeType = this.getTypeSystem().getType(rangeName);
    if (null == f && !featOkTst) {
      CASException casEx = new CASException(CASException.JCAS_FEATURENOTFOUND_ERROR, new String[] {
          t.getName(), s });
      sharedView.errorSet.add(casEx);
    }
    if (null != f)
      try {
        casImpl.checkTypingConditions(t, rangeType, f);
      } catch (LowLevelException e) {
        CASException casEx = new CASException(CASException.JCAS_FEATURE_WRONG_TYPE, new String[] {
            t.getName(), s, rangeName, f.getRange().toString() });
        sharedView.errorSet.add(casEx);
      }
    return f;
  }
View Full Code Here

    Assert.assertEquals(fs1.getType().getName(), fs2.getType().getName());

    List<Feature> features1 = fs1.getType().getFeatures();
    List<Feature> features2 = fs2.getType().getFeatures();
    for (int i = 0; i < features1.size(); i++) {
      Feature feat1 = features1.get(i);
      Feature feat2 = features2.get(i);
      // System.out.println("Comparing " + feat1.getName());
      Type rangeType1 = feat1.getRange();
      Type rangeType2 = feat2.getRange();
      Assert.assertEquals(rangeType1.getName(), rangeType2.getName());
      // System.out.println("Range type " + rangeType1);
      String rangeTypeName = rangeType1.getName();

      if (fs1.getCAS().getTypeSystem().subsumes(
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.