Package org.apache.uima.jcas.cas

Examples of org.apache.uima.jcas.cas.NonEmptyFSList


    if (objArr.length == 0)
    {
      return new EmptyFSList(jcas);
    }
   
    NonEmptyFSList firstList = new NonEmptyFSList(jcas);
    NonEmptyFSList list = firstList;   
    for (int i=0; i < objArr.length; i++)
    {     
      list.setHead(objArr[i]);
      list.addToIndexes();
     
      if ((i+1) < objArr.length)
      {
        NonEmptyFSList nextList = new NonEmptyFSList(jcas);
        list.setTail(nextList);
        list = nextList;
      }
    }
   
View Full Code Here


  public void testGetNthFSList() throws Exception {
    try {
      Token tok1 = new Token(jcas);
      Token tok2 = new Token(jcas);

      NonEmptyFSList fsList1 = new NonEmptyFSList(jcas);
      fsList1.setHead(tok2);
      fsList1.setTail(new EmptyFSList(jcas));
      NonEmptyFSList fsList = new NonEmptyFSList(jcas);
      fsList.setHead(tok1);
      fsList.setTail(fsList1);
      EmptyFSList emptyFsList = new EmptyFSList(jcas);

      try {
        emptyFsList.getNthElement(0);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      try {
        fsList.getNthElement(-1);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_NEGATIVE_INDEX));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      try {
        fsList.getNthElement(2);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_PAST_END));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      assertTrue(tok1 == fsList.getNthElement(0));
      assertTrue(tok2 == fsList.getNthElement(1));
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
View Full Code Here

  public void testGetNthFSList() throws Exception {
    try {
      Token tok1 = new Token(jcas);
      Token tok2 = new Token(jcas);

      NonEmptyFSList fsList1 = new NonEmptyFSList(jcas);
      fsList1.setHead(tok2);
      fsList1.setTail(new EmptyFSList(jcas));
      NonEmptyFSList fsList = new NonEmptyFSList(jcas);
      fsList.setHead(tok1);
      fsList.setTail(fsList1);
      EmptyFSList emptyFsList = new EmptyFSList(jcas);

      try {
        emptyFsList.getNthElement(0);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      try {
        fsList.getNthElement(-1);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_NEGATIVE_INDEX));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      try {
        fsList.getNthElement(2);
        assertTrue(false); // error if we get here
      } catch (CASRuntimeException e) {
        assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_PAST_END));
        System.out.print("Expected Error: ");
        System.out.println(e.getMessage());
      }

      assertTrue(tok1 == fsList.getNthElement(0));
      assertTrue(tok2 == fsList.getNthElement(1));
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
View Full Code Here

    tokenBuilder.buildTokens(jCas, text);

    Collection<TOP> allFS = select(jCas, TOP.class);

    // Building a list... OMG!
    NonEmptyFSList allFSList = new NonEmptyFSList(jCas);
    NonEmptyFSList head = allFSList;
    Iterator<TOP> i = allFS.iterator();
    while (i.hasNext()) {
      head.setHead(i.next());
      if (i.hasNext()) {
        head.setTail(new NonEmptyFSList(jCas));
        head = (NonEmptyFSList) head.getTail();
      } else {
        head.setTail(new EmptyFSList(jCas));
      }
    }

    // Print what is expected
    for (FeatureStructure fs : allFS) {
View Full Code Here

    tokenBuilder.buildTokens(jCas, text);

    Collection<TOP> allFS = select(jCas, TOP.class);

    // Building a list... OMG!
    NonEmptyFSList allFSList = new NonEmptyFSList(jCas);
    NonEmptyFSList head = allFSList;
    Iterator<TOP> i = allFS.iterator();
    while (i.hasNext()) {
      head.setHead(i.next());
      if (i.hasNext()) {
        head.setTail(new NonEmptyFSList(jCas));
        head = (NonEmptyFSList) head.getTail();
      } else {
        head.setTail(new EmptyFSList(jCas));
      }
    }

    // Print what is expected
    for (FeatureStructure fs : allFS) {
View Full Code Here

  public static Collection<TOP> create(FSList aList, Type type) {
    TypeSystem ts = aList.getCAS().getTypeSystem();
    List<FeatureStructure> data = new ArrayList<FeatureStructure>();
    FSList i = aList;
    while (i instanceof NonEmptyFSList) {
      NonEmptyFSList l = (NonEmptyFSList) i;
      TOP value = l.getHead();
      if (value != null && (type == null || ts.subsumes(type, value.getType()))) {
        data.add(l.getHead());
      }
      i = l.getTail();
    }

    return asList(data.toArray(new TOP[data.size()]));
  }
View Full Code Here

  public static FSList createFSList(JCas aJCas, Collection<? extends TOP> aCollection) {
    if (aCollection.isEmpty()) {
      return new EmptyFSList(aJCas);
    }

    NonEmptyFSList head = new NonEmptyFSList(aJCas);
    NonEmptyFSList list = head;
    Iterator<? extends TOP> i = aCollection.iterator();
    while (i.hasNext()) {
      head.setHead(i.next());
      if (i.hasNext()) {
        head.setTail(new NonEmptyFSList(aJCas));
        head = (NonEmptyFSList) head.getTail();
      } else {
        head.setTail(new EmptyFSList(aJCas));
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.uima.jcas.cas.NonEmptyFSList

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.