public JCas getJCas() { try { return cas.getJCas(); } catch (CASException e) { e.printStackTrace(); } return null; }
/** * @return The view with name {@link #DEFAULT_VIEW} */ static public JCas getDefaultView( final JCas jCas ) { try { return jCas.getView( DEFAULT_VIEW ); } catch ( CASException casE ) { LOGGER.error( casE.getMessage() ); } return jCas; }
public void add(String[] types) throws CASException { final int max = types.length - 1; boolean rc; for (int i = 0; i < max; i++) { rc = add(types[i], types[i + 1]); if (!rc) { CASException e = new CASException(CASException.CYCLE_IN_TYPE_ORDER, new String[] { types[i], types[i + 1] }); throw e; } } }
throw new AnalysisEngineProcessException(e1.getCause()); e.printStackTrace(); return; mapAnnotations(jcas, map, modifiedViewName); } catch (CASException e) { e.printStackTrace();
throw new AnalysisEngineProcessException(e1.getCause()); e.printStackTrace(); return; mapAnnotations(jcas, map, outputViewName); } catch (CASException e) { e.printStackTrace();
@Override public Object getValue(TOP a) { try { JCas jcas = a.getCAS().getJCas(); return JCasUtil.select(jcas, Token.class).size(); } catch (CASException e) { e.printStackTrace(); return 0; } }
/** * @param jCas ye olde ... * @return All views, including gold and default */ static public Collection<JCas> getAllViews( final JCas jCas ) { if ( jCas == null ) { return Collections.emptyList(); } final Collection<JCas> views = new ArrayList<>(); try { jCas.getViewIterator().forEachRemaining( views::add ); } catch ( CASException casE ) { LOGGER.error( casE.getMessage() ); } return views; }
private static int[] encodeTypeList(String[] typeList, TypeSystem ts) throws CASException { int[] a = new int[typeList.length]; LowLevelTypeSystem llts = (LowLevelTypeSystem) ts; for (int i = 0; i < a.length; i++) { int t = llts.ll_getCodeForTypeName(typeList[i]); if (t == LowLevelTypeSystem.UNKNOWN_TYPE_CODE) { CASException e = new CASException(CASException.TYPEORDER_UNKNOWN_TYPE, new String[] { typeList[i] }); throw e; } a[i] = t; } return a; }
@SuppressWarnings("synthetic-access") @Override public void process(JCas jcas) throws AnalysisEngineProcessException { JCas goldView = null; try { goldView = jcas.getView(goldViewName); } catch (CASException e) { e.printStackTrace(); throw new AnalysisEngineProcessException(e); } copyRelations(jcas, goldView, dropout); }
/** * @param patientId - * @param docId - * @param viewName - * @return Stored view for the parameters */ synchronized public JCas getStoredView( final String patientId, final String docId, final String viewName ) { final JCas patientCas = _patientMap.get( patientId ); if ( patientCas == null ) { LOGGER.warn( "No patient with id " + patientId ); return null; } final ViewInfo viewInfo = new ViewInfo( patientId, docId, viewName ); try { return patientCas.getView( viewInfo.getViewCode() ); } catch ( CASException casE ) { LOGGER.error( casE.getMessage() ); } return null; }
public JCas getView(String localViewName) throws CASException { try { return casImpl.getView(localViewName).getJCas(); } catch (CASRuntimeException e) { throw new CASException(e); // https://issues.apache.org/jira/browse/UIMA-5869 } }
@Override public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) { try { JCas jcas = aCas.getJCas(); String docId = DocumentIDAnnotationUtil.getDeepDocumentId(jcas); System.out.println("Doc id for entity process complete: " + docId); System.out.println("Found " + JCasUtil.select(jcas, IdentifiedAnnotation.class).size() + " medical terms."); // The following was a bit verbose, but here's how you'd print out the text of each discovered entity span: /* for(IdentifiedAnnotation annot : JCasUtil.select(jcas, IdentifiedAnnotation.class)){ System.out.println("Found entity: " + annot.getCoveredText()); } */ } catch (CASException e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * @param patientId - * @param docId - * @return Map of ViewNames to Views */ synchronized public Map<String, JCas> getStoredViews( final String patientId, final String docId ) { final JCas patientCas = _patientMap.get( patientId ); if ( patientCas == null ) { LOGGER.warn( "No patient with id " + patientId ); return null; } final Collection<String> viewNames = getStoredViewNames( patientId, docId ); final Map<String, JCas> viewMap = new HashMap<>(); try { for ( String viewName : viewNames ) { final ViewInfo viewInfo = new ViewInfo( viewName ); viewMap.put( viewInfo.getViewName(), patientCas.getView( viewName ) ); } } catch ( CASException casE ) { LOGGER.error( casE.getMessage() ); } return viewMap; }
throw new CASException(MESSAGE_DIGEST, "INVALID_FEATURE_PATH_SYNTAX", new Object[] { featurePath, "null for a feature path" }); throw new CASException(MESSAGE_DIGEST, "INVALID_FEATURE_PATH_SYNTAX", new Object[] { this.featurePathString, "//" }); this.builtInFunction = FUNCTION_TYPE_NAME; } else { throw new CASException(MESSAGE_DIGEST, "INVALID_FEATURE_PATH_SYNTAX", new Object[] { this.featurePathString, builtInFunctionName });
@Override public Step next() { // if we are past the last annotator finish if (currentStep >= mSequence.size()) { return new FinalStep(); } // if we have gold standard relations, continue if(currentStep > 0 && mSequence.get(currentStep-1).equals(DocumentIDPrinter.class.getName())){ JCas goldView; try { goldView = jcas.getView(GOLD_VIEW_NAME); if(JCasUtil.select(goldView, CoreferenceRelation.class).size() == 0){ System.out.println("Skipping this document with no coreference relations."); return new FinalStep(); } } catch (CASException e) { // no need to stop flow -- just go ahead to default simple step. e.printStackTrace(); } } // otherwise finish return new SimpleStep(mSequence.get(currentStep++)); } }
@Override public Vector<Double> calculateScores(JCas aCas) throws ScoringComponentException { Vector<Double> scoresVector = new Vector<Double>(); try { JCas tView = aCas.getView("TextView"); JCas hView = aCas.getView("HypothesisView"); scoresVector.addAll(calculateTSScores(tView, hView)); // add the backup values scoresVector.addAll(super.calculateScores(aCas)); } catch (CASException e) { throw new ScoringComponentException(e.getMessage()); } return scoresVector; }
public Feature getRequiredFeature(Type t, String s) throws CASException { Feature f = t.getFeatureByBaseName(s); if (null == f) { CASException casEx = new CASException(CASException.JCAS_FEATURENOTFOUND_ERROR, new String[] { t.getName(), s }); throw casEx; } return f; }
private String getDocumentId(CAS cas) { Header header = null; Type headerType = cas.getTypeSystem().getType(Header.class.getCanonicalName()); Iterator<org.apache.uima.jcas.tcas.Annotation> iterator; try { iterator = cas.getJCas().getAnnotationIndex(Header.type).iterator(); header = (Header) iterator.next(); } catch (CASRuntimeException e) { e.printStackTrace(); } catch (CASException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (header != null) { return header.getDocId(); } return new Integer(id++).toString(); } }
@Override public Vector<Double> calculateScores(JCas cas) throws ScoringComponentException { // all the values: (T&H/H), (T&H/T), and ((T&H/H)*(T&H/T)) Vector<Double> scoresVector = new Vector<Double>(); try { JCas tView = cas.getView("TextView"); HashMap<String, Integer> tBag = countTokens(tView); JCas hView = cas.getView("HypothesisView"); HashMap<String, Integer> hBag = countTokens(hView); scoresVector.addAll(calculateSimilarity(tBag, hBag)); String task = JCasUtil.select(cas, EntailmentMetadata.class).iterator().next().getTask(); if (null == task) { scoresVector.add(0d); scoresVector.add(0d); scoresVector.add(0d); scoresVector.add(0d); } else { scoresVector.add(isTaskIE(task)); scoresVector.add(isTaskIR(task)); scoresVector.add(isTaskQA(task)); scoresVector.add(isTaskSUM(task)); } } catch (CASException e) { throw new ScoringComponentException(e.getMessage()); } return scoresVector; }
private static void reportInitErrors(JCasImpl jcas) throws CASException { JCasSharedView sv = jcas.sharedView; if (sv.errorSet.size() > 0) { boolean doThrow = false; StringBuffer msg = new StringBuffer(100); msg.append('\n'); for (ErrorReport f : sv.errorSet) { msg.append(f.e.getMessage()); msg.append('\n'); doThrow = doThrow || f.doThrow; } if (doThrow) { CASException e = new CASException(CASException.JCAS_INIT_ERROR, new String[] { msg.toString() }); throw e; } else { Logger logger = UIMAFramework.getLogger(); if (null == logger) { throw new CASRuntimeException(CASException.JCAS_INIT_ERROR, new String[] {msg.toString()}); } else { logger.log(Level.WARNING, msg.toString()); } } } }