org.apache.uima.cas.impl.CASImpl Java Examples

The following examples show how to use org.apache.uima.cas.impl.CASImpl. 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: JsonCasSerializerTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void setupTypeSystem(String tsdName) throws InvalidXMLException, IOException, ResourceInitializationException, CASException {
    File tsdFile = JUnitExtension.getFile("CasSerialization/desc/" + tsdName);
    tsd = parser.parseTypeSystemDescription(new XMLInputSource(tsdFile));
    cas = (CASImpl) CasCreationUtils.createCas(tsd, null, null);
//    cas.getSofaRef();  // creates the default sofa
    jcas = cas.getJCas();
    tsi = cas.getTypeSystemImpl();
    topType = (TypeImpl) tsi.getTopType();
    annotationType = (TypeImpl) tsi.getType("uima.tcas.Annotation"); 
    allTypesType = (TypeImpl) tsi.getType("org.apache.uima.test.AllTypes");
    tokenType = (TypeImpl) tsi.getType("org.apache.uima.test.Token");
    emptyIntListType = (TypeImpl) tsi.getType("uima.cas.EmptyIntegerList");
//    nonEmptyIntListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyIntegerList");
//    emptyFSListType = (TypeImpl) tsi.getType("uima.cas.EmptyFSList");
//    nonEmptyFSListType = (TypeImpl) tsi.getType("uima.cas.NonEmptyFSList");
    
  }
 
Example #2
Source File: SerializationNoMDTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * @see junit.framework.TestCase#setUp()
 */
public void setUp() throws Exception {
  super.setUp();
  casMgr = initCAS();
  cas = (CASImpl)casMgr;

  TypeSystem ts = cas.getTypeSystem();
  wordType = ts.getType(WORD_TYPE);
  // assert(wordType != null);
  separatorType = ts.getType(SEP_TYPE);
  eosType = ts.getType(EOS_TYPE);
  tokenType = ts.getType(TOKEN_TYPE);
  tokenTypeFeature = ts.getFeatureByFullName(TOKEN_TYPE_FEAT_Q);
  startFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
  endFeature = ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_END);
  sentenceType = ts.getType(SENT_TYPE);
}
 
Example #3
Source File: Util.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public static AbstractCas setupViewSwitchClassLoadersLockCas(
    CAS cas, 
    boolean sofaAware, 
    ComponentInfo componentInfo,
    ResourceManager resourceManager, 
    Class<? extends AbstractCas> casInterface) {
  CASImpl ci = getStartingView(cas, sofaAware, componentInfo);
  // get requested interface to CAS (CAS or JCas)
  // next will create JCas if needed, but not already created
  // must precede the switchClassLoader call - that one needs the JCas link, if it is being used
  AbstractCas r = CasManager_impl.getCasInterfaceStatic(ci, casInterface);
  // This cas will be unlocked and its class loader restored when the
  //   next() method returns it
  // Insure the same view is passed for switching/restoring  https://issues.apache.org/jira/browse/UIMA-2211
  ci.switchClassLoaderLockCasCL(resourceManager.getExtensionClassLoader());    
  return r;
}
 
Example #4
Source File: UiucKnownPlace_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (UiucKnownPlace_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = UiucKnownPlace_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UiucKnownPlace(addr, UiucKnownPlace_Type.this);
   UiucKnownPlace_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new UiucKnownPlace(addr, UiucKnownPlace_Type.this);
}
 
Example #5
Source File: FSArray.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Make a new FSArray of given size
 * @param jcas The JCas
 * @param length The number of elements in the new array
 */
public FSArray(JCas jcas, int length) {
  super(jcas);
  _casView.validateArraySize(length);
  theArray = new TOP[length];

  if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
    _casView.traceFSCreate(this);
  }
  if (_casView.isId2Fs()) {
    _casView.adjustLastFsV2Size_arrays(length);
  }    
}
 
