Package org.apache.uima.cas

Examples of org.apache.uima.cas.CAS


               .parseResourceSpecifier(in);
         // Create the Text Analysis Engine.
         ae = UIMAFramework.produceAnalysisEngine(specifier, null, null);

         // Create a new CAS.
         CAS cas = ae.newCAS();
         // Set the document text on the CAS.
         cas.setDocumentText(text);
         cas.setDocumentLanguage(language);
         // Process the sample document.
         ae.process(cas);

         return cas;
      } catch (Exception ex) {
View Full Code Here


         throws Exception {
      try {
         Object tsDescriptor = UIMAFramework.getXMLParser().parse(
               new XMLInputSource(tsFile));
         TypeSystemDescription tsDesc = (TypeSystemDescription) tsDescriptor;
         CAS cas = CasCreationUtils.createCas(tsDesc, null,
               new FsIndexDescription[0]);

         SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
         XCASDeserializer xcasDeserializer = new XCASDeserializer(cas
               .getTypeSystem());
         parser.parse(xcasFile, xcasDeserializer.getXCASHandler(cas));

         return cas;
      } catch (Exception ex) {
View Full Code Here

*/
public class CasComparer {
  public static void assertEquals(CAS c1, CAS c2) {
   
    // this code handles initial views with no SofaFS
    CAS initialView1 = c1.getView(CAS.NAME_DEFAULT_SOFA);
    CAS initialView2 = c2.getView(CAS.NAME_DEFAULT_SOFA);
    assertEqualViews(initialView1, initialView2);
    // this code skips the initial view, if it doesn't have a sofa FS
    FSIterator<SofaFS> sofaIter = c1.getSofaIterator();
    int c1Sofas = 0;
    while (sofaIter.hasNext()) {
      SofaFS sofa = (SofaFS) sofaIter.next();
      CAS tcas1 = c1.getView(sofa);
      CAS tcas2 = c2.getView(tcas1.getViewName());
      assertEqualViews(tcas1, tcas2);
      c1Sofas++;
    }
    sofaIter = c2.getSofaIterator();
    int c2Sofas = 0;
View Full Code Here

*/
public class CasManager_implTest extends TestCase {
  public void testEnableReset() throws Exception {
    CasManager mgr = UIMAFramework.newDefaultResourceManager().getCasManager();
    mgr.defineCasPool("test", 1, null);
    CAS cas = mgr.getCas("test");
   
    ((CASImpl)cas).enableReset(false);
   
//    try {
//      cas.release();
//      fail();
//    }
//    catch (CASAdminException e) {
//      //expected
//    }

    cas.release()// should work, release unlocks things.
 
    cas = mgr.getCas("test");
    ((CASImpl)cas).enableReset(true);
    cas.release();

  }
View Full Code Here

     
      AnnotationTypeTreeNode typeNode = new AnnotationTypeTreeNode(type);
     
      nameAnnotationTypeNodeMap.put(type.getName(), typeNode);
     
      CAS cas = mInputDocument.getCAS();
     
      AnnotationIndex<AnnotationFS> index = cas.getAnnotationIndex(type);
     
      for (FSIterator<AnnotationFS> it = index.iterator(); it.hasNext(); ) {
        AnnotationFS annotation = it.next();
       
        if (annotation.getType().equals(type)) {
View Full Code Here

  private InputStream getDocument(String fileName, String text, String language, DocumentFormat format) {

    String failedToImportLine = "Failed to import: " + fileName + "\n\n";
   
    CAS cas = createEmtpyCAS();
    cas.setDocumentText(removeNonXmlChars(text));
    cas.setDocumentLanguage(language);
   
    ByteArrayOutputStream out = new ByteArrayOutputStream(40000);

    if (DocumentFormat.XCAS.equals(format)) {
      try {
View Full Code Here

          // No preference defined, lets use defaults
          if (tsPrefStore == null) {
            tsPrefStore = new PreferenceStore(prefFile.getName());

            CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);
            TypeSystem ts = cas.getTypeSystem();

            Collection<AnnotationStyle> defaultStyles = getConfiguredAnnotationStyles(tsPrefStore,
                    ts);

            Collection<AnnotationStyle> newStyles = DefaultColors.assignColors(ts, defaultStyles);

            // TODO: Settings defaults must be moved to the AnnotationEditor
            for (AnnotationStyle style : newStyles) {
              AnnotationStyle.putAnnotatationStyleToStore(tsPrefStore, style);
            }
          }

          typeSystemPreferences.put(prefFile.getFullPath().toPortableString(), tsPrefStore);
        }

        documentToTypeSystemMap.put(document, typeSystemFile
                .getFullPath().toPortableString());

        IPreferenceStore store = sessionPreferenceStores.get(getTypesystemId(element));

        if (store == null) {
          PreferenceStore newStore = new PreferenceStore();
          sessionPreferenceStores.put(getTypesystemId(element), newStore);
          newStore.addPropertyChangeListener(new SaveSessionPreferencesTrigger(element));

          String sessionPreferenceString = typeSystemFile.getPersistentProperty(new QualifiedName(
                  "", CAS_EDITOR_SESSION_PROPERTIES));

          if (sessionPreferenceString != null) {
            try {
              newStore.load(new ByteArrayInputStream(sessionPreferenceString.getBytes("UTF-8")));
            } catch (IOException e) {
              CasEditorPlugin.log(e);
            }
          }
        }

        // TODO:
        // Preferences are bound to the type system
        // Changed in one place, then it should change in all places

        CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);

        DocumentFormat documentFormat;

        // Which file format to use ?
        if (casFile.getName().endsWith("xmi")) {
View Full Code Here

  public void run() {
    AnnotationSelection annotations = new AnnotationSelection(getStructuredSelection());

    ICasDocument document = editor.getDocument();
   
    CAS documentCAS = document.getCAS();

    AnnotationFS mergedAnnotation = documentCAS.createAnnotation(annotations.getFirst().getType(),
            annotations.getFirst().getBegin(), annotations.getLast().getEnd());

    document.removeFeatureStructures(annotations.toList());
    document.addFeatureStructure(mergedAnnotation);
  }
View Full Code Here

    }

    // have list of features really disappearing (not kept present by imports or built-ins)
    // return all types/features of these for types which are subtypes of the passed-in type

    CAS tcas = editor.getCurrentView();
    TypeSystem typeSystem = tcas.getTypeSystem();
    Type thisType = typeSystem.getType(localTd.getName());
    List subsumedTypesList = typeSystem.getProperlySubsumedTypes(thisType);
    subsumedTypesList.add(thisType);
    Type[] subsumedTypes = (Type[]) subsumedTypesList.toArray(new Type[0]);
View Full Code Here

  public void resetNoQuestions() {
    int numViews = this.getBaseSofaCount();
    // Flush indexRepository for all Sofa
    for (int view = 1; view <= numViews; view++) {
      CAS tcas = (view == 1) ? getInitialView() : getView(view);
      if (tcas != null) {
        ((CASImpl) tcas).resetView();

        // mySofaRef = -1 is a flag in initial view that sofa has not been set.
        // For the initial view, it is possible to not have a sofa - it is set
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.CAS

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.