org.apache.uima.cas.CAS.getView()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.apache.uima.cas.CAS.getView()方法的一些代码示例,展示了CAS.getView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CAS.getView()方法的具体详情如下:
包路径:org.apache.uima.cas.CAS
类名称:CAS
方法名:getView

CAS.getView介绍

[英]Get the view for a Sofa (subject of analysis). The view provides access to the Sofa data and the index repository that contains metadata (annotations and other feature structures) pertaining to that Sofa.
[中]获取沙发的视图(分析主题)。该视图提供对Sofa数据和包含与该Sofa相关的元数据(注释和其他要素结构)的索引存储库的访问。

代码示例

代码示例来源:origin: org.apache.uima/uimafit-core

/**
 * Convenience method to get the specified view or a default view if the requested view does not
 * exist. The default can also be {@code null}.
 * 
 * @param cas
 *          a CAS
 * @param viewName
 *          the requested view.
 * @param fallback
 *          the default view if the requested view does not exist.
 * @return the requested view or the default if the requested view does not exist.
 */
public static CAS getView(CAS cas, String viewName, CAS fallback) {
 CAS view;
 try {
  view = cas.getView(viewName);
 } catch (CASRuntimeException e) {
  // use fall-back view instead
  view = fallback;
 }
 return view;
}

代码示例来源:origin: org.apache.uima/uimaj-ep-cas-editor

@Override
public void switchView(String viewName) {
 String oldViewName = mCAS.getViewName();
 mCAS = mCAS.getView(viewName);
 fireViewChanged(oldViewName, viewName);
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.stanfordnlp-gpl

/**
 * Gets the named view; if the view doesn't exist it will be created.
 */
private static CAS getOrCreateView(CAS aCas, String aViewName)
{
  // TODO: there should be some way to do this without the try...catch
  try {
    return aCas.getView(aViewName);
  }
  catch (CASRuntimeException e) {
    // create the view
    return aCas.createView(aViewName);
  }
}

代码示例来源:origin: edu.utah.bmi.nlp/nlp-core

public void itemStateChanged(ItemEvent e) {
    if (e.getSource() != sofaSelectionComboBox || cas == null) {
      return;
    }
    // a new sofa was selected. Switch to that view and update display
    String sofaId = (String) e.getItem();
    CAS newCas = "DEFAULT".equalsIgnoreCase(sofaId) ? cas.getView(CAS.NAME_DEFAULT_SOFA) : cas.getView(sofaId);
    if (newCas != cas) {
      setCAS(newCas);
    }
  }
});

代码示例来源:origin: apache/uima-uimaj

public static ViewInfo[] getOtherViews(CAS cas) {
 Iterator<SofaFS> sofaIt = cas.getSofaIterator();
 List<ViewInfo> r = new ArrayList<ViewInfo>();
 while (sofaIt.hasNext()) {
  SofaFS item = sofaIt.next();
  CAS oCas = cas.getView(item);
  if (oCas != cas)
   r.add(new ViewInfo(oCas));
 }
 return r.toArray(new ViewInfo[r.size()]);
}

代码示例来源:origin: apache/uima-uimaj

public static CASImpl getStartingView(CAS cas, boolean sofaAware, ComponentInfo componentInfo) {
  // OLD behavior:
   // if this is a sofa-aware component, give it the Base CAS
   // if it is a sofa-unaware component, give it whatever view maps to the _InitialView
  // NEW behavior:
   // always return whatever view maps to the _InitialView
  CASImpl ci;
  // need to set the componentInfo for the getView to find the sofa mappings
  // Do this *before* the getView call below
  // note: this is in a shared view part of the CAS
  cas.setCurrentComponentInfo(componentInfo);  
//    if (sofaAware) {
//      ci = ((CASImpl) cas).getBaseCAS();
//    } else {
//      ci = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);
//    }
  ci = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);
  
  return ci;
 }

