Examples of EntityMention


Examples of edu.stanford.nlp.ie.machinereading.structure.EntityMention

   * @param proto The serialized entity mention.
   * @param sentence The sentence this mention is attached to.
   * @return The entity mention corresponding to the serialized object.
   */
  private EntityMention fromProto(CoreNLPProtos.Entity proto, CoreMap sentence) {
    EntityMention rtn = new EntityMention(
        proto.hasObjectID() ? proto.getObjectID() : null,
        sentence,
        proto.hasHeadStart() ? new Span(proto.getHeadStart(), proto.getHeadEnd()) : null,
        proto.hasHeadEnd() ? new Span(proto.getExtentStart(), proto.getExtentEnd()) : null,
        proto.hasType() ? proto.getType() : null,
        proto.hasSubtype() ? proto.getSubtype() : null,
        proto.hasMentionType() ? proto.getMentionType() : null );
    if (proto.hasNormalizedName()) { rtn.setNormalizedName(proto.getNormalizedName()); }
    if (proto.hasHeadTokenIndex()) { rtn.setHeadTokenPosition(proto.getHeadTokenIndex()); }
    if (proto.hasCorefID()) { rtn.setCorefID(proto.getCorefID()); }
    return rtn;
  }
View Full Code Here

Examples of edu.stanford.nlp.ie.machinereading.structure.EntityMention

          if(e.getMentions().contains(aceEntityMention)){
            corefID = entityID;
            break;
          }
        }
        EntityMention convertedMention = convertAceEntityMention(aceEntityMention, docId, sentence, tokenOffset, corefID);
