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


        feats.add(feat);

        // get the relation this arg belongs to, then its predicate, then the other arguments (via relations)
        FSList rels = entArg.getRelation().getPredicate().getRelations();
        while(rels instanceof NonEmptyFSList){
          NonEmptyFSList node = (NonEmptyFSList) rels;
          SemanticRoleRelation curRel = (SemanticRoleRelation) node.getHead();
          SemanticArgument curArg =  curRel.getArgument();
          if(entArg.getCoveredText().equals(curArg.getCoveredText())){
            // show which arg is the current arg
            //          out.print("*");
          }else{
            feat = "SRL: " + curArg.getLabel() + ":" + curArg.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }

          rels = node.getTail();
        }
      }
     
      // now look for dependency relations:
      List<ConllDependencyNode> coveredNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, lastWord);
      if(coveredNodes.size() > 0){
        ConllDependencyNode curNode = coveredNodes.get(0);
        ConllDependencyNode predNode = null;
        if(pred != null){
          List<ConllDependencyNode> predNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, pred);
          if(predNodes.size() > 0){
            predNode = predNodes.get(0);
          }
        }
        List<ConllDependencyNode> allNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, sent);

        for(ConllDependencyNode node : allNodes){
          if(node.getHead() == curNode){
            String feat = "entpointer:" + node.getDeprel() + ":" + node.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }else if(predNode != null && node.getHead() == predNode){
            String feat = "predpointer:" + node.getDeprel() + ":" + node.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }
        }
      }
    }
View Full Code Here

              .length());
      alchemyAnnotation.setAlchemyType(type.toString());
      alchemyAnnotation.addToIndexes();
      UIMAFramework.getLogger().log(Level.INFO, new StringBuilder("added AlchemyAnnotation for ").append(alchemyAnnotation.getCoveredText()).append(" of type ").append(type.toString()).toString());
      // update entity occurrences
      NonEmptyFSList list = (NonEmptyFSList) fs.getOccurrences();
      if (list != null) {
        NonEmptyFSList newTail = new NonEmptyFSList(cas);
        newTail.setHead(list.getHead());
        newTail.setTail(list.getTail());
      } else {
        list = new NonEmptyFSList(cas);
      }
      list.setHead(alchemyAnnotation);
      fs.setOccurrences(list);
    }
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();
        // NOTE: If this is in place, then we will only output negative examples backwards until we reach
        // the actual coreferent entity.  This may have the effect of suggesting that further away markables
        // are _more_ likely to be coreferent, which is an assumption that probably does not hold up in the
        // test set configuration.  Try commenting this feature out to see if it makes the feature more useful.
//        if(label == 1) break;
View Full Code Here

        feats.add(feat);

        // get the relation this arg belongs to, then its predicate, then the other arguments (via relations)
        FSList rels = entArg.getRelation().getPredicate().getRelations();
        while(rels instanceof NonEmptyFSList){
          NonEmptyFSList node = (NonEmptyFSList) rels;
          SemanticRoleRelation curRel = (SemanticRoleRelation) node.getHead();
          SemanticArgument curArg =  curRel.getArgument();
          if(entArg.getCoveredText().equals(curArg.getCoveredText())){
            // show which arg is the current arg
            //          out.print("*");
          }else{
            feat = "SRL: " + curArg.getLabel() + ":" + curArg.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }

          rels = node.getTail();
        }
      }
     
      // now look for dependency relations:
      List<ConllDependencyNode> coveredNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, lastWord);
      if(coveredNodes.size() > 0){
        ConllDependencyNode curNode = coveredNodes.get(0);
        ConllDependencyNode predNode = null;
        if(pred != null){
          List<ConllDependencyNode> predNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, pred);
          if(predNodes.size() > 0){
            predNode = predNodes.get(0);
          }
        }
        List<ConllDependencyNode> allNodes = JCasUtil.selectCovered(jcas, ConllDependencyNode.class, sent);

        for(ConllDependencyNode node : allNodes){
          if(node.getHead() == curNode){
            String feat = "entpointer:" + node.getDeprel() + ":" + node.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }else if(predNode != null && node.getHead() == predNode){
            String feat = "predpointer:" + node.getDeprel() + ":" + node.getCoveredText().replace(' ', '_').toLowerCase();
            feats.add(feat);
          }
        }
      }
    }
