Package org.apache.uima.cas.admin

Examples of org.apache.uima.cas.admin.LinearTypeOrderBuilder


   *           if an error occurs during type priority setup
   */
  public static void setupTypePriorities(CASMgr aCASMgr, TypePriorities aTypePriorities)
          throws ResourceInitializationException {
    if (aTypePriorities != null) {
      LinearTypeOrderBuilder typeOrderBuilder = aCASMgr.getIndexRepositoryMgr()
              .getDefaultOrderBuilder();
      TypePriorityList[] priorityLists = aTypePriorities.getPriorityLists();
      for (int i = 0; i < priorityLists.length; i++) {
        // check that all types exist. This error would be caught in
        // typeOrderBuilder.getOrder(), but that's too late to indicate
        // the location of the faulty descriptor in the error message.
        String[] typeList = priorityLists[i].getTypes();
        for (int j = 0; j < typeList.length; j++) {
          if (aCASMgr.getTypeSystemMgr().getType(typeList[j]) == null) {
            throw new ResourceInitializationException(
                    ResourceInitializationException.UNDEFINED_TYPE_FOR_PRIORITY_LIST, new Object[] {
                        typeList[j], priorityLists[i].getSourceUrlString() });
          }
        }
        try {
          typeOrderBuilder.add(priorityLists[i].getTypes());
        } catch (CASException e) {
          // typically caused by a cycle in the priorities - the caused-by message
          // will clarify.
          throw new ResourceInitializationException(
                  ResourceInitializationException.INVALID_TYPE_PRIORITIES,
View Full Code Here


   *                 if an error occurs during type priority setup
   */
  public static void setupTypePriorities(CASMgr aCASMgr, TypePriorities aTypePriorities)
      throws ResourceInitializationException {
    if (aTypePriorities != null) {
      LinearTypeOrderBuilder typeOrderBuilder = aCASMgr.getIndexRepositoryMgr()
          .getDefaultOrderBuilder();
      TypePriorityList[] priorityLists = aTypePriorities.getPriorityLists();
      for (int i = 0; i < priorityLists.length; i++) {
        // check that all types exist. This error would be caught in
        // typeOrderBuilder.getOrder(), but that's too late to indicate
        // the location of the faulty descriptor in the error message.
        String[] typeList = priorityLists[i].getTypes();
        for (int j = 0; j < typeList.length; j++) {
          if (aCASMgr.getTypeSystemMgr().getType(typeList[j]) == null) {
            throw new ResourceInitializationException(
                ResourceInitializationException.UNDEFINED_TYPE_FOR_PRIORITY_LIST, new Object[] {
                    typeList[j], priorityLists[i].getSourceUrlString() });
          }
        }
        try {
          typeOrderBuilder.add(priorityLists[i].getTypes());
        } catch (CASException e) {
          // typically caused by a cycle in the priorities - the caused-by message
          // will clarify.
          throw new ResourceInitializationException(
              ResourceInitializationException.INVALID_TYPE_PRIORITIES,
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.apache.uima.cas.admin.FSIndexRepositoryMgr#createTypeSortOrder()
   */
  public LinearTypeOrderBuilder createTypeSortOrder() {
    final LinearTypeOrderBuilder orderBuilder = new LinearTypeOrderBuilderImpl(this.typeSystem);
    if (this.defaultOrderBuilder == null) {
      this.defaultOrderBuilder = orderBuilder;
    }
    return orderBuilder;
  }
View Full Code Here

    comp.setType(annotation);
    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_BEGIN),
            FSIndexComparator.STANDARD_COMPARE);
    comp.addKey(annotation.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END),
            FSIndexComparator.REVERSE_STANDARD_COMPARE);
    LinearTypeOrderBuilder tob = irm.createTypeSortOrder();
    try {
      tob.add(new String[] { CAS.TYPE_NAME_ANNOTATION, SENT_TYPE, TOKEN_TYPE });
      comp.addKey(tob.getOrder(), FSIndexComparator.STANDARD_COMPARE);
    } catch (CASException e) {
      TestCase.assertTrue(false);
    }
    irm.createIndex(comp, ANNOT_BAG_INDEX, FSIndex.BAG_INDEX);
    irm.createIndex(comp, ANNOT_SET_INDEX, FSIndex.SET_INDEX);
View Full Code Here

   */
  /**
   * Test driver.
   */
  public void testMain() throws Exception {
    LinearTypeOrderBuilder order = irm.createTypeSortOrder();
    order = irm.createTypeSortOrder();
    LinearTypeOrder lo;
    try {
      order.add(new String[] { "aaa", "bbb" });
      lo = order.getOrder();
      check(lo, "aaa", "bbb");
    } catch (CASException e) {
      assertTrue(false);
    }
  }
View Full Code Here

      assertTrue(false);
    }
  }

  public void testN1() throws Exception {
    LinearTypeOrderBuilder order = irm.createTypeSortOrder();
    order = irm.createTypeSortOrder();
    LinearTypeOrder lo;
    try {
      // aaa (and all its subtypes) come before bbb (and all its subtypes)
      order.add(new String[] { "aaa", "bbb" });
      // aa (and all its subtypes) come before
      //   abaa (and all its subtypes) come before
      //     abbbb (and all its subtypes)
      order.add(new String[] { "aa", "abaa", "abbbb" });
      lo = order.getOrder();
      check(lo, new String[] { "aa", "abaa", "abbbb" });
      check(lo, "aaa", "bbb");

      check(lo, "aaa", "abaaa");
      check(lo, "aaab", "abaab")
View Full Code Here

    }
  }

  public void testLoop2() throws Exception {
    try {
      LinearTypeOrderBuilder obuilder;
      LinearTypeOrder order;
      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "a", "b" });
      check(order = obuilder.getOrder(), "aa", "bb");
      checkBackwards(order, "bb", "aa");
      check(order, "ab", "bb");
      check(order, "aa", "ba");
      check(order, "ab", "ba");

      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "b", "a" });
      check(order = obuilder.getOrder(), "ba", "aa");
      check(order, "bb", "aa");
      check(order, "ba", "ab");
      check(order, "bb", "ab");

      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "a", "b" });
      obuilder.add(new String[] { "bb", "a" });
      check(order = obuilder.getOrder(), "bb", "aa"); // these two forced to reverse
      check(order, "bb", "ab"); // these two forced to reverse
      check(order, "aa", "ba");
      check(order, "ab", "ba");

      // set a child in front of the sib of its parent,
      // and one in front of the child of its prev sib.
      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "aba", "aa" });
      obuilder.add(new String[] { "b", "aa" });
      check(order = obuilder.getOrder(), "aba", "aa");
      check(order, "bb", "aa"); // child of b dragged along?
      check(order, "b", "aaa"); // child of aa dragged?

      // siblings children dragged
      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "ab", "aa" });
      obuilder.add(new String[] { "b", "aa" });
      check(order = obuilder.getOrder(), "ab", "aa");
      check(order, "b", "aa");
      check(order, "bb", "aa"); // child of b dragged along?
      check(order, "b", "aaa"); // child of aa dragged?

      // siblings children dragged
      obuilder = irm.createTypeSortOrder();
      obuilder.add(new String[] { "ab", "aa" });
      obuilder.add(new String[] { "b", "aa" });
      obuilder.add(new String[] { "a", "b" });

      check(order = obuilder.getOrder(), "ab", "aa");
      check(order, "b", "aa");
      check(order, "bb", "aa"); // child of b dragged along?
      check(order, "b", "aaa"); // child of aa dragged?
      check(order, "ac", "b");
