Java Code Examples for org.apache.uima.jcas.JCas#addFsToIndexes()

The following examples show how to use org.apache.uima.jcas.JCas#addFsToIndexes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TRExReader.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private <K extends Constituent> K getConstituent(TAnnotation constituent, Class<K> clazz, JCas jCas) {
  Constituent result = getInstancedConstitient(jCas, constituent, clazz);
  if(constituent.boundaries != null) {
    result.setExplicit(true);
    result.setBegin(constituent.boundaries[0]);
    result.setEnd(constituent.boundaries[1]);
  }
  result.setUri(constituent.uri);
  List<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, result.getBegin(), result.getEnd());
  FSArray array = new FSArray(jCas, tokens.size());
  for (int i = 0; i < tokens.size(); i++) {
    array.set(i, tokens.get(i));
  }
  array.addToIndexes();
  result.setTokens(array);
  jCas.addFsToIndexes(clazz.cast(result));
  return clazz.cast(result);
}
 
Example 2
Source File: MemReleaseI2b2CollectionReader.java    From ctakes-docker with Apache License 2.0 6 votes vote down vote up
/**********************************
   public static String decrypt( final String key, final String note ) throws Exception {
      String str = "";
      str = I2b2Cryptography.decrypt( key, note );
      return str;
   }
**********************************/

   private JCas setMetadata( final JCas jCas ) throws SQLException {
      final Metadata metadata = new Metadata( jCas );
      final SourceData sourcedata = new SourceData( jCas );
      metadata.setPatientID( _resultSet.getLong( _db_col_patient_num ) );
      sourcedata.setAuthorSpecialty( _resultSet.getString( _db_col_provider_id ) );
      sourcedata.setNoteTypeCode( _resultSet.getString( _db_col_concept_cd ) );
      sourcedata.setSourceEncounterId( _resultSet.getString( _db_col_encounter_num ) );
      sourcedata.setSourceInstanceId( _resultSet.getLong( _db_col_instance_num )+"" );
      final Timestamp ts = _resultSet.getTimestamp( _db_col_start_date );
      sourcedata.setSourceOriginalDate( ts.toString() );
      metadata.setSourceData( sourcedata );
      jCas.addFsToIndexes( metadata );
      logger.log(SEVERE, metadata.getPatientID() + " " + sourcedata.getSourceEncounterId() + " " + sourcedata.getSourceInstanceId());
      return jCas;
   }
 
Example 3
Source File: WebannoTsv3Reader.java    From webanno with Apache License 2.0 6 votes vote down vote up
/**
 * The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain
 * number and link number references, sorted in an ascending order <br>
 * Iterate over each chain number and link number references and construct the chain.
 */
private void addChainAnnotations(JCas aJCas)
{
    for (Type linkType : chainAnnosPerTyep.keySet()) {
        for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) {

            Type chainType = aJCas.getCas().getTypeSystem().getType(
                    linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN);
            Feature firstF = chainType.getFeatureByBaseName(FIRST);
            Feature nextF = linkType.getFeatureByBaseName(NEXT);
            FeatureStructure chain = aJCas.getCas().createFS(chainType);

            aJCas.addFsToIndexes(chain);
            AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1);
            AnnotationFS linkFs = firstFs;
            chain.setFeatureValue(firstF, firstFs);
            for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) {
                linkFs.setFeatureValue(nextF,
                        chainAnnosPerTyep.get(linkType).get(chainNo).get(i));
                linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i);
            }
        }
    }
}
 
Example 4
Source File: ExternalRecommenderIntegrationTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private void addCasMetadata(JCas aJCas, long aDocumentId)
{
    CASMetadata cmd = new CASMetadata(aJCas);
    cmd.setUsername(USER_NAME);
    cmd.setProjectId(PROJECT_ID);
    cmd.setSourceDocumentId(aDocumentId);
    aJCas.addFsToIndexes(cmd);
}
 
Example 5
Source File: XmlFixingFilesInDirectoryCollectionReader.java    From ctakes-docker with Apache License 2.0 5 votes vote down vote up
private JCas setMetadata( final JCas jCas ) throws SQLException {
	final Metadata metadata = new Metadata( jCas );
	final SourceData sourcedata = new SourceData( jCas );
	metadata.setPatientID( 0L );
	sourcedata.setAuthorSpecialty( "Unknown" );
	sourcedata.setNoteTypeCode( "UnknownNoteType" );
	sourcedata.setSourceEncounterId( -1L+"" );
	sourcedata.setSourceInstanceId( -1L+"" );
	sourcedata.setSourceOriginalDate( (new Timestamp(System.currentTimeMillis())).toString() );
	metadata.setSourceData( sourcedata );
	jCas.addFsToIndexes( metadata );
	logger.log(Level.INFO, metadata.getPatientID() + " " + sourcedata.getSourceEncounterId() + " " + sourcedata.getSourceInstanceId());
	return jCas;
}
 