//        EntityMention convertedMention = convertAceEntityMention(aceEntityMention, docId, sentence, tokenOffset);
        entityCounts.incrementCount(convertedMention.getType());
        logger.info("CONVERTED MENTION HEAD SPAN: " + convertedMention.getHead());
        logger.info("CONVERTED ENTITY MENTION: " + convertedMention);
        AnnotationUtils.addEntityMention(sentence, convertedMention);
        entityMentionMap.put(aceEntityMention.getId(), convertedMention);

        // TODO: make Entity objects as needed
      }

      // convert relation mentions
      for (AceRelationMention aceRelationMention : relationMentions) {
        RelationMention convertedMention = convertAceRelationMention(aceRelationMention, docId, sentence, entityMentionMap);
        if(convertedMention != null){
          relationCounts.incrementCount(convertedMention.getType());
          logger.info("CONVERTED RELATION MENTION: " + convertedMention);
          AnnotationUtils.addRelationMention(sentence, convertedMention);
        }

        // TODO: make Relation objects
      }

      // convert EventMentions
      for(AceEventMention aceEventMention: eventMentions){
        EventMention convertedMention = convertAceEventMention(aceEventMention, docId, sentence, entityMentionMap, tokenOffset);
        if(convertedMention != null){
          eventCounts.incrementCount(convertedMention.getType());
          logger.info("CONVERTED EVENT MENTION: " + convertedMention);
          AnnotationUtils.addEventMention(sentence, convertedMention);
        }

        // TODO: make Event objects
View Full Code Here

Examples of edu.stanford.nlp.ie.machinereading.structure.EntityMention

    // note: the ace.reader stores absolute token offset from the beginning of the document, but
    //       we need token offsets from the beginning of the sentence => adjust by tokenOffset
    // note: in ace.reader the end token position is inclusive, but
    //       in our setup the end token position is exclusive => add 1 to end
    EntityMention converted = new EntityMention(
        entityMention.getId(),
        sentence,
        new Span(extStart, extEnd),
        new Span(headStart, headEnd),
        entityMention.getParent().getType(),
View Full Code Here

Examples of edu.stanford.nlp.ie.machinereading.structure.EntityMention

        numBlankLinesSeen++;
        break;
      case 3: // relation
        String type = pieces.get(2);
        List<ExtractionObject> args = new ArrayList<ExtractionObject>();
        EntityMention entity1 = indexToEntityMention.get(pieces.get(0));
        EntityMention entity2 = indexToEntityMention.get(pieces.get(1));
        args.add(entity1);
        args.add(entity2);
        Span span = new Span(entity1.getExtentTokenStart(), entity2
            .getExtentTokenEnd());
        // identifier = "relation" + sentenceID + "-" + sentence.getAllRelations().size();
        identifier = RelationMention.makeUniqueId();
        RelationMention relationMention = new RelationMention(identifier,
            sentence, span, type, null, args);
        AnnotationUtils.addRelationMention(sentence, relationMention);
        break;
      case 9: // token
        /*
         * Roth token lines look like this:
         *
         * 19 Peop 9 O NNP/NNP Jamal/Ghosheh O O O
         */

        // Entities may be multiple words joined by '/'; we split these up
        List<String> words = StringUtils.split(pieces.get(5), "/");
        //List<String> postags = StringUtils.split(pieces.get(4),"/");

        String text = StringUtils.join(words, " ");
        identifier = "entity" + pieces.get(0) + "-" + pieces.get(2);
        String nerTag = getNormalizedNERTag(pieces.get(1)); // entity type of the word/expression

        if (sentenceID == null)
          sentenceID = pieces.get(0);

        if (!nerTag.equals("O")) {
          Span extentSpan = new Span(tokenCount, tokenCount + words.size());
          // Temporarily sets the head span to equal the extent span.
          // This is so the entity has a head (in particular, getValue() works) even if preprocessSentences isn't called.
          // The head span is later modified if preprocessSentences is called.
          EntityMention entity = new EntityMention(identifier, sentence,
              extentSpan, extentSpan, nerTag, null, null);
          AnnotationUtils.addEntityMention(sentence, entity);

          // we can get by using these indices as strings since we only use them
          // as a hash key
View Full Code Here

Examples of edu.stanford.nlp.ie.machinereading.structure.EntityMention

        entityMention.getLdctype());
    return converted;
  }

  private EntityMention convertAceEntityMention(AceEntityMention entityMention, String docId, CoreMap sentence, int tokenOffset, String corefID) {
    EntityMention converted = convertAceEntityMention(entityMention, docId, sentence, tokenOffset);
    converted.setCorefID(corefID);
    return converted;
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.EntityMention

        sentence);

    // Create pairings (this will change depending on the classification direction)
    List<IdentifiedAnnotationPair> pairs = new ArrayList<IdentifiedAnnotationPair>();
    for (int i = 0; i < args.size(); ++i) {
      EntityMention arg1 = args.get(i);
      int jStart = this.classifyBothDirections ? 0 : i + 1;
      for (int j = jStart; j < args.size(); ++j) {
        EntityMention arg2 = args.get(j);
        // skip identical entity mentions and mentions with identical spans
        if (i == j || (arg1.getBegin() == arg2.getBegin() && arg1.getEnd() == arg2.getEnd())) {
          continue;
        }
        pairs.add(new IdentifiedAnnotationPair(arg1, arg2));
      }
    }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.EntityMention

        // for disjoint spans, just ignore the gap
        Span first = entry.getValue().get(0);
        Span last = entry.getValue().get(entry.getValue().size() - 1);
       
        EntityMention entityMention = new EntityMention(initView, first.start, last.end);
        entityMention.setTypeID(Mapper.getEntityTypeId(entityTypes.get(entry.getKey())));
        entityMention.setId(identifiedAnnotationId++);
        entityMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
        entityMention.setConfidence(1);
       
        entityMention.addToIndexes();
      }
  }
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.EntityMention

        modifier.addToIndexes();
        spanToModifier.put(modifierSpan, modifier);
      }
     
      // create an entity mention object and add it to the cas
      EntityMention entityMention = null;
      if(spanToEntity.containsKey(entityMentionSpan)) {
        // an entity with the same span has already been added to the cas
        entityMention = spanToEntity.get(entityMentionSpan);
      }
      else {
        // this entity needs to be addded to the cas
        entityMention = new EntityMention(jCas, entityMentionSpan.start, entityMentionSpan.end);
        entityMention.setTypeID(entityMentionType);
        entityMention.setId(identifiedAnnotationId++);
        entityMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
        entityMention.setConfidence(1);
        entityMention.addToIndexes();
        spanToEntity.put(entityMentionSpan, entityMention);
      }

      RelationArgument relationArgument1 = new RelationArgument(jCas);
      relationArgument1.setId(relationArgumentId++);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.EntityMention

      // for disjoint spans, just ignore the gap
      Span first1 = entityMentions.get(relationInfo.id1).get(0);
      Span last1 = entityMentions.get(relationInfo.id1).get(entityMentions.get(relationInfo.id1).size() - 1);
      Span span1 = new Span(first1.start, last1.end);

      EntityMention entityMention1 = null;
      if(spanToEntity.containsKey(span1)) {
        // an entity with the same span has already been added to the cas
        entityMention1 = spanToEntity.get(span1);
      }
      else {
        // this entity still needs to be addded to the cas
        entityMention1 = new EntityMention(jCas, span1.start, span1.end);
        entityMention1.setTypeID(Mapper.getEntityTypeId(entityTypes.get(relationInfo.id1)));
        entityMention1.setId(identifiedAnnotationId++);
        entityMention1.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
        entityMention1.setConfidence(1);
        entityMention1.addToIndexes();
        spanToEntity.put(span1, entityMention1);
      }

      // again, rememeber that some entities have disjoint spans
      Span first2 = entityMentions.get(relationInfo.id2).get(0);
      Span last2 = entityMentions.get(relationInfo.id2).get(entityMentions.get(relationInfo.id2).size() - 1);
      Span span2 = new Span(first2.start, last2.end);

      EntityMention entityMention2 = null;
      if(spanToEntity.containsKey(span2)) {
        // an entity with this span already exists in the cas
        entityMention2 = spanToEntity.get(span2);
      }
      else {
        // this entity still needs to be added to the cas
        entityMention2 = new EntityMention(jCas, span2.start, span2.end);
        entityMention2.setTypeID(Mapper.getEntityTypeId(entityTypes.get(relationInfo.id2)));
        entityMention2.setId(identifiedAnnotationId++);
        entityMention2.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
        entityMention2.setConfidence(1);
        entityMention2.addToIndexes();
        spanToEntity.put(span2, entityMention2);
      }

      RelationArgument relationArgument1 = new RelationArgument(jCas);
      relationArgument1.setId(relationArgumentId++);
View Full Code Here

Examples of org.apache.ctakes.typesystem.type.textsem.EntityMention

      // ignore all entities that cannot be found by ctakes
      if(Mapper.getEntityTypeId(entityTypes.get(entry.getKey())) == CONST.NE_TYPE_ID_UNKNOWN) {
        continue;
      }

      EntityMention entityMention = new EntityMention(jCas, span.start, span.end);
      entityMention.setTypeID(Mapper.getEntityTypeId(entityTypes.get(entry.getKey())));
      entityMention.setId(identifiedAnnotationId++);
      entityMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
      entityMention.setConfidence(1);
      entityMention.addToIndexes();

      spanToEntity.put(span, entityMention);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.