Package org.apache.uima.cas

Examples of org.apache.uima.cas.ByteArrayFS


          buf.append(elemStr);
        }
        return buf.toString();
      } else if (arrayType == LowLevelCAS.TYPE_CLASS_BYTEARRAY) {
        // special case for byte arrays: serialize as hex digits
        ByteArrayFS byteArrayFS = new ByteArrayFSImpl(addr, cas);
        int len = byteArrayFS.size();
        for (int i = 0; i < len; i++) {
          byte b = byteArrayFS.get(i);
          // this test is necessary to generate a leading zero where necessary
          if ((b & 0xF0) == 0) {
            buf.append('0').append(Integer.toHexString(b).toUpperCase());
          } else {
            buf.append(Integer.toHexString(0xFF & b).toUpperCase());
View Full Code Here


                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_BYTEARRAY: {
            ByteArrayFS returnFS = (ByteArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_DOUBLEARRAY: {
            DoubleArrayFS returnFS = (DoubleArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_FLOATARRAY: {
            FloatArrayFS returnFS = (FloatArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               return convertToString(returnFS.toStringArray());
            }
         }
         case LowLevelCAS.TYPE_CLASS_FSARRAY: {
            ArrayFS returnFS = (ArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_INTARRAY: {
            IntArrayFS returnFS = (IntArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_LONGARRAY: {
            LongArrayFS returnFS = (LongArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_SHORTARRAY: {
            ShortArrayFS returnFS = (ShortArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         case LowLevelCAS.TYPE_CLASS_STRINGARRAY: {
            StringArrayFS returnFS = (StringArrayFS) featurePathValue.getFs();
            if (returnFS == null) {
               return null;
            } else {
               // check if we have a built-in function
               if (this.builtInFunction > NO_BUILT_IN_FUNCTION) {
                  return evaluateBuiltInFunction(returnFS);
               } else {
                  return convertToString(returnFS.toStringArray());
               }
            }
         }
         }
      }
View Full Code Here

        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ByteArrayFS) {
      ByteArrayFS arrayFs = (ByteArrayFS) aSrcFs;
      int len = arrayFs.size();
      ByteArrayFS destFS = mDestCas.createByteArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ShortArrayFS) {
      ShortArrayFS arrayFs = (ShortArrayFS) aSrcFs;
      int len = arrayFs.size();
      ShortArrayFS destFS = mDestCas.createShortArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof LongArrayFS) {
      LongArrayFS arrayFs = (LongArrayFS) aSrcFs;
      int len = arrayFs.size();
      LongArrayFS destFS = mDestCas.createLongArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof FloatArrayFS) {
      FloatArrayFS arrayFs = (FloatArrayFS) aSrcFs;
      int len = arrayFs.size();
      FloatArrayFS destFS = mDestCas.createFloatArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof DoubleArrayFS) {
      DoubleArrayFS arrayFs = (DoubleArrayFS) aSrcFs;
      int len = arrayFs.size();
      DoubleArrayFS destFS = mDestCas.createDoubleArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof BooleanArrayFS) {
      BooleanArrayFS arrayFs = (BooleanArrayFS) aSrcFs;
      int len = arrayFs.size();
      BooleanArrayFS destFS = mDestCas.createBooleanArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ArrayFS) {
      ArrayFS arrayFs = (ArrayFS) aSrcFs;
      int len = arrayFs.size();
      ArrayFS destFS = mDestCas.createArrayFS(len);
      for (int i = 0; i < len; i++) {
        FeatureStructure srcElem = arrayFs.get(i);
        if (srcElem != null) {
          FeatureStructure copyElem = copyFs(arrayFs.get(i));
          destFS.set(i, copyElem);
        }
      }
      return destFS;
    }
    assert false; // the set of array types should be exhaustive, so we should never get here
View Full Code Here

     *          a Delta CAS.
     * @return
     */
    private int createByteArray(String hexString, int xmiId, int addr) {
      int arrayLen = hexString.length() / 2;
      ByteArrayFS fs = null;
     
      if (addr > 0) {   //non-shared and fs exists
      fs = (ByteArrayFS) casBeingFilled.createFS(addr);
        if (fs.size() != arrayLen) {  //if length changes, create newFS
          fs = casBeingFilled.createByteArrayFS(arrayLen);
        }
      } else if (xmiId == -1) { //non-shared and no fs
      fs = casBeingFilled.createByteArrayFS(arrayLen);
      } else  {       //shared
      if (isNewFS(xmiId)) {
        fs = casBeingFilled.createByteArrayFS(arrayLen);
      } else {
        addr = getFsAddrForXmiId(xmiId);
        fs = (ByteArrayFS) casBeingFilled.createFS(addr);
        if (fs.size() != arrayLen) {
          fs = casBeingFilled.createByteArrayFS(arrayLen);
        }
      }
      }
     
      for (int i = 0; i < arrayLen; i++) {
        byte high = hexCharToByte(hexString.charAt(i * 2));
        byte low = hexCharToByte(hexString.charAt(i * 2 + 1));
        byte b = (byte) ((high << 4) | low);
        fs.set(i, b);
      }

      int arrayAddr = ((FeatureStructureImpl) fs).getAddress();
      deserializedFsAddrs.add(arrayAddr);
      addFsAddrXmiIdMapping(arrayAddr, xmiId);
View Full Code Here

        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ByteArrayFS) {
      ByteArrayFS arrayFs = (ByteArrayFS) aSrcFs;
      int len = arrayFs.size();
      ByteArrayFS destFS = mDestCas.createByteArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ShortArrayFS) {
      ShortArrayFS arrayFs = (ShortArrayFS) aSrcFs;
      int len = arrayFs.size();
      ShortArrayFS destFS = mDestCas.createShortArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof LongArrayFS) {
      LongArrayFS arrayFs = (LongArrayFS) aSrcFs;
      int len = arrayFs.size();
      LongArrayFS destFS = mDestCas.createLongArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof FloatArrayFS) {
      FloatArrayFS arrayFs = (FloatArrayFS) aSrcFs;
      int len = arrayFs.size();
      FloatArrayFS destFS = mDestCas.createFloatArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof DoubleArrayFS) {
      DoubleArrayFS arrayFs = (DoubleArrayFS) aSrcFs;
      int len = arrayFs.size();
      DoubleArrayFS destFS = mDestCas.createDoubleArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof BooleanArrayFS) {
      BooleanArrayFS arrayFs = (BooleanArrayFS) aSrcFs;
      int len = arrayFs.size();
      BooleanArrayFS destFS = mDestCas.createBooleanArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ArrayFS) {
      ArrayFS arrayFs = (ArrayFS) aSrcFs;
      int len = arrayFs.size();
      ArrayFS destFS = mDestCas.createArrayFS(len);
      for (int i = 0; i < len; i++) {
        FeatureStructure srcElem = arrayFs.get(i);
        if (srcElem != null) {
          FeatureStructure copyElem = copyFs(arrayFs.get(i));
          destFS.set(i, copyElem);
        }
      }
      return destFS;
    }
    assert false; // the set of array types should be exhaustive, so we should never get here
View Full Code Here

     *          value of the byte array as a hex string
     * @return
     */
    private int createByteArray(String hexString, int xmiId) {
      int arrayLen = hexString.length() / 2;
      ByteArrayFS fs = casBeingFilled.createByteArrayFS(arrayLen);
      for (int i = 0; i < arrayLen; i++) {
        byte high = hexCharToByte(hexString.charAt(i * 2));
        byte low = hexCharToByte(hexString.charAt(i * 2 + 1));
        byte b = (byte) ((high << 4) | low);
        fs.set(i, b);
      }

      int arrayAddr = ((FeatureStructureImpl) fs).getAddress();
      deserializedFsAddrs.add(arrayAddr);
      addFsAddrXmiIdMapping(arrayAddr, xmiId);
View Full Code Here

        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ByteArrayFS) {
      ByteArrayFS arrayFs = (ByteArrayFS) aSrcFs;
      int len = arrayFs.size();
      ByteArrayFS destFS = mOriginalTgtCasView.createByteArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ShortArrayFS) {
      ShortArrayFS arrayFs = (ShortArrayFS) aSrcFs;
      int len = arrayFs.size();
      ShortArrayFS destFS = mOriginalTgtCasView.createShortArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof LongArrayFS) {
      LongArrayFS arrayFs = (LongArrayFS) aSrcFs;
      int len = arrayFs.size();
      LongArrayFS destFS = mOriginalTgtCasView.createLongArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof FloatArrayFS) {
      FloatArrayFS arrayFs = (FloatArrayFS) aSrcFs;
      int len = arrayFs.size();
      FloatArrayFS destFS = mOriginalTgtCasView.createFloatArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof DoubleArrayFS) {
      DoubleArrayFS arrayFs = (DoubleArrayFS) aSrcFs;
      int len = arrayFs.size();
      DoubleArrayFS destFS = mOriginalTgtCasView.createDoubleArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof BooleanArrayFS) {
      BooleanArrayFS arrayFs = (BooleanArrayFS) aSrcFs;
      int len = arrayFs.size();
      BooleanArrayFS destFS = mOriginalTgtCasView.createBooleanArrayFS(len);
      for (int i = 0; i < len; i++) {
        destFS.set(i, arrayFs.get(i));
      }
      return destFS;
    }
    if (aSrcFs instanceof ArrayFS) {
      ArrayFS arrayFs = (ArrayFS) aSrcFs;
      int len = arrayFs.size();
      ArrayFS destFS = mOriginalTgtCasView.createArrayFS(len);
      for (int i = 0; i < len; i++) {
        FeatureStructure srcElem = arrayFs.get(i);
        if (srcElem != null) {
          FeatureStructure copyElem = copyFsInner(arrayFs.get(i));
          destFS.set(i, copyElem);
        }
      }
      return destFS;
    }
    assert false; // the set of array types should be exhaustive, so we should never get here
View Full Code Here

      // shortarraySofaFS.setLocalSofaData(shortArrayFS);
      CAS shortArrayView =this.cas.createView("shortArraySofaData");
      shortArrayView.setSofaDataArray(shortArrayFS, "shorts");

      // create a byte array fs
      ByteArrayFS byteArrayFS =this.cas.createByteArrayFS(5);
      byteArrayFS.set(0, (byte) 8);
      byteArrayFS.set(1, (byte) 16);
      byteArrayFS.set(2, (byte) 64);
      byteArrayFS.set(3, (byte) 128);
      byteArrayFS.set(4, (byte) 255);
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("byteArraySofaData");
      // SofaFS bytearraySofaFS = cas.createSofa(id, "text");
      // bytearraySofaFS.setLocalSofaData(byteArrayFS);
      CAS byteArrayView =this.cas.createView("byteArraySofaData");
      byteArrayView.setSofaDataArray(byteArrayFS, "bytes");

      // create a long array fs
      LongArrayFS longArrayFS =this.cas.createLongArrayFS(5);
      longArrayFS.set(0, Long.MAX_VALUE);
      longArrayFS.set(1, Long.MAX_VALUE - 1);
      longArrayFS.set(2, Long.MAX_VALUE - 2);
      longArrayFS.set(3, Long.MAX_VALUE - 3);
      longArrayFS.set(4, Long.MAX_VALUE - 4);
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("longArraySofaData");
      // SofaFS longarraySofaFS = cas.createSofa(id, "text");
      // longarraySofaFS.setLocalSofaData(longArrayFS);
      CAS longArrayView =this.cas.createView("longArraySofaData");
      longArrayView.setSofaDataArray(longArrayFS, "longs");

      DoubleArrayFS doubleArrayFS =this.cas.createDoubleArrayFS(5);
      doubleArrayFS.set(0, Double.MAX_VALUE);
      doubleArrayFS.set(1, Double.MIN_VALUE);
      doubleArrayFS.set(2, Double.parseDouble("1.5555"));
      doubleArrayFS.set(3, Double.parseDouble("99.000000005"));
      doubleArrayFS.set(4, Double.parseDouble("4.44444444444444444"));
      // create a Sofa and set the SofaArray feature.
      // id = new SofaID_impl();
      // id.setSofaID("doubleArraySofaData");
      // SofaFS doublearraySofaFS = cas.createSofa(id, "text");
      // doublearraySofaFS.setLocalSofaData(doubleArrayFS);
      CAS doubleArrayView =this.cas.createView("doubleArraySofaData");
      doubleArrayView.setSofaDataArray(doubleArrayFS, "doubles");

      // create remote sofa and set the SofaURI feature
      // id = new SofaID_impl();
      // id.setSofaID("remoteSofaData");
      // SofaFS remoteSofa = cas.createSofa(id, "text");
      // remoteSofa.setRemoteSofaURI("file:.\\Sofa.xcas");
      CAS remoteView =this.cas.createView("remoteSofaData");
      String sofaFileName = "./Sofa.xcas";
      remoteView.setSofaDataURI("file:" + sofaFileName, "text");

      // read sofa data
      // InputStream is = strSofa.getSofaDataStream();
      InputStream is = stringView.getSofaDataStream();
      assertTrue(is != null);
      byte[] dest = new byte[1];
      StringBuffer buf = new StringBuffer();
      while (is.read(dest) != -1) {
        buf.append((char) dest[0]);
      }
      assertTrue(buf.toString().equals("this beer is good"));

      dest = new byte[4];
      // is = intarraySofaFS.getSofaDataStream();
      is.close();
      is = intArrayView.getSofaDataStream();
      assertTrue(is != null);
      int i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getInt() == intArrayFS.get(i++));
      }

      // is = floatarraySofaFS.getSofaDataStream();
      is.close();
      is = floatArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getFloat() == floatArrayFS.get(i++));
      }

      dest = new byte[2];
      // is = shortarraySofaFS.getSofaDataStream();
      is.close();
      is = shortArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).getShort() == shortArrayFS.get(i++));
      }

      dest = new byte[1];
      // is = bytearraySofaFS.getSofaDataStream();
      is.close();
      is = byteArrayView.getSofaDataStream();
      assertTrue(is != null);
      i = 0;
      while (is.read(dest) != -1) {
        assertTrue(ByteBuffer.wrap(dest).get() == byteArrayFS.get(i++));
      }

      dest = new byte[8];
      // is = longarraySofaFS.getSofaDataStream();
      is.close();
View Full Code Here

  }
 
  public void testSetSofaDataArray() {
    final String TEST_MIME = "text/plain";   
    CAS testView = this.cas.createView("TestView");
    ByteArrayFS sofaDataArray = testView.createByteArrayFS(2);
    sofaDataArray.set(0, (byte)0);
    sofaDataArray.set(1, (byte)42);
    testView.setSofaDataArray(sofaDataArray, TEST_MIME);
    assertEquals(sofaDataArray, testView.getSofa().getLocalFSData());
    assertEquals(TEST_MIME, testView.getSofa().getSofaMime());
  }
View Full Code Here

    assertEquals(TEST_MIME, testView.getSofa().getSofaMime());
  }
 
  public void testSetSofaDataArrayOnInitialView() {
    final String TEST_MIME = "text/plain";   
    ByteArrayFS sofaDataArray = this.cas.createByteArrayFS(2);
    sofaDataArray.set(0, (byte)0);
    sofaDataArray.set(1, (byte)42);
    this.cas.setSofaDataArray(sofaDataArray, TEST_MIME);
    assertEquals(sofaDataArray, this.cas.getSofa().getLocalFSData());
    assertEquals(TEST_MIME, this.cas.getSofa().getSofaMime());
  }
View Full Code Here

TOP

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

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.