Package org.apache.uima.cas

Examples of org.apache.uima.cas.ArrayFS


  public void testCopyToArray() {
    FeatureStructure fs1 = this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_ANNOTATION));
    FeatureStructure fs2 = this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_TOP));
    FeatureStructure fs3 = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
    ArrayFS array = this.cas.createArrayFS(4);
    array.set(0, fs1);
    array.set(1, fs2);
    array.set(2, fs3);
    // We now have an FS array with the last element being null
    final int destinationOffset = 2;
    final int destiniationSize = 10;
    FeatureStructure[] fsArray = new FeatureStructure[destiniationSize];
    String[] stringArray = new String[destiniationSize];
    // Copy to array, skipping first element
    // This must not throw an NPE, see UIMA-726
    array.copyToArray(1, fsArray, destinationOffset, array.size() - 1);
    array.copyToArray(1, stringArray, destinationOffset, array.size() - 1);
    assertTrue(fs2.equals(fsArray[destinationOffset]));
    assertTrue(fs3.equals(fsArray[destinationOffset+1]));
    assertNotNull(stringArray[destinationOffset]);
    assertNotNull(stringArray[destinationOffset+1]);
    for (int i = 0; i < destinationOffset; i++) {
View Full Code Here


    AnnotationFS annot = this.cas.createAnnotation(annotationType, 0, 5);
    IntArrayFS intArray = this.cas.createIntArrayFS(3);
    intArray.set(0, 1);
    intArray.set(1, 2);
    intArray.set(2, -10);
    ArrayFS subArray1 = this.cas.createArrayFS(1);
    ArrayFS subArray2 = this.cas.createArrayFS(2);
    subArray1.set(0, subArray2);
    subArray2.set(1, annot);
    ArrayFS superArray = this.cas.createArrayFS(3);
    superArray.set(0, subArray1);
    superArray.set(1, subArray2);
    superArray.set(2, intArray);
    assertTrue(superArray.get(0).equals(subArray1));
    assertTrue(superArray.get(1).equals(subArray2));
    assertTrue(superArray.get(2).equals(intArray));
    assertTrue(((ArrayFS) superArray.get(0)).get(0).equals(subArray2));
    assertTrue(((ArrayFS) superArray.get(1)).get(0) == null);
    assertTrue(((ArrayFS) superArray.get(1)).get(1).equals(annot));
    assertTrue(((IntArrayFS) superArray.get(2)).get(0) == 1);
    assertTrue(((IntArrayFS) superArray.get(2)).get(1) == 2);
    assertTrue(((IntArrayFS) superArray.get(2)).get(2) == -10);
  }
View Full Code Here

    else if (element instanceof ArrayValue) {

      ArrayValue value = (ArrayValue) element;

      if (value.getFeatureStructure() instanceof ArrayFS) {
        ArrayFS array = (ArrayFS) value.getFeatureStructure();

        FeatureStructure fs = array.get(value.slot());

        if (fs == null) {
          cell.setText("null");
        }
        else {
View Full Code Here

            } else if (tableItem.getData() instanceof ArrayValue) {
              ArrayValue value = (ArrayValue) tableItem.getData();

              if (value.getFeatureStructure() instanceof ArrayFS) {

                ArrayFS array = (ArrayFS) value.getFeatureStructure();

                array.set(value.slot(), (FeatureStructure) event.data);

                document.update(array);

                event.detail = DND.DROP_COPY;
              }
View Full Code Here

    }

    int size;

    if (value instanceof ArrayFS) {
      ArrayFS array = (ArrayFS) value;

      size = array.size();
    } else if (value instanceof CommonArrayFS) {
      CommonArrayFS array = (CommonArrayFS) value;

      size = array.size();
    } else if (value instanceof StringArrayFS) {
      StringArrayFS array = (StringArrayFS) value;

      size = array.size();
    } else {
      throw new CasEditorError("Unkown array type!");
    }

    return size;
View Full Code Here

        return getElements(arrayFS);
      }
    } else if (parentElement instanceof ArrayValue) {
      ArrayValue value = (ArrayValue) parentElement;

      ArrayFS array = (ArrayFS) value.getFeatureStructure();

      return getElements(array.get(value.slot()));
    }
    else {
      throw new CasEditorError("Unexpected element type!");
    }
  }
View Full Code Here

      ArrayValue value = (ArrayValue) element;

      if (value.getFeatureStructure() instanceof ArrayFS) {

        ArrayFS array = (ArrayFS) value.getFeatureStructure();

        return hasChildren(array.get(value.slot()));
      }
      else {
        // false for primitive arrays
        return false;
      }
