Examples of FeatureValue


Examples of hivemall.io.FeatureValue

        features1.add("good");
        features1.add("opinion");
        udtf.update(features1, 1, 0.f);

        /* check weights */
        FeatureValue word1 = FeatureValue.parse(new String("good"));
        assertEquals(1.f, udtf.model.get(word1.getFeature()).get(), 1e-5f);

        FeatureValue word2 = FeatureValue.parse(new String("opinion"));
        assertEquals(1.f, udtf.model.get(word2.getFeature()).get(), 1e-5f);

        /* update weights by List<Object> */
        List<String> features2 = new ArrayList<String>();
        features2.add("bad");
        features2.add("opinion");
        udtf.update(features2, -1, 0.f);

        /* check weights */
        assertEquals(1.f, udtf.model.get(word1.getFeature()).get(), 1e-5f);

        FeatureValue word3 = FeatureValue.parse(new String("bad"));
        assertEquals(-1.f, udtf.model.get(word3.getFeature()).get(), 1e-5f);

        FeatureValue word4 = FeatureValue.parse(new String("opinion"));
        assertEquals(0.f, udtf.model.get(word4.getFeature()).get(), 1e-5f);
    }
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

  public static boolean hasFeature(CasData aCAS, String featureName) {
    Iterator<FeatureStructure> it = aCAS.getFeatureStructures();
    while (it.hasNext()) {
        FeatureStructure fs = it.next();
        FeatureValue fValue = fs.getFeatureValue(featureName);
        if (fValue != null) {
          return true;
        }
    }
    return false;
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

        UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "dumpFeatures",
                LOG_RESOURCE_BUNDLE, "UIMA_cas_feature_structure_type__FINE", fs.getType());

        String[] names = fs.getFeatureNames();
        for (int i = 0; names != null && i < names.length; i++) {
          FeatureValue fValue = fs.getFeatureValue(names[i]);
          if (fValue != null) {
            UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(),
                    "dumpFeatures", LOG_RESOURCE_BUNDLE, "UIMA_cas_feature_name__FINE",
                    new Object[] { names[i], fValue.toString() });
          }
        }
    }

  }
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

            if (System.getProperty("DEBUG") != null)
              System.out.println("Feature Structure:::" + fs.getType() + " Has Value::" + names[i]);
          }

          if ("uima.cpm.DocumentText".equals(featureName) || "UTF8:UTF8Content".equals(featureName)) {
            FeatureValue fValue = fs.getFeatureValue("value");
            if (fValue == null) {
              return null;
            }
            return fValue.toString();
          } else if ("Detag:DetagContent".equals(featureName)) {
            FeatureValue fValue = fs.getFeatureValue("Doc:SpannedText");
            if (fValue == null) {
              return null;
            }
            return fValue.toString();

          }
          FeatureValue fValue = fs.getFeatureValue(featureName);
          if (fValue != null) {
            featureValue = fValue.toString();
            break;
          }
      }
    }
    return featureValue;
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

        FeatureStructure fs = it.next();
        if (featureStructureName.equals(fs.getType())) {
          String[] names = fs.getFeatureNames();
          for (int i = 0; names != null && i < names.length; i++) {
            if (names[i].equals(featureName)) {
              FeatureValue fValue = fs.getFeatureValue(featureName);
              if (fValue != null) {
                featureValue = fValue.toString();
                v.add(featureValue);
              }
            }
          }
      }
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

    Iterator<FeatureStructure> it = aCAS.getFeatureStructures();
    String featureValue = null;
    while (it.hasNext()) {
      FeatureStructure fs = it.next();
      if (fs.getType().equals(aFeatureStructure)) {
        FeatureValue fValue = fs.getFeatureValue(featureName);
        if (fValue != null) {
          featureValue = fValue.toString();
          break;
        }
      }
    }
    return featureValue;
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

        attrs.addAttribute("", "_indexed", "_indexed", "CDATA", indexedStr.toString());
      }

      String[] features = aFS.getFeatureNames();
      for (int i = 0; i < features.length; i++) {
        FeatureValue featVal = aFS.getFeatureValue(features[i]);
        if (featVal instanceof PrimitiveValue) {
          if (!"value".equals(features[i])) {
            attrs.addAttribute("", features[i], features[i], "CDATA", featVal.toString());
          } else {
            contentValue = featVal.toString();
          }
        } else {
          if (!"value".equals(features[i])) {
            attrs.addAttribute("", "_ref_" + features[i], "_ref_" + features[i], "CDATA",
                    ((ReferenceValue) featVal).getTargetId());
          } else {
            contentValue = ((ReferenceValue) featVal).getTargetId();
          }
        }
      }

      String xcasElementName = getXCasElementName(aFS);
      mHandler.startElement("", xcasElementName, xcasElementName, attrs);

      // encode array subelements
      String[] arrayElems = null;
      if (aFS instanceof PrimitiveArrayFS) {
        arrayElems = ((PrimitiveArrayFS) aFS).toStringArray();
      } else if (aFS instanceof ReferenceArrayFS) {
        arrayElems = ((ReferenceArrayFS) aFS).getIdRefArray();
      }
      if (arrayElems != null) {
        for (int j = 0; j < arrayElems.length; j++) {
          mHandler.startElement("", "i", "i", new AttributesImpl());
          if (arrayElems[j] != null) {
            mHandler.characters(arrayElems[j].toCharArray(), 0, arrayElems[j].length());
          }
          mHandler.endElement("", "i", "i");
        }
      }

      // encode "value" feature, if specified, as content
      if (contentValue != null) {
        mHandler.characters(contentValue.toCharArray(), 0, contentValue.length());
      }
      // encode annotation spanned text, if this FS has valid begin and end features
      else if (mIncludeAnnotationSpannedText && aDocTextHolder.docText != null
              && aDocTextHolder.docText.length > 0) {
        FeatureValue begin = aFS.getFeatureValue("begin");
        FeatureValue end = aFS.getFeatureValue("end");
        if (begin instanceof PrimitiveValue && end instanceof PrimitiveValue) {
          int beginChar = ((PrimitiveValue) begin).toInt();
          int endChar = ((PrimitiveValue) end).toInt();
          if (beginChar >= 0 && endChar > beginChar && endChar <= aDocTextHolder.docText.length) {
            // special case: do not include text of annotations spanning entire document
View Full Code Here

Examples of org.apache.uima.cas_data.FeatureValue

   */
  private void _generateDocFS(FeatureStructure aFS, DocTextHolder aDocTextHolder)
          throws SAXException {
    AttributesImpl attrs = new AttributesImpl();
    String textFeature = this.getDocumentTextFeatureName();
    FeatureValue docTextValue = aFS.getFeatureValue(textFeature);
    if (docTextValue != null) {
      String text = docTextValue.toString();
      aDocTextHolder.docText = text.toCharArray();
      if (!textFeature.equals("value")) {
        attrs.addAttribute("", "_content", "_content", "CDATA", textFeature);
      }
      mHandler.startElement("", mXCasDocTextTag, mXCasDocTextTag, attrs);
View Full Code Here

Examples of org.apache.uima.caseditor.editor.FeatureValue

      FeatureStructure featureStructure;

      if (parentElement instanceof ModelFeatureStructure) {
        featureStructure = ((ModelFeatureStructure) parentElement).getStructre();
      } else if (parentElement instanceof FeatureValue) {
        FeatureValue value = (FeatureValue) parentElement;

        if (parentElement instanceof StringArray) {
          StringArray array = (StringArray) parentElement;
          return array.toArray();
        }

        featureStructure = (FeatureStructure) value.getValue();
      } else {
        assert false : "Unexpected element!";

        return new Object[] {};
      }

      Type type = featureStructure.getType();

      Vector featureTypes = type.getAppropriateFeatures();

      Iterator featuresItertor = featureTypes.iterator();

      while (featuresItertor.hasNext()) {
        Feature feature = (Feature) featuresItertor.next();

        if (Primitives.isPrimitive(feature)) {
          // create a new pair
          // feature and value
          // add string
          childs.add(new FeatureValue(mDocument, featureStructure, feature));
        } else {
          childs.add(new FeatureValue(mDocument, featureStructure, feature));
        }
      }

      assert childs.size() > 0;
View Full Code Here

Examples of org.apache.uima.caseditor.editor.FeatureValue

    public boolean hasChildren(Object element) {
      if (element instanceof IAdaptable
              && ((IAdaptable) element).getAdapter(FeatureStructure.class) != null) {
        return true;
      } else if (element instanceof FeatureValue) {
        FeatureValue featureValue = (FeatureValue) element;

        if (Primitives.isPrimitive(featureValue.getFeature())) {
          Object value = featureValue.getValue();

          if (value == null) {
            return false;
          }

          if (value instanceof StringArray) {
            StringArray array = (StringArray) featureValue.getValue();

            if (array.size() > 0) {
              return true;
            } else {
              return false;
            }
          }

          return false;
        } else {
          return featureValue.getValue() != null ? true : false;
        }
      } else {
        assert false : "Unexpected element";

        return false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.