Package org.apache.uima.cas_data

Examples of org.apache.uima.cas_data.FeatureStructure


   * Test for void generateXCas(CasData)
   */
  public void testGenerateXCasCasData() throws Exception {
    try {
      CasData casData = new CasDataImpl();
      FeatureStructure testFS = new FeatureStructureImpl();
      testFS.setType("Test");
      testFS.setId("foo");
      testFS.setIndexed(new int[] { 1 });
      testFS.setFeatureValue("myFeature", new PrimitiveValueImpl("myValue"));
      testFS.setFeatureValue("value", new PrimitiveValueImpl("this should show up in XML content"));
      casData.addFeatureStructure(testFS);

      CasDataToXCas generator = new CasDataToXCas();
      TestContentHandler testContentHandler = new TestContentHandler("Test");
      generator.setContentHandler(testContentHandler);
      generator.generateXCas(casData);
      Assert.assertTrue(testContentHandler.foundTestElement);

      // also try colon and dash conversions
      casData = new CasDataImpl();
      testFS = new FeatureStructureImpl();
      testFS.setType("Test_colon_Foo_dash_Bar_colon_What_dash_a_dash_mess");
      testFS.setId("foo");
      testFS.setIndexed(new int[] { 1 });
      testFS.setFeatureValue("myFeature", new PrimitiveValueImpl("myValue"));
      testFS.setFeatureValue("value", new PrimitiveValueImpl("this should show up in XML content"));
      casData.addFeatureStructure(testFS);

      testContentHandler = new TestContentHandler("Test:Foo-Bar:What-a-mess");
      generator.setContentHandler(testContentHandler);
      generator.generateXCas(casData);
View Full Code Here


      // System.out.println(casData);
      Iterator<FeatureStructure> fsIter = casData.getFeatureStructures();
      boolean foundCrawlUrl = false;
      while (fsIter.hasNext()) {
        FeatureStructure fs = fsIter.next();
        if ("Crawl_colon_URL".equals(fs.getType())) {
          // System.out.println("[" + fs.getFeatureValue("value") + "]");
          Assert
                  .assertEquals(
                          "http://www.nolimitmedia.com/index.php?act=group&gro=1&gron=Flash&PHPSESSID=5dcc31fb425c4a204b70d9eab92531a5",
                          fs.getFeatureValue("value").toString());
          foundCrawlUrl = true;
        }
      }
      assertTrue(foundCrawlUrl);
    } catch (Exception e) {
View Full Code Here

    TypeSystemDescription result = UIMAFramework.getResourceSpecifierFactory()
        .createTypeSystemDescription();
    Iterator<FeatureStructure> iter = aCasData.getFeatureStructures();
    List<TypeDescription> typesArr = new ArrayList<TypeDescription>();
    while (iter.hasNext()) {
      FeatureStructure casFS = iter.next();
      TypeDescription newType = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
      newType.setName(casFS.getType());
      newType.setSupertypeName("uima.tcas.annotation");
      newType.setDescription("CasData Type");
      String features[] = casFS.getFeatureNames();
      if (features != null) {
        for (int i = 0; i < features.length; i++) {
          String featName = features[i];
          String rangeName = "";
          String description = "";
          PrimitiveValue pVal = (PrimitiveValue) casFS.getFeatureValue(featName);
          if (pVal.get().getClass().getName().equals("java.lang.String")) {
            System.out.println(" the feature is a String ");
            rangeName = "uima.cas.String";
            description = " featue of the casDataType";
          }
View Full Code Here

      // System.out.println(casData);
      Iterator fsIter = casData.getFeatureStructures();
      boolean foundCrawlUrl = false;
      while (fsIter.hasNext()) {
        FeatureStructure fs = (FeatureStructure) fsIter.next();
        if ("Crawl_colon_URL".equals(fs.getType())) {
          // System.out.println("[" + fs.getFeatureValue("value") + "]");
          Assert
                  .assertEquals(
                          "http://www.nolimitmedia.com/index.php?act=group&gro=1&gron=Flash&PHPSESSID=5dcc31fb425c4a204b70d9eab92531a5",
                          fs.getFeatureValue("value").toString());
          foundCrawlUrl = true;
        }
      }
      assertTrue(foundCrawlUrl);
    } catch (Exception e) {
View Full Code Here

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

  public static boolean hasFeatureStructure(CasData aCAS, String aName) {
    Iterator it = aCAS.getFeatureStructures();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof FeatureStructure) {
        FeatureStructure fs = (FeatureStructure) object;
        if (fs.getType().equals(aName)) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

  public static void dumpFeatures(CasData aCAS) {
    Iterator it = aCAS.getFeatureStructures();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof FeatureStructure) {
        FeatureStructure fs = (FeatureStructure) object;
        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

    Iterator it = aCAS.getFeatureStructures();
    String featureValue = null;
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof FeatureStructure) {
        FeatureStructure fs = (FeatureStructure) object;
        if (System.getProperty("DEBUG") != null)
          System.out.println("FeatureName::::::::::::::::::::::::::::::::::::::::::>"
                  + fs.getType() + " Searching For::" + featureName);
        if (featureName.equals(fs.getType())) {
          String[] names = fs.getFeatureNames();
          for (int i = 0; names != null && i < names.length; i++) {
            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;
          }
        }
View Full Code Here

    String featureValue = null;
    Vector v = new Vector();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof FeatureStructure) {
        FeatureStructure fs = (FeatureStructure) object;
        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

    String featureValue = null;
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof FeatureStructure
              && ((FeatureStructure) object).getType().equals(aFeatureStructure)) {
        FeatureStructure fs = (FeatureStructure) object;
        FeatureValue fValue = fs.getFeatureValue(featureName);
        if (fValue != null) {
          featureValue = fValue.toString();
          break;
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.uima.cas_data.FeatureStructure

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.