View Full Code Here

    Feature annotArrayFeat = annotArrayTestType.getFeatureByBaseName("arrayOfAnnotations");
    Iterator<AnnotationFS> iter2 = cas2.getAnnotationIndex(annotArrayTestType).iterator();
    assertTrue(iter2.hasNext());
    while (iter2.hasNext()) {
      FeatureStructure fs = iter2.next();
      ArrayFS arrayFS = (ArrayFS) fs.getFeatureValue(annotArrayFeat);
      assertNotNull(arrayFS);
      for (int i = 0; i < arrayFS.size(); i++) {
        assertNotNull(arrayFS.get(i));
      }
    }
   
    // test that lenient mode does not report errors
    CAS cas3 = CasCreationUtils.createCas(new TypeSystemDescription_impl(),
View Full Code Here

    AnnotationFS annot2 = newView2.createAnnotation(orgType, annotStart2, annotStart2 + annotText.length());
    newView2.addFsToIndexes(annot2);

    // Add an FS with an array of existing annotations in another view
    int nToks = 3;
    ArrayFS array = newView2.createArrayFS(nToks);
    Type thingType = newCas2.getTypeSystem().getType("org.apache.uima.testTypeSystem.Thing");
    FSIterator thingIter = newCas2.getAnnotationIndex(thingType).iterator();
    for (int i = 0; i < nToks; ++i)
      array.set(i, (FeatureStructure)thingIter.next())
    Type annotArrayTestType = newView2.getTypeSystem().getType("org.apache.uima.testTypeSystem.AnnotationArrayTest");
    Feature annotArrayFeat = annotArrayTestType.getFeatureByBaseName("arrayOfAnnotations");
    AnnotationFS fsArrayTestAnno = newView2.createAnnotation(annotArrayTestType, 13, 27);
    fsArrayTestAnno.setFeatureValue(annotArrayFeat,array);
    newView2.addFsToIndexes(fsArrayTestAnno);
   
    // re-serialize each new CAS back to XMI, keeping consistent ids
    String newSerCas1 = serialize(newCas1, deserSharedData1, marker1);
    String newSerCas2 = serialize(newCas2, deserSharedData2, marker2);
   
    // merge the two XMI CASes back into the original CAS
    // the shared data will be reset and recreated if not using deltaCas
    if (useDeltas) {
      deserialize(newSerCas1, cas, serSharedData, false, maxOutgoingXmiId);
    } else {
      deserialize(newSerCas1, cas, serSharedData, false, -1);
    }
    assertEquals(numAnnotations + 2, cas.getAnnotationIndex().size());

    deserialize(newSerCas2, cas, serSharedData, false, maxOutgoingXmiId);
    assertEquals(numAnnotations + 5, cas.getAnnotationIndex().size());
    assertEquals(docText, cas.getDocumentText());

    // Serialize/deserialize again in case merge created duplicate ids
    String newSerCasMerged = serialize(cas, serSharedData);
    deserialize(newSerCasMerged, cas, serSharedData, false, -1);
   
    //check covered text of annotations
    FSIterator iter = cas.getAnnotationIndex().iterator();
    while (iter.hasNext()) {
      AnnotationFS annot = (AnnotationFS)iter.next();
      assertEquals(cas.getDocumentText().substring(
              annot.getBegin(), annot.getEnd()), annot.getCoveredText());
    }
    //check Owner annotation we created to test link across merge boundary
    iter = cas.getAnnotationIndex(ownerType).iterator();
    while (iter.hasNext()) {
      AnnotationFS
      annot = (AnnotationFS)iter.next();
      String componentId = annot.getStringValue(componentIdFeat);
      if ("XCasDeserializerTest".equals(componentId)) {
        FeatureStructure targetRelArgs = annot.getFeatureValue(argsFeat);
        AnnotationFS targetDomain = (AnnotationFS)targetRelArgs.getFeatureValue(domainFeat);
        assertEquals(60, targetDomain.getBegin());
        assertEquals(70, targetDomain.getEnd());
        AnnotationFS targetRange = (AnnotationFS)targetRelArgs.getFeatureValue(rangeFeat);
        assertEquals(orgBegin, targetRange.getBegin());
        assertEquals(orgEnd, targetRange.getEnd());
      }    
    }
    //check Sofas
    CAS targetView1 = cas.getView("newSofa1");
    assertEquals(sofaText1, targetView1.getDocumentText());
    CAS targetView2 = cas.getView("newSofa2");
    assertEquals(sofaText2, targetView2.getDocumentText());
    AnnotationFS targetAnnot1 = (AnnotationFS)
      targetView1.getAnnotationIndex(orgType).iterator().get();
    assertEquals(annotText, targetAnnot1.getCoveredText());
    AnnotationFS targetAnnot2 = (AnnotationFS)
    targetView2.getAnnotationIndex(orgType).iterator().get();
    assertEquals(annotText, targetAnnot2.getCoveredText());
    assertTrue(targetView1.getSofa().getSofaRef() !=
            targetView2.getSofa().getSofaRef());
   
    CAS checkPreexistingView = cas.getView("preexistingView");
    assertEquals(preexistingViewText, checkPreexistingView.getDocumentText());
    Type personType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.Person");   
    AnnotationFS targetAnnot3 = (AnnotationFS)
            checkPreexistingView.getAnnotationIndex(personType).iterator().get();
    assertEquals("John Smith", targetAnnot3.getCoveredText());

    // Check the FS with an array of pre-existing FSs
    iter = targetView2.getAnnotationIndex(annotArrayTestType).iterator();
    componentIdFeat = thingType.getFeatureByBaseName("componentId");
    while (iter.hasNext()) {
      AnnotationFS annot = (AnnotationFS)iter.next();
      ArrayFS fsArray = (ArrayFS)annot.getFeatureValue(annotArrayFeat);
      assertTrue(fsArray.size() == 3);
      for (int i = 0; i < fsArray.size(); ++i) {
        AnnotationFS refAnno = (AnnotationFS)fsArray.get(i);
        assertEquals(thingType.getName(), refAnno.getType().getName());
        assertEquals("JResporator", refAnno.getStringValue(componentIdFeat));
        assertTrue(cas == refAnno.getView());
      }
    }
View Full Code Here

    cas.addFsToIndexes(orgAnnot1);
    AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20);
    cas.addFsToIndexes(orgAnnot2);
    AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20);
    cas.addFsToIndexes(testAnnot);
    ArrayFS arrayFs = cas.createArrayFS(2);
    arrayFs.set(0, orgAnnot1);
    arrayFs.set(1, orgAnnot2);
    Feature arrayFeat = testAnnotType.getFeatureByBaseName("arrayFeat");
    testAnnot.setFeatureValue(arrayFeat, arrayFs);
   
    //serialize to XMI
    String xmiStr = serialize(cas, null);
View Full Code Here

TOP

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

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.