Example 6
Source File: EvaluationPreprocessorAnnotator.java    From bluima with Apache License 2.0 5 votes vote down vote up
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

    // because of later evaluation, copy annotation to view_gold (later used
    // by AnnotationEvaluator) and remove it from view_system.
    Collection<? extends Annotation> goldsFromInitialView = select(jCas,
            goldAnnotation);
    JCas goldView = null;
    try {
        goldView = jCas.createView(VIEW_GOLD);
    } catch (Throwable e) {
        throw new AnalysisEngineProcessException(
                NO_RESOURCE_FOR_PARAMETERS, new Object[] { VIEW_GOLD }, e);
    }

    CasCopier casCopier = new CasCopier(jCas.getCas(), goldView.getCas());

    goldView.setDocumentText(jCas.getDocumentText());
    // view_system annot. stored in List for later delete
    // (conccurentModifExeption)
    List<Annotation> toDelete = new ArrayList<Annotation>();
    for (Annotation g : goldsFromInitialView) {
        goldView.addFsToIndexes(casCopier.copyFs(g));
        if (deleteFrom) {
            toDelete.add(g);
        }
    }
    Annotation[] arr = toDelete.toArray(new Annotation[toDelete.size()]);
    for (int i = 0; i < arr.length; i++) {
        arr[i].removeFromIndexes(jCas);
    }
}
 
Example 7
Source File: IndexRepositoryTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testMissingSofaRef() throws Exception {
  JCas jcas = cas.getJCas();
  Annotation a = new Annotation(jcas, 0, 4);
  FeatureImpl feat = (FeatureImpl) cas.getTypeSystem().getType(CAS.TYPE_NAME_ANNOTATION_BASE)
                       .getFeatureByBaseName(CAS.FEATURE_BASE_NAME_SOFA);
  a._setFeatureValueNcNj(feat, null);
  try {
    jcas.addFsToIndexes(a);
  } catch (CASRuntimeException e) {
    assertEquals("SOFAREF_NOT_SET", e.getMessageKey());
    return;
  }
  fail("required exception not thrown"); // fail
}
 
Example 8
Source File: WebannoTsv3Reader.java    From webanno with Apache License 2.0 4 votes vote down vote up
private int addAnnotationWithNoFeature(JCas aJCas, Type aType, AnnotationUnit aUnit,
        List<AnnotationFS> aAnnos,
        Map<AnnotationUnit, Map<Integer, AnnotationFS>> aMultiTokUnits, int aEnd, int aRef)
{
    String anno = annotationsPerPostion.get(aType).get(aUnit).get(0);
    if (!anno.equals("_")) {
        int i = 0;
        String stackedAnnoRegex = "(?<!\\\\)" + Pattern.quote("|");
        for (String mAnnos : anno.split(stackedAnnoRegex)) {
            String multipleSlotAnno = "(?<!\\\\)" + Pattern.quote(";");
            for (String mAnno : mAnnos.split(multipleSlotAnno)) {
                String depRef = "";
                if (mAnno.endsWith("]")) {
                    depRef = mAnno.substring(mAnno.indexOf("[") + 1, mAnno.length() - 1);
                    aRef = depRef.contains("_") ? 0
                            : Integer.valueOf(mAnno.substring(mAnno.indexOf("[") + 1,
                                    mAnno.length() - 1));
                    mAnno = mAnno.substring(0, mAnno.indexOf("["));
                }

                boolean isMultitoken = false;
                AnnotationFS multiAnnoFs = null;

                if (!aMultiTokUnits.isEmpty()) {
                    for (AnnotationUnit u : aMultiTokUnits.keySet()) {
                        for (Integer r : aMultiTokUnits.get(u).keySet()) {
                            if (aRef == r) {
                                isMultitoken = true;
                                multiAnnoFs = aMultiTokUnits.get(u).get(r);
                                break;
                            }
                        }
                    }
                }

                if (isMultitoken) {

                    Feature endF = aType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_END);
                    multiAnnoFs.getCAS().removeFsFromIndexes(multiAnnoFs);
                    multiAnnoFs.setIntValue(endF, aEnd);
                    multiAnnoFs.getCAS().addFsToIndexes(multiAnnoFs);
                    setAnnoRefPerUnit(aUnit, aType, aRef, multiAnnoFs);

                }
                else {

                    aMultiTokUnits.putIfAbsent(aUnit, new HashMap<>());
                    aMultiTokUnits.get(aUnit).put(aRef, aAnnos.get(i));
                    aJCas.addFsToIndexes(aAnnos.get(i));
                    setAnnoRefPerUnit(aUnit, aType, aRef, aAnnos.get(i));
                }
                aRef++;
            }
            i++;
        }
    }
    return aRef;
}