代码示例来源:origin: org.apache.uima/uimaj-tools

@Override
 public void itemStateChanged(ItemEvent e) {
  if (disableSofaSelectionComboBoxStateChangeAction) { // UIMA-4863
   return;
  }
  if (e.getSource() != sofaSelectionComboBox || cas == null || e.getStateChange() != ItemEvent.SELECTED ) {
   return;
  }
  // a new sofa was selected. Switch to that view and update display
  String sofaId = (String) e.getItem();
  CAS newCas = "DEFAULT".equalsIgnoreCase(sofaId) ? cas.getView(CAS.NAME_DEFAULT_SOFA) : cas.getView(sofaId);
  if (newCas != cas) {
   setCAS(newCas);
  }
 }
});

代码示例来源:origin: org.apache.uima/uimafit-core

/**
 * Convenience method to get the specified view or create a new view if the requested view does
 * not exist.
 * 
 * @param cas
 *          a CAS
 * @param viewName
 *          the requested view.
 * @param create
 *          the view is created if it does not exist.
 * @return the requested view
 * @throws IllegalArgumentException
 *           if the view does not exist and is not to be created.
 */
public static CAS getView(CAS cas, String viewName, boolean create) {
 CAS view;
 try {
  view = cas.getView(viewName);
 } catch (CASRuntimeException e) {
  // View does not exist
  if (create) {
   view = cas.createView(viewName);
  } else {
   throw new IllegalArgumentException("No view with name [" + viewName + "]");
  }
 }
 return view;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.stanfordnlp-gpl

/**
 * Does a complete deep copy of one CAS into another CAS. The contents of each view in the
 * source CAS will be copied to the same-named view in the destination CAS. If the view does not
 * already exist it will be created. All FeatureStructures that are indexed in a view in the
 * source CAS will become indexed in the same-named view in the destination CAS.
 *
 * @param aSrcCas
 *            the CAS to copy from
 * @param aDestCas
 *            the CAS to copy to
 * @param aCopySofa
 *            if true, the sofa data and mimeType of each view will be copied. If false they
 *            will not.
 */
public static void copyCas(CAS aSrcCas, CAS aDestCas, boolean aCopySofa)
{
  CasCopier copier = new CasCopier(aSrcCas, aDestCas);
  Iterator<SofaFS> sofaIter = aSrcCas.getSofaIterator();
  while (sofaIter.hasNext()) {
    SofaFS sofa = sofaIter.next();
    CAS view = aSrcCas.getView(sofa);
    copier.copyCasView(view, aCopySofa);
  }
}

代码示例来源:origin: apache/uima-uimaj

/**
 * Gets the named view; if the view doesn't exist it will be created.
 */
private static CASImpl getOrCreateView(CAS aCas, String aViewName) {
 //TODO: there should be some way to do this without the try...catch
 try { // throws if view doesn't exist
  return (CASImpl) aCas.getView(aViewName).getLowLevelCAS(); 
 }
 catch(CASRuntimeException e) {
  //create the view
  return (CASImpl) aCas.createView(aViewName).getLowLevelCAS(); 
 }
}

代码示例来源:origin: apache/uima-uimaj

public AbstractCas next() throws AnalysisEngineProcessException {
 // get a new CAS
 CAS cas = mUimaContext.getEmptyCas(CAS.class);
 // check if type system changed; if so, notify CollectionReader
 checkTypeSystemChange(cas);
 // Get the right view of the CAS. Sofa-aware components get the base CAS.
 // Sofa-unaware components get whatever is mapped to the default text sofa.
 CAS view = ((CASImpl) cas).getBaseCAS();
 if (!mSofaAware) {
  view = cas.getView(CAS.NAME_DEFAULT_SOFA);
 }
 try {
  mCollectionReader.getNext(view);
 } catch (CollectionException e) {
  throw new AnalysisEngineProcessException(e);
 } catch (IOException e) {
  throw new AnalysisEngineProcessException(e);
 }
 return cas;
}

代码示例来源:origin: org.apache.uima/uimaj-tools

public void process(CAS aCAS) throws AnalysisEngineProcessException {
 // get handle to CAS view containing XML document
 CAS xmlCas = aCAS.getView("xmlDocument");
 InputStream xmlStream = xmlCas.getSofa().getSofaDataStream();
 // parse with detag handler
 DetagHandler handler = new DetagHandler();
 try {
  SAXParser parser = parserFactory.newSAXParser();
  parser.parse(xmlStream, handler);
 } catch (Exception e) {
  throw new AnalysisEngineProcessException(e);
 }
 // create the plain text view and set its document text
 CAS plainTextView = aCAS.createView("plainTextDocument");
 plainTextView.setDocumentText(handler.getDetaggedText());
 plainTextView.setDocumentLanguage(aCAS.getView("_InitialView").getDocumentLanguage());
 // Index the SourceDocumentInformation object, if there is one, in the new sofa.
 // This is needed by the SemanticSearchCasIndexer
 Iterator iter = xmlCas.getAnnotationIndex(sourceDocInfoType).iterator();
 if (iter.hasNext()) {
  FeatureStructure sourceDocInfoFs = (FeatureStructure) iter.next();
  plainTextView.getIndexRepository().addFS(sourceDocInfoFs);
 }
}

代码示例来源:origin: org.apache.uima/uimaj-cpe

/**
 * Gets the feature as int.
 *
 * @param aCas the a cas
 * @param aFeature the a feature
 * @param aName the a name
 * @return the feature as int
 * @throws Exception the exception
 */
public static int getFeatureAsInt(CAS aCas, Feature aFeature, String aName) throws Exception {
 Feature seqNo2 = aFeature.getRange().getFeatureByBaseName(aName);
 FeatureStructure documentMetaData = aCas.getView(CAS.NAME_DEFAULT_SOFA).getDocumentAnnotation()
     .getFeatureValue(aFeature);
 return documentMetaData.getIntValue(seqNo2);
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.castransformation-asl

private AlignedString getAlignedString(JCas aSomeCase, String from, String to)
    throws AnalysisEngineProcessException, CASException {
  CAS baseCas = aSomeCase.getCasImpl().getBaseCAS();
  // Try to get the AlignedString for the current JCas.
  AlignmentStorage asstore = AlignmentStorage.getInstance();
  AlignedString as = asstore.get(baseCas, to, from);
  if (as == null) {
    // Attempt to reconstruct the alignment from the SofaChangeAnnotations.
    // This only works when they have not been altered in the mean time.
    ExtendedLogger logger = getLogger();
    if (logger.isInfoEnabled()) {
      logger.info("No mapping found from [" + from + "] to [" + to + "] on ["
          + baseCas.hashCode() + "]. "
          + "Restoring mapping from SofaChangeAnnotation found in [" + to + "]."
      );
    }
    JCas view = aSomeCase.getCas().getView(to).getJCas();
    as = AlignmentFactory.createAlignmentsFor(view);
  }
  // If there is none we have to fail. Practically this should never happen
  // when the alignment state is reconstructed in the previous step.
  if (as == null) {
    throw new AnalysisEngineProcessException(new IllegalStateException(
        "No mapping found from [" + from + "] to [" + to + "] on ["
            + baseCas.hashCode() + "]"));
  }
  return as;
}

代码示例来源:origin: org.apache.uima/uimaj-cpe

/**
 * Returns a value associated with a given feature.
 *
 * @param aCas -
 *          Cas containing data to extract
 * @param aFeature -
 *          feature to locate in the CAS
 * @param aName -
 *          name of the feature
 * @return - value as String
 * @throws Exception the exception
 */
public static String getFeatureAsString(CAS aCas, Feature aFeature, String aName)
    throws Exception {
 Feature seqNo2 = aFeature.getRange().getFeatureByBaseName(aName);
 FeatureStructure documentMetaData = aCas.getView(CAS.NAME_DEFAULT_SOFA).getDocumentAnnotation()
     .getFeatureValue(aFeature);
 return documentMetaData.getStringValue(seqNo2);
}

代码示例来源:origin: nlpie/biomedicus

);
CAS originalDocumentView = cas.getView(DocumentIdentifiers.ORIGINAL_DOCUMENT);
IndexListener indexListener = new CasIndexListener(originalDocumentView);

代码示例来源:origin: nlpie/biomedicus

@Override
 public void process(CAS aCAS) {
  LOGGER.trace("Annotating rtf paragraphs.");
  CAS systemView = aCAS.getView(documentName);

  Type newParagraphType = systemView.getTypeSystem()
    .getType("biomedicus.v2.rtf.NewParagraph");

  Type paragraphType = systemView.getTypeSystem()
    .getType("biomedicus.v2.Paragraph");

  AnnotationIndex<AnnotationFS> newParagraphIndex = systemView
    .getAnnotationIndex(newParagraphType);
  int start = 0;

  for (AnnotationFS newParagraph : newParagraphIndex) {
   int end = newParagraph.getEnd();
   systemView.addFsToIndexes(
     systemView.createAnnotation(paragraphType, start, end));

   start = end;
  }
 }
}