View Full Code Here

    }

    FSIndexRepositoryMgr irm = cas1.getIndexRepositoryMgr();

    // Check that appropriate exception is thrown on unknown types.
    LinearTypeOrderBuilder order = irm.createTypeSortOrder();
    boolean excCaught = false;
    try {
      order.add(new String[] { "foo", "bar" });
      order.getOrder();
    } catch (NullPointerException e) {
      assertTrue(false);
    } catch (CASException e) {
      excCaught = true;
    }
    assertTrue(excCaught);

    // Create an alternative annotation index using a type sort order.
    order = irm.createTypeSortOrder();
    try {
      order.add(new String[] { TOKEN_TYPE, SENT_TYPE, CAS.TYPE_NAME_ANNOTATION });
      order.getOrder();
    } catch (CASException e) {
      assertTrue(false);
    }
  }
View Full Code Here

      comp.addKey(newTypeOrder(), FSIndexComparator.STANDARD_COMPARE);
      return comp;
    }

    private LinearTypeOrder newTypeOrder() {
      LinearTypeOrderBuilder ltob = new LinearTypeOrderBuilderImpl(ts);
      LinearTypeOrder order;
      try {
        ltob.add(new String[] { "Type1", "Type1Sub1", "Type1Sub2" });
        order = ltob.getOrder();
      } catch (CASException e) {
        throw new Error(e);
      }
      return order;
    }
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.apache.uima.cas.admin.FSIndexRepositoryMgr#createTypeSortOrder()
   */
  public LinearTypeOrderBuilder createTypeSortOrder() {
    final LinearTypeOrderBuilder orderBuilder = new LinearTypeOrderBuilderImpl(this.typeSystem);
    if (this.defaultOrderBuilder == null) {
      this.defaultOrderBuilder = orderBuilder;
    }
    return orderBuilder;
  }
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.admin.LinearTypeOrderBuilder

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.