View Full Code Here

        // propagate the collection relation type
        RelationArgument anaRa = new RelationArgument(jcas);
        anaRa.setId(anaphor.getId());
        anaRa.setArgument(anaphor.getContent());
        anaRa.setRole("mention");
        NonEmptyFSList node = new NonEmptyFSList(jcas);
        node.setHead(anaRa);
        node.setTail(emptyList);
        collectionRas.put(anaphor, node);
        NonEmptyFSList anteNode = null;
        if(collectionRas.containsKey(bestAnte.m)){
          anteNode = collectionRas.get(bestAnte.m);
          // find the end of the chain of this node
          while(anteNode.getTail() instanceof NonEmptyFSList){
            anteNode = (NonEmptyFSList) anteNode.getTail();
          }
        }else{
          RelationArgument anteRa = new RelationArgument(jcas);
          anteRa.setId(bestAnte.m.getId());
          anteRa.setArgument(bestAnte.m.getContent());
          anteRa.setRole("mention");
         
          anteNode = new NonEmptyFSList(jcas);
          anteNode.setHead(anteRa);
          collectionRas.put(bestAnte.m, anteNode);
          CollectionTextRelation chain = new CollectionTextRelation(jcas);
          chain.setId(chainId++);
          chain.setCategory("CoreferenceChain");
          chain.setMembers(anteNode);
          chain.addToIndexes();
        }
        anteNode.setTail(node);
       
       
//        ppt.union(m2q.get(anaphor), m2q.get(bestAnte.m));
        if(anaphor instanceof PronounMarkable){
          // if the anaphor is a pronoun then it won't be in the cas as an identifiedannotation so we need to add it.
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

    NEMarkable m = (NEMarkable) lm.get(p); // Current markable under consideration
    MarkablePairSet pairList = new MarkablePairSet(jcas);
    pairList.setBegin(m.getBegin());
    pairList.setEnd(m.getEnd());
    pairList.setAnaphor(m);
    NonEmptyFSList head = new NonEmptyFSList(jcas);
    pairList.setAntecedentList(head);
    NonEmptyFSList tail = null;
    for (int q = p-1; q>=0; --q) {
      Markable a = (Markable) lm.get(q); // Candidate antecedent

      // Don't link to a expletive
//      if (dnr.contains(m)) continue;
      // Look no more than 10 sentences
      int sentdist = sentDist(jcas, a, m);
      if (sentdist>CorefConsts.NEDIST) break;
//      else if (sentdist>PRODIST && m instanceof PronounMarkable) continue;
      // filter out if both are NEs but of diff types
      if (m.getContent() instanceof IdentifiedAnnotation &&
          a.getContent() instanceof IdentifiedAnnotation &&
          ((IdentifiedAnnotation)m.getContent()).getTypeID() != ((IdentifiedAnnotation)a.getContent()).getTypeID())
        continue;

      // filter out "which" that crosses sentence boundary
      if (a.getCoveredText().equalsIgnoreCase("which") &&
          sentDist(jcas, a, m)>=1)
        continue;
      // ban pairs that one markable is a sub/superspan of the other
      if ((a.getBegin()<=m.getBegin() && a.getEnd()>=m.getEnd()) ||
          m.getBegin()<=a.getBegin() && m.getEnd()>=a.getEnd())
        continue;
      // Create a vector
      BooleanLabeledFS labeledAntecedent = new BooleanLabeledFS(jcas);
      labeledAntecedent.setFeature(a);
      if(tail == null){
        tail = head;
      }else{
        tail.setTail(new NonEmptyFSList(jcas));
        tail = (NonEmptyFSList) tail.getTail();
      }
      tail.setHead(labeledAntecedent);
//      if (isGoldPair(a, m)){
//        labeledAntecedent.setLabel(true);
//        // FIXME this cannot be done, it's implicitly looking at the label and changing the possible outcomes...
//        break; // stop if a gold pair is found
//      }else{
//        labeledAntecedent.setLabel(false);
//      }
    }
    if(tail == null) pairList.setAntecedentList(new EmptyFSList(jcas));
    else tail.setTail(new EmptyFSList(jcas));
    numVecs++;
    pairList.addToIndexes();   
  }
