Package org.apache.uima.jcas.cas

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


  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

  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

      String corefType = (anaphor instanceof NEMarkable ? CorefConsts.NE : (anaphor instanceof DemMarkable ? CorefConsts.DEM : CorefConsts.PRON));
      //      String nodeStr = vec.getVector();
      //      int label = getLabel(nodeStr);
      FSList pairList = pair.getAntecedentList();
      while(pairList instanceof NonEmptyFSList){
        NonEmptyFSList node = (NonEmptyFSList) pairList;
        BooleanLabeledFS labeledProb = (BooleanLabeledFS) node.getHead();
        int label = labeledProb.getLabel() ? 1 : 0;
        if(anaphora){
          if(label == 1) posAnaphInst++;
          else negAnaphInst++;
          anaphLabels.add(label);
          svm_node[] nodes = vecCreator.createAnaphoricityVector(anaphor, jcas);
          anaphNodes.add(nodes);
        }
        Markable antecedent = (Markable) labeledProb.getFeature();
        label = (labeler.isGoldPair(anaphor, antecedent) ? 1 : 0);
        if(label == 1){
          numPos++;
          if(corefType.equals(CorefConsts.NE)){
            posNeInst++;
            //          neInds.add(ind);
          }else if(corefType.equals(CorefConsts.DEM)){
            posDemInst++;
          }else if(corefType.equals(CorefConsts.PRON)){
            posPronInst++;
          }
        }
        else if(label == 0){
          if(corefType.equals(CorefConsts.NE)){
            negNeInst++;
            //          neInds.add(ind);
          }else if(corefType.equals(CorefConsts.DEM)){
            negDemInst++;
          }else if(corefType.equals(CorefConsts.PRON)){
            negPronInst++;
          }
        }
//        corefLabels.add(label);
//        corefTypes.add(corefType);        // need to add it every time so the indices match...
        //      corefPathTrees.add(pathTree);

        if(printVectors){
          svm_node[] nodes = vecCreator.getNodeFeatures(anaphor, antecedent, jcas); //getNodes(nodeStr);
//          corefNodes.add(nodes);
          PrintWriter writer = null;
          if(corefType.equals(CorefConsts.NE)){
            writer = neOut;
          }else if(corefType.equals(CorefConsts.PRON)){
            writer = pronOut;
          }else if(corefType.equals(CorefConsts.DEM)){
            writer = demOut;
          }
          writer.print(label);
          for(svm_node inst : nodes){
            writer.print(" ");
            writer.print(inst.index);
            writer.print(":");
            writer.print(inst.value);
          }
          writer.println();
          writer.flush();
        }

        if(printTrees){
          //          Markable anaphor = vec.getAnaphor();
          //          Markable antecedent = vec.getAntecedent();
          TreebankNode antecedentNode = MarkableTreeUtils.markableNode(jcas, antecedent.getBegin(), antecedent.getEnd());
          TreebankNode anaphorNode = MarkableTreeUtils.markableNode(jcas, anaphor.getBegin(), anaphor.getEnd());
          debug.println(TreeUtils.tree2str(antecedentNode));
          debug.println(TreeUtils.tree2str(anaphorNode));
//          TopTreebankNode pathTree = TreeExtractor.extractPathTree(antecedentNode, anaphorNode, jcas);
          SimpleTree pathTree = TreeExtractor.extractPathTree(antecedentNode, anaphorNode);
          SimpleTree petTree = TreeExtractor.extractPathEnclosedTree(antecedentNode, anaphorNode, jcas);
//          TopTreebankNode tree = mctTree;
//          String treeStr = TreeUtils.tree2str(tree);
//          String treeStr = mctTree.toString();
          String treeStr = pathTree.toString();
          PrintWriter writer = null;
          if(corefType.equals(CorefConsts.NE)){
            writer = neTreeOut;
          }else if(corefType.equals(CorefConsts.PRON)){
            writer = pronTreeOut;
          }else if(corefType.equals(CorefConsts.DEM)){
            writer = demTreeOut;
          }
          writer.print(label == 1 ? "+1" : "-1");
          writer.print(" |BT| ");
          writer.print(treeStr.replaceAll("\\) \\(", ")("));
          writer.println(" |ET|");
        }
        pairList = node.getTail();
        if(label == 1) break;
      }
    }
    if(printVectors){
      neOut.close();
View Full Code Here

    }

    // Scan from the end of the Markable list
    // insert Markables to the head of their chains
    for (int i = ec.length-1; i >= 0; --i) {
      NonEmptyFSList l = new NonEmptyFSList(jcas);
      l.setHead(lm.get(i));
      l.setTail(listhds[ec[i]]);
      listhds[ec[i]] = l;
      chains[ec[i]].setMembers(l);
    }
  }
View Full Code Here


  private LinkedList<Markable> fs2ll(FSList fs) {
    LinkedList<Markable> ll = new LinkedList<Markable>();
    while(fs instanceof NonEmptyFSList){
      NonEmptyFSList node = (NonEmptyFSList) fs;
      BooleanLabeledFS feat = (BooleanLabeledFS) node.getHead();
      Markable antecedent = (Markable) feat.getFeature();
      ll.add(antecedent);
      fs = node.getTail();
    }
    return ll;
  }
View Full Code Here

    wikipediaEntity.addToIndexes();

  }

  private FSList findSTSAnnotations(JCas jcas) {
    NonEmptyFSList annotations = new NonEmptyFSList(jcas);
    WikipediaEntityAnnotation annotation = new WikipediaEntityAnnotation(jcas);
    annotation.setBegin(0);
    annotation.setEnd(1);
    annotation.setUri("http://somesite.org/#STS135cit1");
    annotation.addToIndexes();
    annotations.setHead(annotation);
    return annotations;
  }
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

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.