Java Code Examples for org.apache.uima.cas.CAS#getSofaIterator()
The following examples show how to use
org.apache.uima.cas.CAS#getSofaIterator() .
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: CasComparer.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void assertEqualsInner(CAS c1, CAS c2) { alreadyCompared.clear(); // this code handles initial views with no SofaFS CAS initialView1 = c1.getView(CAS.NAME_DEFAULT_SOFA); CAS initialView2 = c2.getView(CAS.NAME_DEFAULT_SOFA); assertEqualViewsInner(initialView1, initialView2); // this code skips the initial view, if it doesn't have a sofa FS FSIterator<Sofa> sofaIter = c1.getSofaIterator(); int c1Sofas = 0; while (sofaIter.hasNext()) { SofaFS sofa = sofaIter.next(); CAS tcas1 = c1.getView(sofa); CAS tcas2 = c2.getView(tcas1.getViewName()); assertEqualViewsInner(tcas1, tcas2); c1Sofas++; } sofaIter = c2.getSofaIterator(); int c2Sofas = 0; while (sofaIter.hasNext()) { c2Sofas++; sofaIter.moveToNext(); } Assert.assertTrue(c1Sofas == c2Sofas); }
Example 2
Source File: VinciAnalysisEngineService_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Analyzes a given document by a AnalysisEngine. When completed this method returns a VinciFrame * containing XCAS translated into a set of Vinci subFrames. Each subframe containing one * annotation with all its attributes. * * @param ct the ct * @return VinciFrame containing XCAS translated into a set of Vinci subframes. * @exception Exception if there is an error during processing */ private Transportable analyze(CASTransportable ct) throws Exception { CAS cas = ct.getCas(); try { long annotStartTime = System.currentTimeMillis(); mAE.process(cas); int annotationTime = (int) (System.currentTimeMillis() - annotStartTime); if (debug) { System.out.println("Annotation took: " + annotationTime + "ms"); } ct.getExtraDataFrame().fset(Constants.ANNOTATION_TIME, annotationTime); // Extract CAS // UIMAFramework.getLogger().log("CAS ACount::" + // cas.getAnnotationIndex().size()); int totalAnnots = 0; SofaFS sofa; FSIterator sItr = cas.getSofaIterator(); while (sItr.isValid()) { sofa = (SofaFS) sItr.get(); totalAnnots += cas.getView(sofa).getAnnotationIndex().size(); sItr.moveToNext(); } UIMAFramework.getLogger().log(Level.FINEST, "CAS ACount::" + totalAnnots); ct.setCommand(null); return ct; } catch (Exception ex) { ct.cleanup(); throw ex; } }
Example 3
Source File: DebugFSLogicalStructure.java From uima-uimaj with Apache License 2.0 | 5 votes |
public static ViewInfo[] getOtherViews(CAS cas) { Iterator<SofaFS> sofaIt = cas.getSofaIterator(); List<ViewInfo> r = new ArrayList<>(); 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()]); }
Example 4
Source File: VinciBinaryAnalysisEngineService_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * Analyzes a given document by a CasObjectProcessor. When completed this method returns a * VinciFrame containing XCAS translated into a set of Vinci subFrames. Each subframe containing * one annotation with all its attributes. * * @param aRequestFrame request frame * @return VinciFrame containing XCAS translated into a set of Vinci subframes. * @throws ServiceException the service exception */ private Transportable analyze(AFrame aRequestFrame) throws ServiceException { CAS cas = null; try { // get CAS object from pool cas = mCasPool.getCas(0); // deserialize into CAS object byte[] casBytes = aRequestFrame.fgetTrueBinary("BinaryCAS"); CASCompleteSerializer serializer = (CASCompleteSerializer) SerializationUtils .deserialize(casBytes); Serialization.deserializeCASComplete(serializer, (CASMgr) cas); long annotStartTime = System.currentTimeMillis(); // invoke Analysis Engine mAE.processCas(cas); int annotationTime = (int) (System.currentTimeMillis() - annotStartTime); if (debug) { System.out.println("Annotation took: " + annotationTime + "ms"); } // serialize CAS AFrame responseFrame = new AFrame(); CASSerializer responseSerializer = Serialization.serializeCAS(cas); byte[] responseCasBytes = SerializationUtils.serialize(responseSerializer); responseFrame.fsetTrueBinary("BinaryCAS", responseCasBytes); // also add annotation time responseFrame.fset(Constants.ANNOTATION_TIME, annotationTime); // UIMAFramework.getLogger().log("CAS ACount::" + // cas.getAnnotationIndex().size()); int totalAnnots = 0; SofaFS sofa; FSIterator sItr = cas.getSofaIterator(); while (sItr.isValid()) { sofa = (SofaFS) sItr.get(); totalAnnots += cas.getView(sofa).getAnnotationIndex().size(); sItr.moveToNext(); } UIMAFramework.getLogger().log(Level.FINE, "CAS Annotation Count::" + totalAnnots); return responseFrame; } catch (Throwable ex) { UIMAFramework.getLogger().log(Level.SEVERE, "", ex); throw new ServiceException("Unexpected exception in analyze(): " + ex); } finally { // release CAS back to pool if (cas != null) { mCasPool.releaseCas(cas); } } }