View Full Code Here

  private void createDemPairs(LinkedList<Annotation> lm, int p, JCas jcas) {
    DemMarkable m = (DemMarkable) lm.get(p); // Current markable under consideration
    MarkablePairSet pairList = new MarkablePairSet(jcas);
    pairList.setAnaphor(m);
    NonEmptyFSList head = new NonEmptyFSList(jcas);
    pairList.setAntecedentList(head);
    NonEmptyFSList tail = null;

    for (int q = p-1; q>=0; --q) {
      Markable a = (Markable) lm.get(q); // Candidate antecedent
      if (sentDist(jcas, a, m)>CorefConsts.PRODIST) break; // Look no more than 3 sentences

      // Create a vector
      BooleanLabeledFS labeledAntecedent = new BooleanLabeledFS(jcas);
      labeledAntecedent.setFeature(a);
      if(tail == null){
        tail = head;
      }else{
        tail.setTail(new NonEmptyFSList(jcas));
        tail = (NonEmptyFSList) tail.getTail();
      }
      tail.setHead(labeledAntecedent);
//      if (isGoldPair(a, m)){
//        // FIXME
//        labeledAntecedent.setLabel(true);
//        break; // stop if a gold pair is found
//      }else{
//        labeledAntecedent.setLabel(false);
//      }
    }
    if(tail == null) pairList.setAntecedentList(new EmptyFSList(jcas));
    else tail.setTail(new EmptyFSList(jcas));
    numVecs++;
    pairList.addToIndexes();
  }
View Full Code Here

  private void createPronPairs(LinkedList<Annotation> lm, int p, JCas jcas) {
    PronounMarkable m = (PronounMarkable) lm.get(p); // Current markable under consideration
    MarkablePairSet pairList = new MarkablePairSet(jcas);
    pairList.setAnaphor(m);
    NonEmptyFSList head = new NonEmptyFSList(jcas);
    pairList.setAntecedentList(head);
    NonEmptyFSList tail = null;
   
    for (int q = p-1; q>=0; --q) {
      Markable a = (Markable) lm.get(q); // Candidate antecedent
      if (sentDist(jcas, a, m)>CorefConsts.PRODIST) break// Look no more than 3 sentences

      if ((a.getBegin()<=m.getBegin() && a.getEnd()>=m.getEnd()) ||
          m.getBegin()<=a.getBegin() && m.getEnd()>=a.getEnd())
        continue;

      // Create a pair
      BooleanLabeledFS labeledAntecedent = new BooleanLabeledFS(jcas);
      labeledAntecedent.setFeature(a);
      if(tail == null){
        tail = head;
      }else{
        tail.setTail(new NonEmptyFSList(jcas));
        tail = (NonEmptyFSList) tail.getTail();
      }
      tail.setHead(labeledAntecedent);
//      if (isGoldPair(a, m)){
//        // FIXME
//        labeledAntecedent.setLabel(true);
//        break; // stop if a gold pair is found
//      }else{
//        labeledAntecedent.setLabel(false);
//      }
    }
    if(tail == null) pairList.setAntecedentList(new EmptyFSList(jcas));
    else tail.setTail(new EmptyFSList(jcas));
    numVecs++;
    pairList.addToIndexes();
  }
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.