代码示例来源:origin: org.apache.uima/uimaj-ep-cas-editor

@Override
public void switchView(String viewName) {
 // TODO: Optimize the text retrieval and update notification handling
 // Currently the text must be changed before switchView is called ...
 // HACK:
 // Replace the text like set() would do,
 // but without sending out notifications.
 // The stop and resume notification methods do not yield
 // the desired effect
 String text = transformText(getCAS().getView(viewName).getDocumentText());
 getStore().set(text);
 getTracker().set(text);
 // Note: Sends out view update notification
 ((DocumentUimaImpl) mDocument).switchView(viewName);
}

代码示例来源:origin: nlpie/biomedicus

CASArtifact(
  @Nullable LabelAdapters labelAdapters, CAS cas
) {
 this.labelAdapters = labelAdapters;
 this.cas = cas;
 TypeSystem typeSystem = cas.getTypeSystem();
 metadataType = typeSystem.getType("ArtifactMetadata");
 keyFeature = metadataType.getFeatureByBaseName("key");
 valueFeature = metadataType.getFeatureByBaseName("value");
 metadataCas = cas.getView("metadata");
 Type idType = typeSystem.getType("ArtifactID");
 Feature idFeat = idType.getFeatureByBaseName("artifactID");
 FSIndexRepository indexRepository = metadataCas.getIndexRepository();
 artifactID = indexRepository.getIndex("artifactID", idType).iterator().get()
   .getStringValue(idFeat);
 metadataIndex = indexRepository.getIndex("metadata", metadataType);
 casMetadata = new CASMetadata();
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@Override
 public void itemStateChanged(ItemEvent e) {
  // a new sofa was selected. Switch to that view and update
  // display
  String sofaId = (String) e.getItem();
  this.main.setCas(this.main.getCas().getView(sofaId));
  String text = this.main.getCas().getDocumentText();
  if (text == null) {
   text = this.main.getCas().getSofaDataURI();
   if (text != null) {
    text = "SofaURI = " + text;
   } else {
    if (null != this.main.getCas().getSofaDataArray()) {
     text = "Sofa array with mime type = " + this.main.getCas().getSofa().getSofaMime();
    }
   }
  }
  String oldText = this.main.getTextArea().getText();
  if ((oldText == null) || (text == null) || !oldText.equals(text)) {
   this.main.setText(text);
  }
  if (text == null) {
   this.main.getTextArea().repaint();
  }
  this.main.updateIndexTree(true);
 }
}

相关文章