Example #6
Source File: UimaAcronym_Type.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
  if (instanceOf_Type.useExistingInstance) {
    // Return eq fs instance if already created
    FeatureStructure fs = instanceOf_Type.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UimaAcronym(addr, instanceOf_Type);
      instanceOf_Type.jcas.putJfsFromCaddr(addr, fs);
      return fs;
    }
    return fs;
  } else
    return new UimaAcronym(addr, instanceOf_Type);
}
 
Example #7
Source File: Relation_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Relation_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Relation_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Relation(addr, Relation_Type.this);
   Relation_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Relation(addr, Relation_Type.this);
}
 
Example #8
Source File: Entity_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Entity_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Entity_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Entity(addr, Entity_Type.this);
   Entity_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Entity(addr, Entity_Type.this);
}
 
Example #9
Source File: Neuron_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Neuron_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Neuron_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Neuron(addr, Neuron_Type.this);
   Neuron_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Neuron(addr, Neuron_Type.this);
}
 
Example #10
Source File: ChunkADVP_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (ChunkADVP_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = ChunkADVP_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new ChunkADVP(addr, ChunkADVP_Type.this);
   ChunkADVP_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new ChunkADVP(addr, ChunkADVP_Type.this);
}
 
Example #11
Source File: UiucCurrencyFinal_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (UiucCurrencyFinal_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = UiucCurrencyFinal_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UiucCurrencyFinal(addr, UiucCurrencyFinal_Type.this);
   UiucCurrencyFinal_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new UiucCurrencyFinal(addr, UiucCurrencyFinal_Type.this);
}
 
Example #12
Source File: BmeowType_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (BmeowType_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = BmeowType_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new BmeowType(addr, BmeowType_Type.this);
   BmeowType_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new BmeowType(addr, BmeowType_Type.this);
}
 
Example #13
Source File: Coordination_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Coordination_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Coordination_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Coordination(addr, Coordination_Type.this);
   Coordination_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Coordination(addr, Coordination_Type.this);
}
 
Example #14
Source File: Sentence_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Sentence_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Sentence_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Sentence(addr, Sentence_Type.this);
   Sentence_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Sentence(addr, Sentence_Type.this);
}
 
Example #15
Source File: AuthorInfo_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (AuthorInfo_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = AuthorInfo_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new AuthorInfo(addr, AuthorInfo_Type.this);
   AuthorInfo_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new AuthorInfo(addr, AuthorInfo_Type.this);
}
 
Example #16
Source File: Verb_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Verb_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Verb_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Verb(addr, Verb_Type.this);
   Verb_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Verb(addr, Verb_Type.this);
}
 
Example #17
Source File: GeneralEnglish_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (GeneralEnglish_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = GeneralEnglish_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new GeneralEnglish(addr, GeneralEnglish_Type.this);
   GeneralEnglish_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new GeneralEnglish(addr, GeneralEnglish_Type.this);
}
 
Example #18
Source File: UiucKnownName_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (UiucKnownName_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = UiucKnownName_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UiucKnownName(addr, UiucKnownName_Type.this);
   UiucKnownName_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new UiucKnownName(addr, UiucKnownName_Type.this);
}
 
Example #19
Source File: UiucKnownNamesBig_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (UiucKnownNamesBig_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = UiucKnownNamesBig_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UiucKnownNamesBig(addr, UiucKnownNamesBig_Type.this);
   UiucKnownNamesBig_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new UiucKnownNamesBig(addr, UiucKnownNamesBig_Type.this);
}
 
Example #20
Source File: BadContent_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (BadContent_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = BadContent_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new BadContent(addr, BadContent_Type.this);
   BadContent_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new BadContent(addr, BadContent_Type.this);
}
 
Example #21
Source File: AnalysisEngineImplBase.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.analysis_engine.AnalysisEngine#getFeatureNamesForType(java.lang.String)
 */
