Examples of IdentifiedAnnotation


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

  /**
   * Is this pair of entities enclosed inside a noun phrase?
   */
  public static boolean isEnclosed(IdentifiedAnnotationPair pair, TreebankNode np) {
   
    IdentifiedAnnotation arg1 = pair.getArg1();
    IdentifiedAnnotation arg2 = pair.getArg2();

    if((np.getBegin() <= arg1.getBegin()) &&
        (np.getEnd() >= arg1.getEnd()) &&
        (np.getBegin() <= arg2.getBegin()) &&
        (np.getEnd() >= arg2.getEnd())) {
      return true;
    }
   
    return false;
  }
View Full Code Here

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

    //JCasUtil.indexCovering(jcas, IdentifiedAnnotation.class, this.ancestorAnnotationClass)
   
    Map<IdentifiedAnnotation, Collection<Zone>> coveringMap =
      JCasUtil.indexCovering(jcas, IdentifiedAnnotation.class, Zone.class);
   
    IdentifiedAnnotation targetEntityAnnotation = (IdentifiedAnnotation)targetAnnotation;
   
    Collection<Zone> zoneList = coveringMap.get(targetEntityAnnotation);
   
    if (zoneList == null || zoneList.isEmpty())
    {
View Full Code Here

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

    // If the BaseToken Part Of Speech is a Noun
    Collection<BaseToken> tokens = JCasUtil.select(jcas, BaseToken.class);
    for (BaseToken token : tokens) {
      if (saveAnnotation && token.getPartOfSpeech() != null
          && token.getPartOfSpeech().startsWith("N")) {
        IdentifiedAnnotation ann = new IdentifiedAnnotation(jcas);
        ann.setBegin(token.getBegin());
        ann.setEnd(token.getEnd());
        ann.addToIndexes();

        if (printAnnotation) {
          LOG.info("Token:" + token.getCoveredText() + " POS:"
              + token.getPartOfSpeech());
        }
View Full Code Here

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

  public void consumeHit(JCas jcas, Annotation focusAnnot, int scope, ContextHit ctxHit)
      throws AnalysisEngineProcessException {
   
    Integer status = (Integer) ctxHit.getMetaData(StatusContextAnalyzer.CTX_HIT_KEY_STATUS_TYPE);
    if (focusAnnot instanceof IdentifiedAnnotation) {
      IdentifiedAnnotation neAnnot = (IdentifiedAnnotation) focusAnnot;
      //TODO: currently status is an int in the old system.  Let's update this to a constant string?
      neAnnot.setUncertainty(status);
      if(StatusIndicator.HISTORY_STATUS == status
          || StatusIndicator.FAMILY_HISTORY_STATUS == status ) {
        neAnnot.setHistoryOf(1);
      }
    }

    createContextAnnot(jcas, focusAnnot, scope, ctxHit).addToIndexes();
  }
View Full Code Here

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

    {
      if (!(identifiedAnnotation instanceof EntityMention || identifiedAnnotation instanceof EventMention))
      {
        continue;
      }
      IdentifiedAnnotation entityOrEventMention = identifiedAnnotation;
      if (entityOrEventMention.getPolarity() == -1)
      {
        logger.debug(String.format(" - identified annotation: [%d-%d] polarity %d (%s)",
            entityOrEventMention.getBegin(),
            entityOrEventMention.getEnd(),
            entityOrEventMention.getPolarity(),
            entityOrEventMention.getClass().getName()));
      }
      Instance<String> instance = new Instance<String>();
     
//      // extract all features that require only the entity mention annotation
//      instance.addAll(tokenFeatureExtractor.extract(jCas, entityMention));

      // extract all features that require the token and sentence annotations

      //Sentence sentence = sentenceList.iterator().next();
     
      /*
      if (sentence != null)
      {
        for (ContextExtractor<IdentifiedAnnotation> extractor : this.contextFeatureExtractors) {
          instance.addAll(extractor.extractWithin(identifiedAnnotationView, entityMention, sentence));
        }
      } else
      {
        // TODO extract context features for annotations that don't fall within a sentence
        logger.log(Level.WARN, "FIXME/TODO: generate context features for entities that don't fall within a sentence");
      }
      */
     
      /*
      for (ContextExtractor<BaseToken> extractor : this.tokenContextFeatureExtractors) {
          instance.addAll(extractor.extract(identifiedAnnotationView, entityMention));
        }
        */
     
      // only use extract this version if not doing domain adaptation
      if (ffDomainAdaptor==null) {
        for (CleartkExtractor extractor : this.tokenCleartkExtractors) {
          //instance.addAll(extractor.extractWithin(identifiedAnnotationView, entityMention, sentence));
          instance.addAll(extractor.extract(identifiedAnnotationView, entityOrEventMention));
        }
      }
     
//      List<Feature> cuePhraseFeatures = null;
//          cuePhraseInWindowExtractor.extract(jCas, entityOrEventMention);
          //cuePhraseInWindowExtractor.extractWithin(jCas, entityMention, firstCoveringSentence);
//      List<Sentence> sents = new ArrayList<Sentence>(coveringSents.get(entityOrEventMention));
      List<Sentence> sents = new ArrayList<Sentence>(JCasUtil.selectCovering(jCas, Sentence.class, entityOrEventMention.getBegin(), entityOrEventMention.getEnd()));
      if(sents.size() > 0){
        Sentence sentence = sents.get(0);
        List<AssertionCuePhraseAnnotation> cues = JCasUtil.selectCovered(AssertionCuePhraseAnnotation.class, sentence);
        int closest = Integer.MAX_VALUE;
        AssertionCuePhraseAnnotation closestCue = null;
        for(AssertionCuePhraseAnnotation cue : cues){
          List<BaseToken> tokens = JCasUtil.selectBetween(BaseToken.class, cue, entityOrEventMention);
          if(tokens.size() < closest){
            closestCue = cue;
            closest = tokens.size();
          }
//          instance.addAll(cuePhraseInWindowExtractor.extractBetween(jCas, cue, entityOrEventMention));
        }
        if(closestCue != null && closest < 21){
          instance.add(new Feature("ClosestCue_Word", closestCue.getCoveredText()));
//          instance.add(new Feature("ClosestCue_Phrase", closestCue.getCuePhrase()));
          instance.add(new Feature("ClosestCue_PhraseFamily", closestCue.getCuePhraseAssertionFamily()));
          instance.add(new Feature("ClosestCue_PhraseCategory", closestCue.getCuePhraseCategory()));
         
          // add hack-ey domain adaptation to these hacked-in features
          if (!fileToDomain.isEmpty() && ffDomainAdaptor!=null) {
            instance.addAll(ffDomainAdaptor.apply(new Feature("ClosestCue_Word", closestCue.getCoveredText())));
            instance.addAll(ffDomainAdaptor.apply(new Feature("ClosestCue_PhraseFamily", closestCue.getCuePhraseAssertionFamily())));
              instance.addAll(ffDomainAdaptor.apply(new Feature("ClosestCue_PhraseCategory", closestCue.getCuePhraseCategory())));
          }
         
        }
      }
//      if (cuePhraseFeatures != null && !cuePhraseFeatures.isEmpty())
//      {
//        instance.addAll(cuePhraseFeatures);
//      }


      // 7/9/13 SRH trying to make it work just for anatomical site
      int eemTypeId = entityOrEventMention.getTypeID();
      if (eemTypeId == CONST.NE_TYPE_ID_ANATOMICAL_SITE) {
          // 7/9/13 srh modified per tmiller so it's binary but not numeric feature
          //instance.add(new Feature("ENTITY_TYPE_" + entityOrEventMention.getTypeID()));
          instance.add(new Feature("ENTITY_TYPE_ANAT_SITE"));
          // add hack-ey domain adaptation to these hacked-in features
View Full Code Here

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

  private void createNewMention(JCas jCas, IdentifiedAnnotation mention,
      HashSet<Selector> hypothAttr) throws Throwable, IllegalAccessException {
   
    Constructor ctor = mention.getClass().getDeclaredConstructor(JCas.class);
    IdentifiedAnnotation m = (IdentifiedAnnotation) ctor.newInstance(jCas);
   
    m.setBegin(mention.getBegin());
    m.setEnd(mention.getEnd());
    for (Selector s : msg.keySet()) {
      if (!hypothAttr.contains(s)) {
        switch (s) {
        case CONDITIONAL:
          m.setConditional(mention.getConditional());
          break;
        case GENERIC:
          m.setGeneric(mention.getGeneric());
          break;
        case HISTORYOF:
          m.setHistoryOf(mention.getHistoryOf());
          break;
        case POLARITY:
          m.setPolarity(mention.getPolarity());
          break;
        case SUBJECT:
          m.setSubject(mention.getSubject());
          break;
        case UNCERTAINTY:
          m.setUncertainty(mention.getUncertainty());
          break;
        }
      }
    }
 
    m.addToIndexes(jCas);
  }
View Full Code Here

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

        first = mention.getValue().get(0);
        last = mention.getValue().get(mention.getValue().size() - 1);

        // put entity and attributes into the CAS
        // choose either entity or event
        IdentifiedAnnotation eMention;
        int type = Mapper.getEntityTypeId(entityTypes.get(mentionId));
        if (type==CONST.NE_TYPE_ID_ANATOMICAL_SITE) {
          eMention = new EntityMention(initView, first.start, last.end)
        } else if (type==CONST.NE_TYPE_ID_DISORDER
            || type==CONST.NE_TYPE_ID_DRUG
            || type==CONST.NE_TYPE_ID_FINDING
            || type==CONST.NE_TYPE_ID_PROCEDURE
            || type==CONST.NE_TYPE_ID_ANATOMICAL_SITE
            ) {
          eMention = new EventMention(initView, first.start, last.end);
        } else {
          eMention = new IdentifiedAnnotation(initView, first.start, last.end);
        }
       
        // set easy attributes
        eMention.setTypeID(Mapper.getEntityTypeId(entityTypes.get(mentionId)));
        eMention.setId(identifiedAnnotationId++);
        eMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
        eMention.setConfidence(1);

        if (mentionId.endsWith("4351")) {
          System.out.println();
        }
       
          List<ArgumentInfo> assocAttributes = getLeafAttributes(mentionId,
              mentionAttr,attrPtr,attrs,new ArrayList<ArgumentInfo>());
         
          for (ArgumentInfo a : assocAttributes) {

//        // set harder attributes from cas -- look through all attribute ids attached to this mentionId
//        for (String attrId : mentionAttr.get(mentionId) ) {
//          // make sure this attribute was actually somewhere in the knowtator file
//          if (!attrs.containsKey(attrId)) {
//            if (VERBOSE) { System.err.println("WARNING: attribute not found: "+attrId); }
//            continue;
//          }
         
          // look up the attribute id and set values accordingly
          checkForAttrValue(eMention, a.role, a.value);
        }
       
        // add to CAS
        eMention.addToIndexes();
      }
  }
View Full Code Here

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

    }
    Set<HashableAnnotation> all = Sets.union(goldMap.keySet(), systemMap.keySet());
    List<HashableAnnotation> sorted = Lists.newArrayList(all);
    Collections.sort(sorted);
    for (HashableAnnotation key : sorted) {
      IdentifiedAnnotation goldAnnotation = goldMap.get(key);
      IdentifiedAnnotation systemAnnotation = systemMap.get(key);
      Object goldLabel=null;
      Object systemLabel=null;
      if (goldAnnotation == null) {
        logger.debug(key + " not found in gold annotations ");
      } else {
        Feature feature = goldAnnotation.getType().getFeatureByBaseName(classifierType);
        goldLabel = getFeatureValue(feature, categoryClass, goldAnnotation);
        //  Integer goldLabel = goldAnnotation.getIntValue(feature);
      }
     
      if (systemAnnotation == null) {
        logger.info(key + " not found in system annotations ");
      } else {
        Feature feature = systemAnnotation.getType().getFeatureByBaseName(classifierType);
        systemLabel = getFeatureValue(feature, categoryClass, systemAnnotation);
        //  Integer systemLabel = systemAnnotation.getIntValue(feature);
      }
     
      String typeId;
      if (systemAnnotation!=null) {
        typeId = systemAnnotation.getTypeID()+"";
      } else  {
        typeId = "X";
      }
     
      if (goldLabel==null) {
View Full Code Here

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

    }
    Set<HashableAnnotation> all = Sets.union(goldMap.keySet(), systemMap.keySet());
    List<HashableAnnotation> sorted = Lists.newArrayList(all);
    Collections.sort(sorted);
    for (HashableAnnotation key : sorted) {
      IdentifiedAnnotation goldAnnotation = goldMap.get(key);
      IdentifiedAnnotation systemAnnotation = systemMap.get(key);
      Object goldLabel=null;
      Object systemLabel=null;
      if (goldAnnotation == null) {
        logger.debug(key + " not found in gold annotations ");
      } else {
        Feature feature = goldAnnotation.getType().getFeatureByBaseName(classifierType);
        goldLabel = getFeatureValue(feature, categoryClass, goldAnnotation);
        //  Integer goldLabel = goldAnnotation.getIntValue(feature);
      }
     
      if (systemAnnotation == null) {
        logger.info(key + " not found in system annotations ");
      } else {
        Feature feature = systemAnnotation.getType().getFeatureByBaseName(classifierType);
        systemLabel = getFeatureValue(feature, categoryClass, systemAnnotation);
        //  Integer systemLabel = systemAnnotation.getIntValue(feature);
      }
     
      String typeId = "X";
      String typeName = "IdentifiedAnnotation";
      int polarity, uncertainty, historyOf;
      boolean conditional, generic;
      String subject = "";
      String cui, coveredText = "";
      String instanceData = "";
      if (systemAnnotation!=null && systemAnnotation.getEnd()>=0) {
        typeId      = systemAnnotation.getTypeID()+"";
        typeName    = systemAnnotation.getClass().getSimpleName();
        polarity    = systemAnnotation.getPolarity();
        uncertainty = systemAnnotation.getUncertainty();
        conditional = systemAnnotation.getConditional();
        generic     = systemAnnotation.getGeneric();
        subject     = systemAnnotation.getSubject();
        historyOf   = systemAnnotation.getHistoryOf();
        coveredText = systemAnnotation.getCoveredText().replaceAll("\\n", " ").replaceAll(",",";");
        instanceData = documentId+","+polarity+","+uncertainty+","+conditional+","+generic+","+subject+","+historyOf+","+
            typeId+","+typeName+","+coveredText;
      }
     
      if (goldLabel==null) {
View Full Code Here

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

            int arrIdx = 0;
            for ( UmlsConcept umlsConcept : conceptList ) {
               conceptArr.set( arrIdx, umlsConcept );
               arrIdx++;
            }
            IdentifiedAnnotation annotation;
            if ( typeId == CONST.NE_TYPE_ID_DRUG ) {
               annotation = new MedicationMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_ANATOMICAL_SITE ) {
               annotation = new AnatomicalSiteMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_DISORDER ) {
               annotation = new DiseaseDisorderMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_FINDING ) {
               annotation = new SignSymptomMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_LAB ) {
               annotation = new LabMention( jcas );
            } else if ( typeId == CONST.NE_TYPE_ID_PROCEDURE ) {
               annotation = new ProcedureMention( jcas );
            } else {
               annotation = new EntityMention( jcas );
            }
            annotation.setTypeID( typeId );
            annotation.setBegin( neBegin );
            annotation.setEnd( neEnd );
            annotation.setDiscoveryTechnique( CONST.NE_DISCOVERY_TECH_DICT_LOOKUP );
            annotation.setOntologyConceptArr( conceptArr );
            annotation.addToIndexes();
         }
      } catch ( Exception e ) {
         // TODO Poor form - refactor
         // What is really thrown?  The jcas "throwFeatMissing" is not a great help
         throw new AnalysisEngineProcessException( e );
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.