Package org.apache.uima.cas.impl

Examples of org.apache.uima.cas.impl.CASImpl


  /**
   * (Internal) create a new instance of TOP (or subclass of TOP) in Java and Cas, and make them
   * correspond.
   */
  public TOP(JCas jcas) {
    CASImpl casImpl = (CASImpl)jcas.getCas();
    this.jcasType = jcas.getType(getTypeIndexID());
    if (null == jcasType) {
      CASRuntimeException e = new CASRuntimeException(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS,
          new String[] { this.getClass().getName() });
      throw e;
    }
    boolean isSubtypeOfAnnotationBase = casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode);
    if (isSubtypeOfAnnotationBase &&
        (casImpl.getBaseCAS() == casImpl)) {
      throw new CASRuntimeException(CASRuntimeException.DISALLOW_CREATE_ANNOTATION_IN_BASE_CAS,
          new String[] { this.getClass().getName() });
    }
    this.addr = jcasType.ll_cas.ll_createFS(jcasType.casTypeCode);
    jcas.putJfsFromCaddr(addr, this);
   
    if (casImpl.isSubtypeOfAnnotationBaseType(jcasType.casTypeCode)) {
      casImpl.setSofaFeat(addr, casImpl.getSofaRef());
    }
  }
View Full Code Here


   * @deprecated As of v2.0, use {@link JCasImpl#createView(String)} to create a view, which will
   *             also create the Sofa for that view.
   */
  public Sofa(JCas jcas, SofaID ID, String mimeType) {
    super(jcas);
    final CASImpl casImpl = jcasType.casImpl;
    casImpl.addSofa(casImpl.createFS(this.addr), ID.getSofaID(), mimeType);
    casImpl.getView(this); // needed to make reset work
  }
View Full Code Here

      CAS localCas = jcas.getCas();
      assertTrue(localCas == this.cas);
      LowLevelCAS ll_cas = jcas.getLowLevelCas();
      assertTrue(ll_cas == this.cas);
      CASImpl casImpl = jcas.getCasImpl();
      assertTrue(casImpl == this.cas);
      TOP_Type type = jcas.getType(org.apache.uima.jcas.tcas.Annotation.type);
      assertTrue(type instanceof org.apache.uima.jcas.tcas.Annotation_Type);
      type = jcas.getType(Annotation.typeIndexID);
      assertTrue(type instanceof Annotation_Type);
View Full Code Here

   * Create a new CASMgr object.
   *
   * @return A new CASMgr object.
   */
  public static CASMgr createCAS() {
    return new CASImpl();
  }
View Full Code Here

   *          have a major performance impact. As a very rough guideline, this number should not be
   *          smaller than the number of characters in documents you are processing.
   * @return A new CASMgr object.
   */
  public static CASMgr createCAS(int initialHeapSize) {
    return new CASImpl(initialHeapSize);
  }
View Full Code Here

   */
  public static CASMgr createCAS(int initialHeapSize, TypeSystem ts) {
    if (ts == null) {
      throw new NullPointerException("TypeSystem");
    }
    return new CASImpl((TypeSystemImpl) ts, initialHeapSize);
  }
View Full Code Here

   */
  public static CASMgr createCAS(TypeSystem ts) {
    if (ts == null) {
      throw new NullPointerException("TypeSystem");
    }
    return new CASImpl((TypeSystemImpl) ts, CASImpl.DEFAULT_INITIAL_HEAP_SIZE);
  }
View Full Code Here

    }
    if (this.addr == 0) {
      return;
    }
    Type type = getType();
    CASImpl cas = this.fSTreeModel.getCas();
    if (this.fSTreeModel.getCas().isArrayType(type)) {
      int arrayLength = cas.ll_getArraySize((int) this.addr);
//      if (arrayLength > 20) {
//        arrayLength = 20;
//      }
      FSNode node = null;
      int arrayPos = cas.getArrayStartAddress((int) this.addr);
      int nodeClass1;
      if (cas.isIntArrayType(type)) {
        nodeClass1 = FSNode.INT_FS;
      } else if (cas.isFloatArrayType(type)) {
        nodeClass1 = FSNode.FLOAT_FS;
      } else if (cas.isStringArrayType(type)) {
        nodeClass1 = FSNode.STRING_FS;
      } else if (cas.isByteArrayType(type)) {
        nodeClass1 = FSNode.BYTE_FS;
      } else if (cas.isBooleanArrayType(type)) {
        nodeClass1 = FSNode.BOOL_FS;
      } else if (cas.isShortArrayType(type)) {
        nodeClass1 = FSNode.SHORT_FS;
      } else if (cas.isLongArrayType(type)) {
        nodeClass1 = FSNode.LONG_FS;
      } else if (cas.isDoubleArrayType(type)) {
        nodeClass1 = FSNode.DOUBLE_FS;
      } else {
        nodeClass1 = FSNode.STD_FS;
      }
      ArrayList arrayNodes = new ArrayList(arrayLength);
      if (nodeClass1 == INT_FS || nodeClass1 == FLOAT_FS || nodeClass1 == STRING_FS
              || nodeClass1 == STD_FS) {
        for (int i = 0; i < arrayLength; i++) {
          node = new FSNode(this.fSTreeModel, nodeClass1, cas.getHeapValue(arrayPos), i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      } else if (nodeClass1 == BYTE_FS) {
        for (int i = 0; i < arrayLength; i++) {
          node = new FSNode(this.fSTreeModel, nodeClass1, cas.ll_getByteArrayValue((int) this.addr,
                  i), i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      } else if (nodeClass1 == SHORT_FS) {
        for (int i = 0; i < arrayLength; i++) {
          node = new FSNode(this.fSTreeModel, nodeClass1, cas.ll_getShortArrayValue(
                  (int) this.addr, i), i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      } else if (nodeClass1 == BOOL_FS) {
        for (int i = 0; i < arrayLength; i++) {
          int temp = cas.ll_getBooleanArrayValue((int) this.addr, i) ? 1 : 0;
          node = new FSNode(this.fSTreeModel, nodeClass1, temp, i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      } else if (nodeClass1 == LONG_FS) {
        for (int i = 0; i < arrayLength; i++) {
          long temp = cas.ll_getLongArrayValue((int) this.addr, i);
          node = new FSNode(this.fSTreeModel, nodeClass1, temp, i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      } else if (nodeClass1 == DOUBLE_FS) {
        for (int i = 0; i < arrayLength; i++) {
          double temp = cas.ll_getDoubleArrayValue((int) this.addr, i);
          node = new FSNode(this.fSTreeModel, nodeClass1, CASImpl.double2long(temp), i);
          arrayNodes.add(node);
          ++arrayPos;
        }
      }
      this.children = FSTreeModel.createArrayChildren(0, arrayLength, arrayNodes, this.fSTreeModel);
    } else {
      this.children = new ArrayList();
      List feats = type.getFeatures();
      for (int i = 0; i < feats.size(); i++) {
        FeatureImpl feat1 = (FeatureImpl) feats.get(i);
        long featAddr = cas.getHeapValue((int) this.addr + cas.getFeatureOffset(feat1.getCode()));
        if (cas.isDoubleType(feat1.getRange()) || cas.isLongType(feat1.getRange())) {
          featAddr = cas.ll_getLongValue((int) featAddr);
        }
        FSNode childNode = new FSNode(this.fSTreeModel, this.fSTreeModel.getNodeType(
                (int) this.addr, feat1), featAddr, feat1);
        this.children.add(childNode);
      }
View Full Code Here

      Object [] initargs = new Object[2];
      JCasImpl jcasView = null;
      // this funny logic is because although the annotationView should always be set if
      //  a type is a subtype of annotation, it isn't always set if an application uses low-level
      //  api's.  Rather than blow up, we limp along.
      CASImpl maybeAnnotationView = null
      if (isSubtypeOfAnnotationBase) {
        final int sofaNbr = getSofaNbr(addr, casView);
        if (sofaNbr > 0) {
          maybeAnnotationView = (CASImpl)casView.getView(sofaNbr);
        }
      }
      final CASImpl view = (null != maybeAnnotationView) ? maybeAnnotationView : casView;

      try {
        jcasView = (JCasImpl)view.getJCas();
      } catch (CASException e1) {
       logAndThrow(e1, jcasView);
      }
    
     // Return eq fs instance if already created
View Full Code Here

      CAS cas1 = CasCreationUtils.createCas(l);
      cas1.setDocumentText("foo");
      CASCompleteSerializer ser = Serialization.serializeCASComplete((CASMgr) cas1);

      CAS tcas2 = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null);
      CASImpl cas2 = ((CASImpl) tcas2).getBaseCAS();
      tcas2.setDocumentText("bar");

      // reinit
      //  This uses cas2 which only has a base type system to start,
      //    and loads it from a complete serialization which has other new types
      cas2.reinit(ser);
      CAS tcas3 = cas2.getCurrentView();

      assertTrue(tcas2 == tcas3);
      assertNotNull(cas1.getTypeSystem().getType("NamedEntity"));
      assertNotNull(tcas3.getTypeSystem().getType("NamedEntity"));
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.impl.CASImpl

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.