public synchronized String[] getFeatureNamesForType(String aTypeName) {
  // build CAS and populate mFirstTypeSystem
  CASImpl cas = (CASImpl) getCasManager().getCas(this.getUimaContextAdmin().getQualifiedContextName());
  TypeSystemImpl ts = cas.getTypeSystemImpl();
  getCasManager().releaseCas(cas);

  TypeImpl t = ts.getType(aTypeName);
  return (t == null) ? null : t.getFeaturesAsStream().map(f -> f.getShortName()).toArray(size -> new String[size]);
}
 
Example #22
Source File: Topic_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Topic_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Topic_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Topic(addr, Topic_Type.this);
   Topic_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Topic(addr, Topic_Type.this);
}
 
Example #23
Source File: TooFewTokensPerPage_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (TooFewTokensPerPage_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = TooFewTokensPerPage_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new TooFewTokensPerPage(addr, TooFewTokensPerPage_Type.this);
   TooFewTokensPerPage_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new TooFewTokensPerPage(addr, TooFewTokensPerPage_Type.this);
}
 
Example #24
Source File: FlowContainer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public FlowContainer newCasProduced(final CAS newCAS, String producedBy)
        throws AnalysisEngineProcessException {
  mTimer.startIt();
  CAS view = null;
  try {
    view = Util.getStartingView(   
        newCAS, 
        mSofaAware, 
        mFlowControllerContainer.getUimaContextAdmin().getComponentInfo());
    // now get the right interface(e.g. CAS or JCAS)
    // must be done before call to switchClassLoader
    Class<? extends AbstractCas> requiredInterface = mFlowControllerContainer.getRequiredCasInterface();
    AbstractCas casToPass = getCasManager().getCasInterface(view, requiredInterface);

    ((CASImpl)view).switchClassLoaderLockCasCL(getFlowClassLoader());
    Flow flow = mFlow.newCasProduced(casToPass, producedBy);
    if (flow instanceof CasFlow_ImplBase) {
      ((CasFlow_ImplBase)flow).setCas(view);
    }
    if (flow instanceof JCasFlow_ImplBase) {
      ((JCasFlow_ImplBase)flow).setJCas(view.getJCas());
    }
    return new FlowContainer(flow, mFlowControllerContainer, newCAS);
  } catch (CASException e) {
    throw new AnalysisEngineProcessException(e);
  } finally {
    newCAS.setCurrentComponentInfo(null);
    if (null != view) {
      ((CASImpl)view).restoreClassLoaderUnlockCas();
    }
    mTimer.stopIt();
    getMBean().reportAnalysisTime(mTimer.getDuration());
    getMBean().incrementCASesProcessed();
  }
}
 
Example #25
Source File: Measure_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Measure_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Measure_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Measure(addr, Measure_Type.this);
   Measure_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Measure(addr, Measure_Type.this);
}
 
Example #26
Source File: Morphology_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Morphology_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Morphology_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Morphology(addr, Morphology_Type.this);
   Morphology_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Morphology(addr, Morphology_Type.this);
}
 
Example #27
Source File: InBetweenMissing_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (InBetweenMissing_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = InBetweenMissing_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new InBetweenMissing(addr, InBetweenMissing_Type.this);
   InBetweenMissing_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new InBetweenMissing(addr, InBetweenMissing_Type.this);
}
 
Example #28
Source File: VariationLocation_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (VariationLocation_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = VariationLocation_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new VariationLocation(addr, VariationLocation_Type.this);
   VariationLocation_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new VariationLocation(addr, VariationLocation_Type.this);
}
 
Example #29
Source File: Chunk_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Chunk_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Chunk_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Chunk(addr, Chunk_Type.this);
   Chunk_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Chunk(addr, Chunk_Type.this);
}
 
Example #30
Source File: PTBConstituent_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (PTBConstituent_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = PTBConstituent_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new PTBConstituent(addr, PTBConstituent_Type.this);
   PTBConstituent_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new PTBConstituent(addr, PTBConstituent_Type.this);
}